suds python 3 patches / urllib2

# HG changeset patch
# Parent e82ce4498160900648517fd7e02f005119d53ed4
fix urllib2 importing

2to3 is able to convert urllib2 and urllib to the new unified urllib library
just fine. But not if urllib is imported under a different name (u2)

diff --git a/suds/transport/http.py b/suds/transport/http.py
--- a/suds/transport/http.py
+++ b/suds/transport/http.py
@@ -18,9 +18,10 @@
 Contains classes for basic HTTP transport implementations.
 """
 
-import urllib2 as u2
+import urllib2
 import base64
 import socket
+import sys
 from suds.transport import *
 from suds.properties import Unskin
 from urlparse import urlparse
@@ -57,10 +58,10 @@
         try:
             url = request.url
             log.debug('opening (%s)', url)
-            u2request = u2.Request(url)
+            u2request = urllib2.Request(url)
             self.proxy = self.options.proxy
             return self.u2open(u2request)
-        except u2.HTTPError, e:
+        except urllib2.HTTPError, e:
             raise TransportError(str(e), e.code, e.fp)
 
     def send(self, request):
@@ -69,7 +70,7 @@
         msg = request.message
         headers = request.headers
         try:
-            u2request = u2.Request(url, msg, headers)
+            u2request = urllib2.Request(url, msg, headers)
             self.addcookies(u2request)
             self.proxy = self.options.proxy
             request.headers.update(u2request.headers)
@@ -78,7 +79,7 @@
             self.getcookies(fp, u2request)
             result = Reply(200, fp.headers.dict, fp.read())
             log.debug('received:\n%s', result)
-        except u2.HTTPError, e:
+        except urllib2.HTTPError, e:
             if e.code in (202,204):
                 result = None
             else:
@@ -111,7 +112,7 @@
         """
         tm = self.options.timeout
         url = self.u2opener()
-        if self.u2ver() < 2.6:
+        if (sys.version_info < (3, 0)) and (self.u2ver() < 2.6):
             socket.setdefaulttimeout(tm)
             return url.open(u2request)
         else:
@@ -124,7 +125,7 @@
         @rtype: I{OpenerDirector}
         """
         if self.urlopener is None:
-            return u2.build_opener(*self.u2handlers())
+            return urllib2.build_opener(*self.u2handlers())
         else:
             return self.urlopener
 
@@ -135,7 +136,7 @@
         @rtype: [Handler,...]
         """
         handlers = []
-        handlers.append(u2.ProxyHandler(self.proxy))
+        handlers.append(urllib2.ProxyHandler(self.proxy))
         return handlers
 
     def u2ver(self):
@@ -145,7 +146,7 @@
         @rtype: float
         """
         try:
-            part = u2.__version__.split('.', 1)
+            part = urllib2.__version__.split('.', 1)
             n = float('.'.join(part))
             return n
         except Exception, e:
diff --git a/suds/transport/https.py b/suds/transport/https.py
--- a/suds/transport/https.py
+++ b/suds/transport/https.py
@@ -18,7 +18,7 @@
 Contains classes for basic HTTP (authenticated) transport implementations.
 """
 
-import urllib2 as u2
+import urllib2
 from suds.transport import *
 from suds.transport.http import HttpTransport
 from logging import getLogger
@@ -53,7 +53,7 @@
                     - default: None
         """
         HttpTransport.__init__(self, **kwargs)
-        self.pm = u2.HTTPPasswordMgrWithDefaultRealm()
+        self.pm = urllib2.HTTPPasswordMgrWithDefaultRealm()
 
     def open(self, request):
         self.addcredentials(request)
@@ -75,7 +75,7 @@
 
     def u2handlers(self):
             handlers = HttpTransport.u2handlers(self)
-            handlers.append(u2.HTTPBasicAuthHandler(self.pm))
+            handlers.append(urllib2.HTTPBasicAuthHandler(self.pm))
             return handlers
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.