[Checkins] SVN: zc.buildout/branch/regebro-python3/ OK, now fails on installing zope.testing under Python 3. Good checkpoint.

Lennart Regebro regebro at gmail.com
Thu Apr 15 06:07:24 EDT 2010


Log message for revision 110937:
  OK, now fails on installing zope.testing under Python 3. Good checkpoint.
  

Changed:
  U   zc.buildout/branch/regebro-python3/dev.py
  U   zc.buildout/branch/regebro-python3/src/zc/buildout/__init__.py
  U   zc.buildout/branch/regebro-python3/src/zc/buildout/buildout.py
  U   zc.buildout/branch/regebro-python3/src/zc/buildout/download.py
  U   zc.buildout/branch/regebro-python3/src/zc/buildout/easy_install.py
  U   zc.buildout/branch/regebro-python3/src/zc/buildout/rmtree.py
  U   zc.buildout/branch/regebro-python3/src/zc/buildout/testing.py
  U   zc.buildout/branch/regebro-python3/src/zc/buildout/testrecipes.py
  U   zc.buildout/branch/regebro-python3/src/zc/buildout/tests.py

-=-
Modified: zc.buildout/branch/regebro-python3/dev.py
===================================================================
--- zc.buildout/branch/regebro-python3/dev.py	2010-04-15 07:57:23 UTC (rev 110936)
+++ zc.buildout/branch/regebro-python3/dev.py	2010-04-15 10:07:24 UTC (rev 110937)
@@ -19,7 +19,11 @@
 $Id$
 """
 
-import os, shutil, sys, subprocess, urllib2
+import os, shutil, sys, subprocess
+try:
+    from urllib2 import urlopen
+except: # Python 3
+    from urllib.request import urlopen
 
 is_jython = sys.platform.startswith('java')
 
@@ -34,8 +38,8 @@
     import pkg_resources
 except ImportError:
     ez = {}
-    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
-                         ).read() in ez
+    exec(urlopen('http://python-distribute.org/distribute_setup.py'
+                         ).read(), ez)
     ez['use_setuptools'](to_dir='eggs', download_delay=0)
 
     import pkg_resources

Modified: zc.buildout/branch/regebro-python3/src/zc/buildout/__init__.py
===================================================================
--- zc.buildout/branch/regebro-python3/src/zc/buildout/__init__.py	2010-04-15 07:57:23 UTC (rev 110936)
+++ zc.buildout/branch/regebro-python3/src/zc/buildout/__init__.py	2010-04-15 10:07:24 UTC (rev 110937)
@@ -21,4 +21,4 @@
     """
 
     def __str__(self):
-        return " ".join(map(str, self))
+        return " ".join(map(str, self.args))

Modified: zc.buildout/branch/regebro-python3/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branch/regebro-python3/src/zc/buildout/buildout.py	2010-04-15 07:57:23 UTC (rev 110936)
+++ zc.buildout/branch/regebro-python3/src/zc/buildout/buildout.py	2010-04-15 10:07:24 UTC (rev 110937)
@@ -14,7 +14,7 @@
 """Buildout main script
 """
 
-from rmtree import rmtree
+from .rmtree import rmtree
 try:
     from hashlib import md5
 except ImportError:
@@ -22,11 +22,11 @@
     from md5 import md5
 
 try:
-    import UserDict
+    from collections import MutableMapping as DictMixin
 except ImportError:
-    # Python 3
-    from collections import UserDict
-import ConfigParser
+    # Python < 2.6
+    from UserDict import DictMixin
+import configparser
 import copy
 import distutils.errors
 import glob
@@ -79,20 +79,20 @@
     return data
 
 def _print_annotate(data):
-    sections = data.keys()
+    sections = list(data.keys())
     sections.sort()
-    print
-    print "Annotated sections"
-    print "="*len("Annotated sections")
+    print()
+    print("Annotated sections")
+    print("="*len("Annotated sections"))
     for section in sections:
