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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri May 4 20:05:20 CEST 2007


Author: bh
Date: 2007-05-04 20:05:20 +0200 (Fri, 04 May 2007)
New Revision: 82

Modified:
   trunk/ChangeLog
   trunk/inteproxy/main.py
Log:
Fix for issue #369

* inteproxy/main.py (HTTPRedirectHandler): New.  A
HTTPRedirectHandler for urllib2 that switches off redirection
handling.
(setup_urllib2): Install HTTPRedirectHandler too.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-05-04 17:47:56 UTC (rev 81)
+++ trunk/ChangeLog	2007-05-04 18:05:20 UTC (rev 82)
@@ -1,5 +1,14 @@
 2007-05-04  Bernhard Herzog  <bh at intevation.de>
 
+	Fix for issue #369
+
+	* inteproxy/main.py (HTTPRedirectHandler): New.  A
+	HTTPRedirectHandler for urllib2 that switches off redirection
+	handling.
+	(setup_urllib2): Install HTTPRedirectHandler too.
+
+2007-05-04  Bernhard Herzog  <bh at intevation.de>
+
 	* inteproxy/main.py (setup_urllib2): Build a list of handlers
 	incrementatlly so that we can call build_opener in once place
 	instead of two.

Modified: trunk/inteproxy/main.py
===================================================================
--- trunk/inteproxy/main.py	2007-05-04 17:47:56 UTC (rev 81)
+++ trunk/inteproxy/main.py	2007-05-04 18:05:20 UTC (rev 82)
@@ -34,6 +34,28 @@
             user, password = the_application.get_password(title)
         return user, password
 
+class HTTPRedirectHandler(urllib2.HTTPRedirectHandler):
+
+    """A version of urllib2's HTTPRedirectHandler that does not redirect
+
+    The class urllib2.HTTPRedirectHandler implements error handlers for
+    the redirect error codes sent by the server and then starts a new
+    request.  In InteProxy we want to let InteProxy's client to handle
+    the redirects themselves, so we overrride the error handling and do
+    not handle any of the errors.  urrlib2 then falls back on the real
+    http error handler so that InteProxy handles them like other errors
+    such as 404.
+    """
+
+    def http_error_302(self, *args):
+        """Overrides the inherited method and simply returns None.
+        None indicates to urllib2 that the method could not handle the
+        error and that urllib2 should look for another handler.
+        """
+        return None
+    http_error_301 = http_error_303 = http_error_307 = http_error_302
+
+
 def setup_urllib2(debuglevel):
     handlers = [urllib2.HTTPBasicAuthHandler(IntePasswordManager())]
     if os.environ.has_key('https_proxy'):
@@ -50,6 +72,8 @@
         httphandler = urllib2.HTTPHandler(debuglevel=debuglevel)
         httpshandler = urllib2.HTTPSHandler(debuglevel=debuglevel)
         handlers.extend((httphandler, httpshandler))
+
+    handlers.append(HTTPRedirectHandler)
     urllib2.install_opener(urllib2.build_opener(*handlers))
 
 



More information about the Inteproxy-commits mailing list