[Inteproxy-commits] r12 - trunk

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 16 23:22:02 CET 2006


Author: jan
Date: 2006-11-16 23:22:02 +0100 (Thu, 16 Nov 2006)
New Revision: 12

Modified:
   trunk/ChangeLog
   trunk/proxyconnection.py
Log:
Patch by Thomas Arendsen Hein:
Set proxy via ConnectHTTPHandler/ConnectHTTPSHandler.
This fixes redirections and makes setting the proxy easier.

(from Norm Petterson's comment on 2005-05-04 from
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456195)


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-11-16 22:18:19 UTC (rev 11)
+++ trunk/ChangeLog	2006-11-16 22:22:02 UTC (rev 12)
@@ -1,5 +1,13 @@
 2006-11-16  Thomas Arendsen Hein <thomas at intevation.de>
 
+	* proxyconnection.py (ConnectHTTPHandler, ConnectHTTPSHandler):
+	Set proxy via ConnectHTTPHandler/ConnectHTTPSHandler, this fixes
+	redirections and makes setting the proxy easier. Taken from
+	Norm Petterson's comment on 2005-05-04:
+	http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456195
+
+2006-11-16  Thomas Arendsen Hein <thomas at intevation.de>
+
 	* proxyconnection.py (ProxyHTTPConnection.request):
 	"int(port)" instead of just "port", so passing ports really works
 	"rest or '/'" instead of "url" to make HTTP/1.0-only servers happy

Modified: trunk/proxyconnection.py
===================================================================
--- trunk/proxyconnection.py	2006-11-16 22:18:19 UTC (rev 11)
+++ trunk/proxyconnection.py	2006-11-16 22:22:02 UTC (rev 12)
@@ -83,13 +83,25 @@
 
 class ConnectHTTPHandler(urllib2.HTTPHandler):
 
+    def __init__(self, proxy=None, debuglevel=0):
+        self.proxy = proxy
+        urllib2.HTTPHandler.__init__(self, debuglevel)
+
     def do_open(self, http_class, req):
+        if self.proxy is not None:
+            req.set_proxy(self.proxy, 'http')
         return urllib2.HTTPHandler.do_open(self, ProxyHTTPConnection, req)
 
 
 class ConnectHTTPSHandler(urllib2.HTTPSHandler):
 
+    def __init__(self, proxy=None, debuglevel=0):
+        self.proxy = proxy
+        urllib2.HTTPSHandler.__init__(self, debuglevel)
+
     def do_open(self, http_class, req):
+        if self.proxy is not None:
+            req.set_proxy(self.proxy, 'https')
         return urllib2.HTTPSHandler.do_open(self, ProxyHTTPSConnection, req)
 
 
@@ -97,9 +109,9 @@
 
     import sys
 
-    opener = urllib2.build_opener(ConnectHTTPHandler, ConnectHTTPSHandler)
+    opener = urllib2.build_opener(ConnectHTTPHandler(sys.argv[2]),
+                                  ConnectHTTPSHandler(sys.argv[2]))
     urllib2.install_opener(opener)
     req = urllib2.Request(url=sys.argv[1])
-    req.set_proxy(sys.argv[2], 'https')
     f = urllib2.urlopen(req)
     print f.read()



More information about the Inteproxy-commits mailing list