-        print
-        print '[%s]' % section
-        keys = data[section].keys()
+        print()
+        print('[%s]' % section)
+        keys = list(data[section].keys())
         keys.sort()
         for key in keys:
             value, notes = data[section][key]
             keyvalue = "%s= %s" % (key, value)
-            print keyvalue
+            print(keyvalue)
             line = '   '
             for note in notes.split():
                 if note == '[+]':
@@ -100,9 +100,9 @@
                 elif note == '[-]':
                     line = '-= '
                 else:
-                    print line, note
+                    print(line, note)
                     line = '   '
-    print
+    print()
 
 
 def _unannotate_section(section):
@@ -137,11 +137,11 @@
     except ValueError:
         _error("Timeout value must be numeric [%s]." % timeout_string)
     current_timeout = socket.getdefaulttimeout()
-    if current_timeout <> timeout:
+    if current_timeout != timeout:
         socket.setdefaulttimeout(timeout)
 
 
-class Buildout(UserDict.DictMixin):
+class Buildout(DictMixin):
 
     def __init__(self, config_file, cloptions,
                  user_defaults=True, windows_restart=False, command=None):
@@ -159,7 +159,7 @@
             base = os.path.dirname(config_file)
             if not os.path.exists(config_file):
                 if command == 'init':
-                    print 'Creating %r.' % config_file
+                    print('Creating %r.' % config_file)
                     open(config_file, 'w').write('[buildout]\nparts = \n')
                 elif command == 'setup':
                     # Sigh. This model of a buildout instance
@@ -438,11 +438,11 @@
         if self._log_level < logging.DEBUG:
             sections = list(self)
             sections.sort()
-            print
-            print 'Configuration data:'
+            print()
+            print('Configuration data:')
             for section in self._data:
                 _save_options(section, self[section], sys.stdout)
-            print
+            print()
 
 
         # compute new part recipe signatures
@@ -589,7 +589,7 @@
         installed = self['buildout']['installed']
         f = open(installed, 'a')
         f.write('\n[buildout]\n')
-        for option, value in buildout_options.items():
+        for option, value in list(buildout_options.items()):
             _save_option(option, value, f)
         f.close()
 
@@ -605,7 +605,7 @@
                 recipe, 'zc.buildout.uninstall', entry, self)
             self._logger.info('Running uninstall recipe.')
             uninstaller(part, installed_part_options[part])
-        except (ImportError, pkg_resources.DistributionNotFound), v:
+        except (ImportError, pkg_resources.DistributionNotFound) as v:
             pass
 
         # remove created files and directories
@@ -695,7 +695,7 @@
     def _read_installed_part_options(self):
         old = self['buildout']['installed']
         if old and os.path.isfile(old):
-            parser = ConfigParser.RawConfigParser()
+            parser = configparser.RawConfigParser()
             parser.optionxform = lambda s: s
             parser.read(old)
             result = {}
@@ -745,7 +745,7 @@
         installed = recipe_class(self, part, options).install()
         if installed is None:
             installed = []
-        elif isinstance(installed, basestring):
+        elif isinstance(installed, str):
             installed = [installed]
         base = self._buildout_path('')
         installed = [d.startswith(base) and d[len(base):] or d
@@ -760,7 +760,7 @@
         f = open(installed, 'w')
         _save_options('buildout', installed_options['buildout'], f)
         for part in installed_options['buildout']['parts'].split():
-            print >>f
+            print(file=f)
             _save_options(part, installed_options[part], f)
         f.close()
 
@@ -769,7 +769,7 @@
 
     def _display_socket_timeout(self):
         current_timeout = socket.getdefaulttimeout()
-        if current_timeout <> DEFAULT_SOCKET_TIMEOUT:
+        if current_timeout != DEFAULT_SOCKET_TIMEOUT:
             info_msg = 'Socket timeout is set to %d seconds.' % current_timeout
             self._logger.info(info_msg)
 
@@ -855,7 +855,7 @@
             return
 
         if sys.platform == 'win32' and not self.__windows_restart:
-            args = map(zc.buildout.easy_install._safe_arg, sys.argv)
+            args = list(map(zc.buildout.easy_install._safe_arg, sys.argv))
             args.insert(1, '-W')
             if not __debug__:
                 args.insert(0, '-O')
@@ -879,7 +879,7 @@
             )
 
         # Restart
