[Checkins] SVN: zc.buildout/branches/regebro-python3/ Fixed syntax errors and imports

Lennart Regebro regebro at gmail.com
Sat Jul 24 06:45:21 EDT 2010


Log message for revision 114985:
  Fixed syntax errors and imports

Changed:
  U   zc.buildout/branches/regebro-python3/bootstrap/bootstrap.py
  U   zc.buildout/branches/regebro-python3/bootstrap/newbootstrap.py
  U   zc.buildout/branches/regebro-python3/src/zc/buildout/testing.py
  U   zc.buildout/branches/regebro-python3/src/zc/buildout/tests.py

-=-
Modified: zc.buildout/branches/regebro-python3/bootstrap/bootstrap.py
===================================================================
--- zc.buildout/branches/regebro-python3/bootstrap/bootstrap.py	2010-07-24 10:11:46 UTC (rev 114984)
+++ zc.buildout/branches/regebro-python3/bootstrap/bootstrap.py	2010-07-24 10:45:21 UTC (rev 114985)
@@ -53,7 +53,7 @@
     VERSION = ''
 
 USE_DISTRIBUTE = options.distribute
-if sys.version > '3':
+if sys.version >= '3':
     USE_DISTRIBUTE = True
     
 args = args + ['bootstrap']

Modified: zc.buildout/branches/regebro-python3/bootstrap/newbootstrap.py
===================================================================
--- zc.buildout/branches/regebro-python3/bootstrap/newbootstrap.py	2010-07-24 10:11:46 UTC (rev 114984)
+++ zc.buildout/branches/regebro-python3/bootstrap/newbootstrap.py	2010-07-24 10:45:21 UTC (rev 114985)
@@ -18,7 +18,11 @@
 use the -c option to specify an alternate configuration file.
 """
 
-import os, shutil, sys, tempfile, textwrap, urllib, urllib2
+import os, shutil, sys, tempfile, textwrap
+try:
+    from urllib2 import urlopen, pathname2url
+except ImportError:
+    from urllib.request import urlopen, pathname2url
 from optparse import OptionParser
 
 if sys.platform == 'win32':
@@ -64,7 +68,7 @@
     if value:
         if '://' not in value: # It doesn't smell like a URL.
             value = 'file://%s' % (
-                urllib.pathname2url(
+                pathname2url(
                     os.path.abspath(os.path.expanduser(value))),)
         if opt_str == '--download-base' and not value.endswith('/'):
             # Download base needs a trailing slash to make the world happy.
@@ -137,7 +141,7 @@
     if not hasattr(pkg_resources, '_distribute'):
         raise ImportError
 except ImportError:
-    ez_code = urllib2.urlopen(
+    ez_code = urlopen(
         options.setup_source).read().replace('\r\n', '\n')
     ez = {}
     exec ez_code in ez

Modified: zc.buildout/branches/regebro-python3/src/zc/buildout/testing.py
===================================================================
--- zc.buildout/branches/regebro-python3/src/zc/buildout/testing.py	2010-07-24 10:11:46 UTC (rev 114984)
+++ zc.buildout/branches/regebro-python3/src/zc/buildout/testing.py	2010-07-24 10:45:21 UTC (rev 114985)
@@ -16,7 +16,13 @@
 $Id$
 """
 
-import BaseHTTPServer
+try:
+    import BaseHTTPServer
+    from urllib2 import urlopen
+except ImportError:
+    import http.server as BaseHTTPServer
+    from urllib.request import urlopen
+ 
 import errno
 import logging
 import os
@@ -31,7 +37,6 @@
 import textwrap
 import threading
 import time
-import urllib2
 
 import zc.buildout.buildout
 import zc.buildout.easy_install
@@ -124,7 +129,7 @@
             ' '.join(arg for arg in (interpreter, flags, '-c', cmd) if arg))
 
 def get(url):
-    return urllib2.urlopen(url).read()
+    return urlopen(url).read()
 
 def _runsetup(setup, executable, *args):
     if os.path.isdir(setup):
@@ -512,7 +517,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()
@@ -527,7 +532,7 @@
 
 def stop_server(url, thread=None):
     try:
-        urllib2.urlopen(url+'__stop__')
+        urlopen(url+'__stop__')
     except Exception:
         pass
     if thread is not None:
@@ -543,7 +548,8 @@
             s.close()
             if up:
                 break
-        except socket.error, e:
+        except socket.error:
+            e = sys.exc_info()[1]
             if e[0] not in (errno.ECONNREFUSED, errno.ECONNRESET):
                 raise
             s.close()

Modified: zc.buildout/branches/regebro-python3/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/branches/regebro-python3/src/zc/buildout/tests.py	2010-07-24 10:11:46 UTC (rev 114984)
+++ zc.buildout/branches/regebro-python3/src/zc/buildout/tests.py	2010-07-24 10:45:21 UTC (rev 114985)
@@ -2805,11 +2805,14 @@
     >>> src = tmpdir('src')
     >>> write(src, 'wacky_handler.py',
     ... '''
-    ... import urllib2
-    ... class Wacky(urllib2.HTTPHandler):
-    ...     wacky_open = urllib2.HTTPHandler.http_open
+    ... try:
+    ...     from urllib2 import HTTPHandler, build_opener, install_opener
+    ... except ImportError:
+    ...     from urllib.request import HTTPHandler, build_opener, install_opener
+    ... class Wacky(HTTPHandler):
+    ...     wacky_open = HTTPHandler.http_open
     ... def install(buildout=None):
-    ...     urllib2.install_opener(urllib2.build_opener(Wacky))
+    ...     install_opener(build_opener(Wacky))
     ... ''')
     >>> write(src, 'setup.py',
     ... '''



More information about the checkins mailing list