NGSegovia / wsgi-intercept

Automatically exported from code.google.com/p/wsgi-intercept
Other
0 stars 0 forks source link

wsgi_intercept's urlopen fails under Python 2.5 due to wsgi_intercept/urllib2_intercept/wsgi_urllib2.py #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Under Python 2.5, calls to urlopen using wsgi_intercept fail with the
following stacktrace:

Traceback (most recent call last):
  File "/Users/me/Projects/project/httpactions.py", line 42, in __call__
    response = urlopen(request)
  File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.
py",
line 121, in urlopen
    return _opener.open(url, data)
  File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.
py",
line 374, in open
    response = self._open(req, data)
  File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.
py",
line 392, in _open
    '_open', req)
  File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.
py",
line 353, in _call_chain
    result = func(*args)
  File
"/Users/me/Projects/project/eggs/wsgi_intercept-0.3.dev-py2.5.egg/wsgi_intercept
/urllib2/wsgi_urllib2.py",
line 31, in http_open
    return self.do_open(WSGI_HTTP, req)
  File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.
py",
line 1072, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
AttributeError: WSGI_HTTP instance has no attribute 'request'

This appears to be due to a change introduced in Python 2.4 and workaround
code in wsgi_intercept/urllib2_intercept/wsgi_urllib2.py that has an if
2.4/else clause, rather than an if 2.3/else clause.  The following diff
resolves this issue:

--- wsgi_intercept/urllib2_intercept/wsgi_urllib2.py    (revision 26)
+++ wsgi_intercept/urllib2_intercept/wsgi_urllib2.py    (working copy)
@@ -9,26 +9,26 @@
 # ugh, version dependence.
 #

-if sys.version_info[:2] == (2, 4,):
+if sys.version_info[:2] == (2, 3):
+    class WSGI_HTTP(HTTP):
+        _connection_class = WSGI_HTTPConnection
+
     class WSGI_HTTPHandler(HTTPHandler):
         """
         Override the default HTTPHandler class with one that uses the
         WSGI_HTTPConnection class to open HTTP URLs.
         """
         def http_open(self, req):
-            return self.do_open(WSGI_HTTPConnection, req)
+            return self.do_open(WSGI_HTTP, req)

 else:
-    class WSGI_HTTP(HTTP):
-        _connection_class = WSGI_HTTPConnection
-
     class WSGI_HTTPHandler(HTTPHandler):
         """
         Override the default HTTPHandler class with one that uses the
         WSGI_HTTPConnection class to open HTTP URLs.
         """
         def http_open(self, req):
-            return self.do_open(WSGI_HTTP, req)
+            return self.do_open(WSGI_HTTPConnection, req)

 def install_opener():
     handler = WSGI_HTTPHandler()

Original issue reported on code.google.com by jcous...@gmail.com on 4 Dec 2007 at 11:37

GoogleCodeExporter commented 8 years ago

Original comment by kumar.mcmillan on 10 Dec 2007 at 2:11

GoogleCodeExporter commented 8 years ago
thanks Jeff.  committed to rel_0_3 branch, installable as:

easy_install -U http://wsgi-intercept.googlecode.com/svn/branches/rel_0_3

(or you can wait until I cut 0.3.1, which will hopefully be today)

Original comment by kumar.mcmillan on 10 Dec 2007 at 4:50

GoogleCodeExporter commented 8 years ago
yep, this was released today in 0.3.1.  To install:

easy_install -U wsgi_intercept

Original comment by kumar.mcmillan on 10 Dec 2007 at 5:05

GoogleCodeExporter commented 8 years ago
tagging with the proper 0.3 milestone for safe-keeping

Original comment by kumar.mcmillan on 6 Jan 2008 at 9:20