-        args = map(zc.buildout.easy_install._safe_arg, sys.argv)
+        args = list(map(zc.buildout.easy_install._safe_arg, sys.argv))
         if not __debug__:
             args.insert(0, '-O')
         args.insert(0, zc.buildout.easy_install._safe_arg (sys.executable))
@@ -995,10 +995,13 @@
         raise NotImplementedError('__delitem__')
 
     def keys(self):
-        return self._raw.keys()
+        return list(self._raw.keys())
 
     def __iter__(self):
         return iter(self._raw)
+    
+    def __len__(self):
+        return len(self.keys())
 
 
 def _install_and_load(spec, group, entry, buildout):
@@ -1032,14 +1035,14 @@
         return pkg_resources.load_entry_point(
             req.project_name, group, entry)
 
-    except Exception, v:
+    except Exception as v:
         buildout._logger.log(
             1,
             "Could't load %s entry point %s\nfrom %s:\n%s.",
             group, entry, spec, v)
         raise
 
-class Options(UserDict.DictMixin):
+class Options(DictMixin):
 
     def __init__(self, buildout, section, data):
         self.buildout = buildout
@@ -1056,7 +1059,7 @@
             self._raw = self._do_extend_raw(name, self._raw, [])
 
         # force substitutions
-        for k, v in self._raw.items():
+        for k, v in list(self._raw.items()):
             if '${' in v:
                 self._dosub(k, v)
 
@@ -1207,8 +1210,15 @@
         elif key in self._data:
             del self._data[key]
         else:
-            raise KeyError, key
+            raise KeyError(key)
 
+    def __len__(self):
+        return len(self.keys())
+        
+    def __iter__(self):
+        for k in self.keys():
+            yield k
+
     def keys(self):
         raw = self._raw
         return list(self._raw) + [k for k in self._data if k not in raw]
@@ -1283,11 +1293,11 @@
         value = '%(__buildout_space_n__)s' + value[2:]
     if value.endswith('\n\t'):
         value = value[:-2] + '%(__buildout_space_n__)s'
-    print >>f, option, '=', value
+    print(option, '=', value, file=f)
 
 def _save_options(section, options, f):
-    print >>f, '[%s]' % section
-    items = options.items()
+    print('[%s]' % section, file=f)
+    items = list(options.items())
     items.sort()
     for option, value in items:
         _save_option(option, value, f)
@@ -1332,7 +1342,7 @@
 
     result = {}
 
-    parser = ConfigParser.RawConfigParser()
+    parser = configparser.RawConfigParser()
     parser.optionxform = lambda s: s
     parser.readfp(fp)
     if is_temp:
@@ -1403,7 +1413,7 @@
 
 def _update_section(s1, s2):
     s2 = s2.copy() # avoid mutating the second argument, which is unexpected
-    for k, v in s2.items():
+    for k, v in list(s2.items()):
         v2, note2 = v
         if k.endswith('+'):
             key = k.rstrip(' +')
