[Inteproxy-commits] r275 - in trunk: . inteproxy

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Sep 20 21:45:01 CEST 2010


Author: bh
Date: 2010-09-20 21:44:57 +0200 (Mon, 20 Sep 2010)
New Revision: 275

Modified:
   trunk/ChangeLog
   trunk/inteproxy/httpconnection.py
   trunk/inteproxy/proxycore.py
Log:
Make inteproxy/proxyconnection.py completely obsolete.

* inteproxy/httpconnection.py (parse_netloc, default_ports):
Copied here from inteproxy/proxyconnection.py.  They were the last
things defined in that module that were actually still used.

* inteproxy/proxycore.py: Import parse_netloc from httpconnection.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-09-20 19:37:07 UTC (rev 274)
+++ trunk/ChangeLog	2010-09-20 19:44:57 UTC (rev 275)
@@ -1,5 +1,15 @@
 2010-09-20  Bernhard Herzog  <bh at intevation.de>
 
+	Make inteproxy/proxyconnection.py completely obsolete.
+
+	* inteproxy/httpconnection.py (parse_netloc, default_ports):
+	Copied here from inteproxy/proxyconnection.py.  They were the last
+	things defined in that module that were actually still used.
+
+	* inteproxy/proxycore.py: Import parse_netloc from httpconnection.
+
+2010-09-20  Bernhard Herzog  <bh at intevation.de>
+
 	* inteproxy/proxyconnection.py (HTTPSProxyConnection): Removed.
 	Not used anymore.
 

Modified: trunk/inteproxy/httpconnection.py
===================================================================
--- trunk/inteproxy/httpconnection.py	2010-09-20 19:37:07 UTC (rev 274)
+++ trunk/inteproxy/httpconnection.py	2010-09-20 19:44:57 UTC (rev 275)
@@ -1,4 +1,4 @@
-# Copyright (C) 2008, 2009 by Intevation GmbH
+# Copyright (C) 2008, 2009, 2010 by Intevation GmbH
 #
 # Based on code from
 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456195 which
@@ -19,8 +19,9 @@
 via an HTTPS proxy using the HTTP CONNECT method.
 """
 
+import socket
 import httplib
-import socket
+import urllib
 
 # the ssl modules was introduced in Python 2.6.  If available, we use
 # that, otherwise the older ssl support from the socket module
@@ -29,9 +30,32 @@
 except ImportError:
     ssl = None
 
+
+default_ports = {'http' : 80, 'https' : 443}
+
+
+def parse_netloc(scheme, netloc):
+    """Parses netloc and returns (hostname, port).
+
+    If the netloc string doesn't contain a port, the default port of
+    scheme (either 'http' or 'https') is used.  If the port cannot be
+    determined, a ValueError is raise.
+    """
+    host, port = urllib.splitport(netloc)
+    if port is None:
+        port = default_ports.get(scheme)
+        if port is None:
+            raise ValueError("Cannot determine port for URL scheme %r"
+                             % scheme)
+    else:
+        port = int(port)
+    return host, port
+
+
 def log_debug(template, *args):
     pass
 
+
 def connect_tcp(host, port, log_debug=log_debug):
     """Establish a TCP connection to port port on host.
     The return value is the socket object for the connection

Modified: trunk/inteproxy/proxycore.py
===================================================================
--- trunk/inteproxy/proxycore.py	2010-09-20 19:37:07 UTC (rev 274)
+++ trunk/inteproxy/proxycore.py	2010-09-20 19:44:57 UTC (rev 275)
@@ -1,5 +1,5 @@
 #! /usr/bin/python
-# Copyright (C) 2006, 2007, 2008, 2009 by Intevation GmbH
+# Copyright (C) 2006, 2007, 2008, 2009, 2010 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh at intevation.de>
 #
@@ -20,9 +20,8 @@
 from inteproxy.feesdialog import handle_fees_and_access_constraints
 from inteproxy.httpserver import HTTPServer
 from inteproxy.httpmessage import HTTPRequestMessage, HTTPResponseMessage
-from inteproxy.proxyconnection import parse_netloc
 from inteproxy.httpconnection import connect_tcp, connect_http_connect, \
-     connect_ssl, SocketHTTPConnection
+     connect_ssl, SocketHTTPConnection, parse_netloc
 
 
 # same as the BaseHTTPRequestHandler method, but as a standalone function:



More information about the Inteproxy-commits mailing list