--- .\Python 3.2.5.1\App\Scripts\setuptools\command\easy_install.py (original) +++ .\Python 3.2.5.1\App\Scripts\setuptools\command\easy_install.py (refactored) @@ -70,7 +70,7 @@ return s def isascii(s): try: - unicode(s, 'ascii') + str(s, 'ascii') return True except UnicodeError: return False @@ -200,7 +200,7 @@ def finalize_options(self): if self.version: - print 'distribute %s' % get_distribution('distribute').version + print('distribute %s' % get_distribution('distribute').version) sys.exit() py_version = sys.version.split()[0] @@ -265,7 +265,7 @@ self.script_dir = self.install_scripts # default --record from the install command self.set_undefined_options('install', ('record', 'record')) - normpath = map(normalize_path, sys.path) + normpath = list(map(normalize_path, sys.path)) self.all_site_dirs = get_site_dirs() if self.site_dirs is not None: site_dirs = [ @@ -298,7 +298,7 @@ self.local_index = Environment(self.shadow_path+sys.path) if self.find_links is not None: - if isinstance(self.find_links, basestring): + if isinstance(self.find_links, str): self.find_links = self.find_links.split() else: self.find_links = [] @@ -360,7 +360,7 @@ outputs = self.outputs if self.root: # strip any package prefix root_len = len(self.root) - for counter in xrange(len(outputs)): + for counter in range(len(outputs)): outputs[counter] = outputs[counter][root_len:] from distutils import file_util self.execute( @@ -380,7 +380,7 @@ try: pid = os.getpid() except: - pid = random.randint(0,sys.maxint) + pid = random.randint(0,sys.maxsize) return os.path.join(self.install_dir, "test-easy-install-%s" % pid) def warn_deprecated_options(self): @@ -425,7 +425,7 @@ self.pth_file = None PYTHONPATH = os.environ.get('PYTHONPATH','').split(os.pathsep) - if instdir not in map(normalize_path, filter(None,PYTHONPATH)): + if instdir not in list(map(normalize_path, [_f for _f in PYTHONPATH if _f])): # only PYTHONPATH dirs need a site.py, so pretend it's there self.sitepy_installed = True elif self.multi_version and not os.path.exists(pth_file): @@ -681,11 +681,11 @@ distros = WorkingSet([]).resolve( [requirement], self.local_index, self.easy_install ) - except DistributionNotFound, e: + except DistributionNotFound as e: raise DistutilsError( "Could not find required distribution %s" % e.args ) - except VersionConflict, e: + except VersionConflict as e: raise DistutilsError( "Installed distribution %s conflicts with requirement %s" % e.args @@ -776,7 +776,7 @@ f = open(target,"w"+mode) f.write(contents) f.close() - chmod(target, 0777-mask) + chmod(target, 0o777-mask) @@ -890,7 +890,7 @@ f = open(pkg_inf,'w') f.write('Metadata-Version: 1.0\n') for k,v in cfg.items('metadata'): - if k<>'target_version': + if k!='target_version': f.write('%s: %s\n' % (k.replace('_','-').title(), v)) f.close() script_dir = os.path.join(egg_info,'scripts') @@ -1044,7 +1044,7 @@ pkg_resources.require("%(name)s==%(version)s") # this exact version pkg_resources.require("%(name)s>=%(version)s") # this version or higher """ - if self.install_dir not in map(normalize_path,sys.path): + if self.install_dir not in list(map(normalize_path,sys.path)): msg += """ Note also that the installation directory must be on sys.path at runtime for @@ -1087,7 +1087,7 @@ ) try: run_setup(setup_script, args) - except SystemExit, v: + except SystemExit as v: raise DistutilsError("Setup script exited with %s" % (v.args[0],)) def build_and_install(self, setup_script, setup_base): @@ -1129,7 +1129,7 @@ 'site_dirs', 'allow_hosts', ) fetch_options = {} - for key, val in ei_opts.iteritems(): + for key, val in ei_opts.items(): if key not in fetch_directives: continue fetch_options[key.replace('_', '-')] = val[1] # create a settings dictionary suitable for `edit_config` @@ -1194,7 +1194,7 @@ self.byte_compile(to_compile) if not self.dry_run: for f in to_chmod: - mode = ((os.stat(f)[stat.ST_MODE]) | 0555) & 07755 + mode = ((os.stat(f)[stat.ST_MODE]) | 0o555) & 0o7755 chmod(f, mode) def byte_compile(self, to_compile): @@ -1308,10 +1308,10 @@ if not self.user: return home = convert_path(os.path.expanduser("~")) - for name, path in self.config_vars.iteritems(): + for name, path in self.config_vars.items(): if path.startswith(home) and not os.path.isdir(path): self.debug_print("os.makedirs('%s', 0700)" % path) - os.makedirs(path, 0700) + os.makedirs(path, 0o700) @@ -1339,7 +1339,7 @@ config_vars = config_vars.copy() config_vars['base'] = self.prefix scheme = self.INSTALL_SCHEMES.get(os.name,self.DEFAULT_SCHEME) - for attr,val in scheme.items(): + for attr,val in list(scheme.items()): if getattr(self,attr,None) is None: setattr(self,attr,val) @@ -1362,7 +1362,7 @@ def get_site_dirs(): # return a list of 'site' dirs - sitedirs = filter(None,os.environ.get('PYTHONPATH','').split(os.pathsep)) + sitedirs = [_f for _f in os.environ.get('PYTHONPATH','').split(os.pathsep) if _f] prefixes = [sys.prefix] if sys.exec_prefix != sys.prefix: prefixes.append(sys.exec_prefix) @@ -1400,7 +1400,7 @@ if HAS_USER_SITE: sitedirs.append(site.USER_SITE) - sitedirs = map(normalize_path, sitedirs) + sitedirs = list(map(normalize_path, sitedirs)) return sitedirs @@ -1462,13 +1462,13 @@ return None f.seek(prepended-12) - import struct, StringIO, ConfigParser + import struct, io, configparser tag, cfglen, bmlen = struct.unpack("2 or not name.endswith('.pth'): + if len(parts)!=2 or not name.endswith('.pth'): continue if name.endswith('-nspkg.pth'): continue @@ -1550,11 +1550,11 @@ dirty = False def __init__(self, filename, sitedirs=()): - self.filename = filename; self.sitedirs=map(normalize_path, sitedirs) + self.filename = filename; self.sitedirs=list(map(normalize_path, sitedirs)) self.basedir = normalize_path(os.path.dirname(self.filename)) self._load(); Environment.__init__(self, [], None, None) for path in yield_lines(self.paths): - map(self.add, find_distributions(path, True)) + list(map(self.add, find_distributions(path, True))) def _load(self): self.paths = [] @@ -1683,7 +1683,7 @@ chmod(arg, stat.S_IWRITE) return func(arg) exc = sys.exc_info() - raise exc[0], (exc[1][0], exc[1][1] + (" %s %s" % (func,arg))) + raise exc[0](exc[1][0], exc[1][1] + (" %s %s" % (func,arg))) def uncache_zipdir(path): """Ensure that the importer caches dont have stale info for `path`""" @@ -1783,7 +1783,7 @@ log.debug("changing mode of %s to %o", path, mode) try: _chmod(path, mode) - except os.error, e: + except os.error as e: log.debug("chmod failed: %s", e) def fix_jython_executable(executable, options): @@ -1811,7 +1811,7 @@ spec = str(dist.as_requirement()) header = get_script_header("", executable, wininst) for group in 'console_scripts', 'gui_scripts': - for name, ep in dist.get_entry_map(group).items(): + for name, ep in list(dist.get_entry_map(group).items()): script_text = ( "# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n" "__requires__ = %(spec)r\n" @@ -1867,7 +1867,7 @@ names = [] try: names = os.listdir(path) - except os.error, err: + except os.error as err: onerror(os.listdir, path, sys.exc_info()) for name in names: fullname = os.path.join(path, name) @@ -1880,7 +1880,7 @@ else: try: os.remove(fullname) - except os.error, err: + except os.error as err: onerror(os.remove, fullname, sys.exc_info()) try: os.rmdir(path) @@ -1888,7 +1888,7 @@ onerror(os.rmdir, path, sys.exc_info()) def current_umask(): - tmp = os.umask(022) + tmp = os.umask(0o22) os.umask(tmp) return tmp --- G:\Dev\Python\Python 3.2.5.1\App\Scripts\setuptools\command\easy_install.py (original) +++ G:\Dev\Python\Python 3.2.5.1\App\Scripts\setuptools\command\easy_install.py (refactored) @@ -70,7 +70,7 @@ return s def isascii(s): try: - unicode(s, 'ascii') + str(s, 'ascii') return True except UnicodeError: return False @@ -200,7 +200,7 @@ def finalize_options(self): if self.version: - print 'distribute %s' % get_distribution('distribute').version + print('distribute %s' % get_distribution('distribute').version) sys.exit() py_version = sys.version.split()[0] @@ -265,7 +265,7 @@ self.script_dir = self.install_scripts # default --record from the install command self.set_undefined_options('install', ('record', 'record')) - normpath = map(normalize_path, sys.path) + normpath = list(map(normalize_path, sys.path)) self.all_site_dirs = get_site_dirs() if self.site_dirs is not None: site_dirs = [ @@ -298,7 +298,7 @@ self.local_index = Environment(self.shadow_path+sys.path) if self.find_links is not None: - if isinstance(self.find_links, basestring): + if isinstance(self.find_links, str): self.find_links = self.find_links.split() else: self.find_links = [] @@ -360,7 +360,7 @@ outputs = self.outputs if self.root: # strip any package prefix root_len = len(self.root) - for counter in xrange(len(outputs)): + for counter in range(len(outputs)): outputs[counter] = outputs[counter][root_len:] from distutils import file_util self.execute( @@ -380,7 +380,7 @@ try: pid = os.getpid() except: - pid = random.randint(0,sys.maxint) + pid = random.randint(0,sys.maxsize) return os.path.join(self.install_dir, "test-easy-install-%s" % pid) def warn_deprecated_options(self): @@ -425,7 +425,7 @@ self.pth_file = None PYTHONPATH = os.environ.get('PYTHONPATH','').split(os.pathsep) - if instdir not in map(normalize_path, filter(None,PYTHONPATH)): + if instdir not in list(map(normalize_path, [_f for _f in PYTHONPATH if _f])): # only PYTHONPATH dirs need a site.py, so pretend it's there self.sitepy_installed = True elif self.multi_version and not os.path.exists(pth_file): @@ -681,11 +681,11 @@ distros = WorkingSet([]).resolve( [requirement], self.local_index, self.easy_install ) - except DistributionNotFound, e: + except DistributionNotFound as e: raise DistutilsError( "Could not find required distribution %s" % e.args ) - except VersionConflict, e: + except VersionConflict as e: raise DistutilsError( "Installed distribution %s conflicts with requirement %s" % e.args @@ -776,7 +776,7 @@ f = open(target,"w"+mode) f.write(contents) f.close() - chmod(target, 0777-mask) + chmod(target, 0o777-mask) @@ -890,7 +890,7 @@ f = open(pkg_inf,'w') f.write('Metadata-Version: 1.0\n') for k,v in cfg.items('metadata'): - if k<>'target_version': + if k!='target_version': f.write('%s: %s\n' % (k.replace('_','-').title(), v)) f.close() script_dir = os.path.join(egg_info,'scripts') @@ -1044,7 +1044,7 @@ pkg_resources.require("%(name)s==%(version)s") # this exact version pkg_resources.require("%(name)s>=%(version)s") # this version or higher """ - if self.install_dir not in map(normalize_path,sys.path): + if self.install_dir not in list(map(normalize_path,sys.path)): msg += """ Note also that the installation directory must be on sys.path at runtime for @@ -1087,7 +1087,7 @@ ) try: run_setup(setup_script, args) - except SystemExit, v: + except SystemExit as v: raise DistutilsError("Setup script exited with %s" % (v.args[0],)) def build_and_install(self, setup_script, setup_base): @@ -1129,7 +1129,7 @@ 'site_dirs', 'allow_hosts', ) fetch_options = {} - for key, val in ei_opts.iteritems(): + for key, val in ei_opts.items(): if key not in fetch_directives: continue fetch_options[key.replace('_', '-')] = val[1] # create a settings dictionary suitable for `edit_config` @@ -1194,7 +1194,7 @@ self.byte_compile(to_compile) if not self.dry_run: for f in to_chmod: - mode = ((os.stat(f)[stat.ST_MODE]) | 0555) & 07755 + mode = ((os.stat(f)[stat.ST_MODE]) | 0o555) & 0o7755 chmod(f, mode) def byte_compile(self, to_compile): @@ -1308,10 +1308,10 @@ if not self.user: return home = convert_path(os.path.expanduser("~")) - for name, path in self.config_vars.iteritems(): + for name, path in self.config_vars.items(): if path.startswith(home) and not os.path.isdir(path): self.debug_print("os.makedirs('%s', 0700)" % path) - os.makedirs(path, 0700) + os.makedirs(path, 0o700) @@ -1339,7 +1339,7 @@ config_vars = config_vars.copy() config_vars['base'] = self.prefix scheme = self.INSTALL_SCHEMES.get(os.name,self.DEFAULT_SCHEME) - for attr,val in scheme.items(): + for attr,val in list(scheme.items()): if getattr(self,attr,None) is None: setattr(self,attr,val) @@ -1362,7 +1362,7 @@ def get_site_dirs(): # return a list of 'site' dirs - sitedirs = filter(None,os.environ.get('PYTHONPATH','').split(os.pathsep)) + sitedirs = [_f for _f in os.environ.get('PYTHONPATH','').split(os.pathsep) if _f] prefixes = [sys.prefix] if sys.exec_prefix != sys.prefix: prefixes.append(sys.exec_prefix) @@ -1400,7 +1400,7 @@ if HAS_USER_SITE: sitedirs.append(site.USER_SITE) - sitedirs = map(normalize_path, sitedirs) + sitedirs = list(map(normalize_path, sitedirs)) return sitedirs @@ -1462,13 +1462,13 @@ return None f.seek(prepended-12) - import struct, StringIO, ConfigParser + import struct, io, configparser tag, cfglen, bmlen = struct.unpack("2 or not name.endswith('.pth'): + if len(parts)!=2 or not name.endswith('.pth'): continue if name.endswith('-nspkg.pth'): continue @@ -1550,11 +1550,11 @@ dirty = False def __init__(self, filename, sitedirs=()): - self.filename = filename; self.sitedirs=map(normalize_path, sitedirs) + self.filename = filename; self.sitedirs=list(map(normalize_path, sitedirs)) self.basedir = normalize_path(os.path.dirname(self.filename)) self._load(); Environment.__init__(self, [], None, None) for path in yield_lines(self.paths): - map(self.add, find_distributions(path, True)) + list(map(self.add, find_distributions(path, True))) def _load(self): self.paths = [] @@ -1683,7 +1683,7 @@ chmod(arg, stat.S_IWRITE) return func(arg) exc = sys.exc_info() - raise exc[0], (exc[1][0], exc[1][1] + (" %s %s" % (func,arg))) + raise exc[0](exc[1][0], exc[1][1] + (" %s %s" % (func,arg))) def uncache_zipdir(path): """Ensure that the importer caches dont have stale info for `path`""" @@ -1783,7 +1783,7 @@ log.debug("changing mode of %s to %o", path, mode) try: _chmod(path, mode) - except os.error, e: + except os.error as e: log.debug("chmod failed: %s", e) def fix_jython_executable(executable, options): @@ -1811,7 +1811,7 @@ spec = str(dist.as_requirement()) header = get_script_header("", executable, wininst) for group in 'console_scripts', 'gui_scripts': - for name, ep in dist.get_entry_map(group).items(): + for name, ep in list(dist.get_entry_map(group).items()): script_text = ( "# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n" "__requires__ = %(spec)r\n" @@ -1867,7 +1867,7 @@ names = [] try: names = os.listdir(path) - except os.error, err: + except os.error as err: onerror(os.listdir, path, sys.exc_info()) for name in names: fullname = os.path.join(path, name) @@ -1880,7 +1880,7 @@ else: try: os.remove(fullname) - except os.error, err: + except os.error as err: onerror(os.remove, fullname, sys.exc_info()) try: os.rmdir(path) @@ -1888,7 +1888,7 @@ onerror(os.rmdir, path, sys.exc_info()) def current_umask(): - tmp = os.umask(022) + tmp = os.umask(0o22) os.umask(tmp) return tmp