@@ -1590,7 +1600,7 @@
 
 """
 def _help():
-    print _usage
+    print(_usage)
     sys.exit(0)
 
 def main(args=None):
@@ -1684,7 +1694,7 @@
             getattr(buildout, command)(args)
         except SystemExit:
             pass
-        except Exception, v:
+        except Exception as v:
             _doing()
             exc_info = sys.exc_info()
             import pdb, traceback
@@ -1694,7 +1704,7 @@
                 pdb.post_mortem(exc_info[2])
             else:
                 if isinstance(v, (zc.buildout.UserError,
-                                  distutils.errors.DistutilsError,
+                                  distutils.errors.DistutilsError
                                   )
                               ):
                     _error(str(v))

Modified: zc.buildout/branch/regebro-python3/src/zc/buildout/download.py
===================================================================
--- zc.buildout/branch/regebro-python3/src/zc/buildout/download.py	2010-04-15 07:57:23 UTC (rev 110936)
+++ zc.buildout/branch/regebro-python3/src/zc/buildout/download.py	2010-04-15 10:07:24 UTC (rev 110937)
@@ -24,13 +24,16 @@
 import re
 import shutil
 import tempfile
-import urllib
-import urlparse
+try:
+    from urllib.request import URLopener, FancyURLopener
+except ImportError: # Python 2
+    from urllib import URLopener, FancyURLopener
+
 import zc.buildout
 
 
-class URLOpener(urllib.FancyURLopener):
-    http_error_default = urllib.URLopener.http_error_default
+class URLOpener(FancyURLopener):
+    http_error_default = URLopener.http_error_default
 
 
 class ChecksumError(zc.buildout.UserError):
@@ -151,7 +154,7 @@
         """
         if re.match(r"^[A-Za-z]:\\", url):
             url = 'file:' + url
-        parsed_url = urlparse.urlparse(url, 'file')
+        parsed_url = urllib.parse.urlparse(url, 'file')
         url_scheme, _, url_path = parsed_url[:3]
         if url_scheme == 'file':
             self.logger.debug('Using local resource %s' % url)
@@ -166,11 +169,11 @@
                 "Couldn't download %r in offline mode." % url)
 
         self.logger.info('Downloading %s' % url)
-        urllib._urlopener = url_opener
+        urllib.request._urlopener = url_opener
         handle, tmp_path = tempfile.mkstemp(prefix='buildout-')
         try:
             try:
-                tmp_path, headers = urllib.urlretrieve(url, tmp_path)
+                tmp_path, headers = urllib.request.urlretrieve(url, tmp_path)
                 if not check_md5sum(tmp_path, md5sum):
                     raise ChecksumError(
                         'MD5 checksum mismatch downloading %r' % url)
@@ -195,7 +198,7 @@
         else:
             if re.match(r"^[A-Za-z]:\\", url):
                 url = 'file:' + url
-            parsed = urlparse.urlparse(url, 'file')
+            parsed = urllib.parse.urlparse(url, 'file')
             url_path = parsed[2]
 
             if parsed[0] == 'file':

Modified: zc.buildout/branch/regebro-python3/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branch/regebro-python3/src/zc/buildout/easy_install.py	2010-04-15 07:57:23 UTC (rev 110936)
+++ zc.buildout/branch/regebro-python3/src/zc/buildout/easy_install.py	2010-04-15 10:07:24 UTC (rev 110937)
@@ -658,8 +658,8 @@
         while 1:
             try:
                 ws.resolve(requirements)
-            except pkg_resources.DistributionNotFound, err:
-                [requirement] = err
+            except pkg_resources.DistributionNotFound as err:
+                [requirement] = err.args
                 requirement = self._constrain(requirement)
                 if destination:
                     logger.debug('Getting required %r', str(requirement))
@@ -672,7 +672,7 @@
 
                     ws.add(dist)
                     self._maybe_add_setuptools(ws, dist)
-            except pkg_resources.VersionConflict, err:
+            except pkg_resources.VersionConflict as err:
                 raise VersionConflict(err, ws)
             else:
                 break
@@ -863,12 +863,14 @@
         undo.append(lambda: os.remove(tsetup))
         undo.append(lambda: os.close(fd))
 
