matt chisholm committed 5890658 Draft

support Python 3

Comments (0)

Files changed (1)

 import sys, os, zipimport, time, re, imp, types
-from urlparse import urlparse, urlunparse
+    from urlparse import urlparse, urlunparse
+except ImportError:
+    from urllib.parse import urlparse, urlunparse
 from os import open as os_open
 from os.path import isdir, split
+    basestring
+except NameError:
+    basestring = type('') # Python3 support
 # This marker is used to simplify the process that checks is the
 # setuptools package was installed by the Setuptools project
 # or by the Distribute project, in case Setuptools creates
 # attribute is present to decide wether to reinstall the package
 _distribute = True
-def _bypass_ensure_directory(name, mode=0777):
+def _bypass_ensure_directory(name, mode=int('0777', 8)):
     # Sandbox-bypassing version of ensure_directory()
     if not WRITE_SUPPORT:
         raise IOError('"os.mkdir" not supported on this platform.')
 def _declare_state(vartype, **kw):
     g = globals()
-    for name, val in kw.iteritems():
+    for name, val in kw.items():
         g[name] = val
         _state_vars[name] = vartype
 def __getstate__():
     state = {}
     g = globals()
-    for k, v in _state_vars.iteritems():
+    for k, v in _state_vars.items():
         state[k] = g['_sget_'+v](g[k])
     return state
 def __setstate__(state):
     g = globals()
-    for k, v in state.iteritems():
+    for k, v in state.items():
         g['_sset_'+_state_vars[k]](k, g[k], v)
     return state
                     resolvees = shadow_set.resolve(req, env, installer)
-                except ResolutionError,v:
+                except ResolutionError as v:
                     error_info[dist] = v    # save error info
                     if fallback:
                         continue    # try the next older version of project
         return (self.entries[:], self.entry_keys.copy(), self.by_key.copy(),
-    def __setstate__(self, (entries, keys, by_key, callbacks)):
+    def __setstate__(self, args):
+        (entries, keys, by_key, callbacks) = args
         self.entries = entries[:]
         self.entry_keys = keys.copy()
         self.by_key = by_key.copy()
         if == 'posix':
             # Make the resource executable
-            mode = ((os.stat(tempname).st_mode) | 0555) & 07777
+            mode = ((os.stat(tempname).st_mode) | int('0555', 8)) & int('07777', 8)
             os.chmod(tempname, mode)
                 len(script_text), 0, script_text.split('\n'), script_filename
             script_code = compile(script_text,script_filename,'exec')
-            exec script_code in namespace, namespace
+            exec(script_code, namespace, namespace)
     def _has(self, path):
         raise NotImplementedError(
 def yield_lines(strs):
     """Yield non-empty/non-comment lines of a ``basestring`` or sequence"""
-    if isinstance(strs,basestring):
+    if isinstance(strs, basestring):
         for s in strs.splitlines():
             s = s.strip()
             if s and not s.startswith('#'):     # skip blank lines/comments
     def __getattr__(self,attr):
         """Delegate all unrecognized public attributes to .metadata provider"""
         if attr.startswith('_'):
-            raise AttributeError,attr
+            raise AttributeError(attr)
         return getattr(self._provider, attr)
         nloc = _normalize_cached(loc)
         bdir = os.path.dirname(nloc)
-        npath= map(_normalize_cached, path)
+        npath= list(map(_normalize_cached, path))
         bp = None
         for p, item in enumerate(npath):
     def __contains__(self,item):
         if isinstance(item,Distribution):
-            if item.key <> self.key: return False
+            if item.key != self.key: return False
             if self.index: item = item.parsed_version  # only get if we need it
         elif isinstance(item,basestring):
             item = parse_version(item)