-        os.write(fd, runsetup_template % dict(
+        filecontent = runsetup_template % dict(
             setuptools=setuptools_loc,
             setupdir=directory,
             setup=setup,
             __file__ = setup,
-            ))
+            )
+        # os.write always needs binary data, so we encode it:
+        os.write(fd, filecontent.encode())
 
         tmp3 = tempfile.mkdtemp('build', dir=dest)
         undo.append(lambda : shutil.rmtree(tmp3))
@@ -915,7 +917,7 @@
 
     path = [dist.location for dist in working_set]
     path.extend(extra_paths)
-    path = map(realpath, path)
+    path = list(map(realpath, path))
 
     generated = []
 
@@ -1056,7 +1058,7 @@
         logger.info("Generated script %r.", script)
 
         try:
-            os.chmod(dest, 0755)
+            os.chmod(dest, 0o755)
         except (AttributeError, os.error):
             pass
 
@@ -1108,7 +1110,7 @@
     if changed:
         open(dest, 'w').write(contents)
         try:
-            os.chmod(dest,0755)
+            os.chmod(dest,0o755)
         except (AttributeError, os.error):
             pass
         logger.info("Generated interpreter %r.", script)
@@ -1144,7 +1146,7 @@
         sys.argv[:] = _args
         __file__ = _args[0]
         del _options, _args
-        execfile(__file__)
+        exec(open(__file__).read())
 
 if _interactive:
     del _interactive
@@ -1161,7 +1163,7 @@
 
 os.chdir(%(setupdir)r)
 sys.argv[0] = %(setup)r
-execfile(%(setup)r)
+exec(open(%(setup)r).read())
 """
 
 

Modified: zc.buildout/branch/regebro-python3/src/zc/buildout/rmtree.py
===================================================================
--- zc.buildout/branch/regebro-python3/src/zc/buildout/rmtree.py	2010-04-15 07:57:23 UTC (rev 110936)
+++ zc.buildout/branch/regebro-python3/src/zc/buildout/rmtree.py	2010-04-15 10:07:24 UTC (rev 110937)
@@ -54,7 +54,7 @@
     0
     """
     def retry_writeable (func, path, exc):
-        os.chmod (path, 0600)
+        os.chmod (path, 0o600)
         func (path)
 
     shutil.rmtree (path, onerror = retry_writeable)

Modified: zc.buildout/branch/regebro-python3/src/zc/buildout/testing.py
===================================================================
--- zc.buildout/branch/regebro-python3/src/zc/buildout/testing.py	2010-04-15 07:57:23 UTC (rev 110936)
+++ zc.buildout/branch/regebro-python3/src/zc/buildout/testing.py	2010-04-15 10:07:24 UTC (rev 110937)
@@ -16,7 +16,7 @@
 $Id$
 """
 
-import BaseHTTPServer
+import http.server
 import errno
 import logging
 import os
@@ -30,7 +30,7 @@
 import tempfile
 import threading
 import time
-import urllib2
+import urllib.request, urllib.error, urllib.parse
 
 import zc.buildout.buildout
 import zc.buildout.easy_install
@@ -49,7 +49,7 @@
         and os.path.exists(path+'-script.py')
         ):
         path = path+'-script.py'
-    print open(path).read(),
+    print(open(path).read(), end=' ')
 
 def ls(dir, *subs):
     if subs:
@@ -58,12 +58,12 @@
     names.sort()
     for name in names:
         if os.path.isdir(os.path.join(dir, name)):
-            print 'd ',
+            print('d ', end=' ')
         elif os.path.islink(os.path.join(dir, name)):
-            print 'l ',
+            print('l ', end=' ')
         else:
-            print '- ',
-        print name
+            print('- ', end=' ')
+        print(name)
 
 def mkdir(*path):
     os.mkdir(os.path.join(*path))
@@ -110,7 +110,7 @@
     return result
 
 def get(url):
-    return urllib2.urlopen(url).read()
+    return urllib.request.urlopen(url).read()
 
 def _runsetup(setup, executable, *args):
     if os.path.isdir(setup):
@@ -313,10 +313,10 @@
     for f in test.globs['__tear_downs']:
         f()
 
-class Server(BaseHTTPServer.HTTPServer):
+class Server(http.server.HTTPServer):
 
     def __init__(self, tree, *args):
-        BaseHTTPServer.HTTPServer.__init__(self, *args)
+        http.server.HTTPServer.__init__(self, *args)
         self.tree = os.path.abspath(tree)
 
     __run = True
@@ -327,14 +327,14 @@
     def handle_error(self, *_):
         self.__run = False
 
-class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
+class Handler(http.server.BaseHTTPRequestHandler):
 
     Server.__log = False
 
     def __init__(self, request, address, server):
         self.__server = server
         self.tree = server.tree
-        BaseHTTPServer.BaseHTTPRequestHandler.__init__(
+        http.server.BaseHTTPRequestHandler.__init__(
             self, request, address, server)
 
     def do_GET(self):
@@ -397,7 +397,7 @@
 
     def log_request(self, code):
         if self.__server.__log:
-            print '%s %s %s' % (self.command, code, self.path)
+            print('%s %s %s' % (self.command, code, self.path))
 
 def _run(tree, port):
     server_address = ('localhost', port)
@@ -415,7 +415,7 @@
                 return port
         finally:
             s.close()
-    raise RuntimeError, "Can't find port"
+    raise RuntimeError("Can't find port")
 
 def _start_server(tree, name=''):
     port = get_port()
@@ -430,7 +430,7 @@
 
 def stop_server(url, thread=None):
     try:
-        urllib2.urlopen(url+'__stop__')
+        urllib.request.urlopen(url+'__stop__')
     except Exception:
         pass
     if thread is not None:
@@ -446,7 +446,7 @@
             s.close()
             if up:
                 break
-        except socket.error, e:
+        except socket.error as e:
             if e[0] not in (errno.ECONNREFUSED, errno.ECONNRESET):
                 raise
             s.close()
@@ -459,7 +459,7 @@
             raise SystemError("Couln't stop server")
 
 def install(project, destination):
-    if not isinstance(destination, basestring):
+    if not isinstance(destination, str):
         destination = os.path.join(destination.globs['sample_buildout'],
                                    'eggs')
 
@@ -479,7 +479,7 @@
              ).write(dist.location)
 
 def install_develop(project, destination):
-    if not isinstance(destination, basestring):
+    if not isinstance(destination, str):
         destination = os.path.join(destination.globs['sample_buildout'],
                                    'develop-eggs')
 

Modified: zc.buildout/branch/regebro-python3/src/zc/buildout/testrecipes.py
===================================================================
--- zc.buildout/branch/regebro-python3/src/zc/buildout/testrecipes.py	2010-04-15 07:57:23 UTC (rev 110936)
+++ zc.buildout/branch/regebro-python3/src/zc/buildout/testrecipes.py	2010-04-15 10:07:24 UTC (rev 110937)
@@ -7,10 +7,10 @@
         self.options = options
 
     def install(self):
-        items = self.options.items()
+        items = list(self.options.items())
         items.sort()
         for option, value in items:
-            print "  %s=%r" % (option, value)
+            print("  %s=%r" % (option, value))
         return ()
 
     update = install

Modified: zc.buildout/branch/regebro-python3/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/branch/regebro-python3/src/zc/buildout/tests.py	2010-04-15 07:57:23 UTC (rev 110936)
+++ zc.buildout/branch/regebro-python3/src/zc/buildout/tests.py	2010-04-15 10:07:24 UTC (rev 110937)
@@ -2148,9 +2148,9 @@
         )
 
     if dist.extras:
-        print 'downloaded', dist.version
+        print('downloaded', dist.version)
     else:
-        print 'had', dist.version
+        print('had', dist.version)
     sys.path_importer_cache.clear()
 
 def prefer_final():



More information about the checkins mailing list