Commits

Arc Riley committed 48c6997

Further work on Py3 support; try blocks for imports mainly

Comments (0)

Files changed (3)

distutils2/fancy_getopt.py

     return parser.getopt(args, object)
 
 
-
-WS_TRANS = string.maketrans(string.whitespace, ' ' * len(string.whitespace))
+if 'maketrans' in str.__dict__ :
+    # Python 3.2+
+    WS_TRANS = str.maketrans(string.whitespace, ' ' * len(string.whitespace))
+else :
+    # Depreciated syntax
+    WS_TRANS = string.maketrans(string.whitespace, ' ' * len(string.whitespace))
 
 
 def wrap_text(text, width):

distutils2/tests/pypi_server.py

 implementations (static HTTP and XMLRPC over HTTP).
 """
 
-import Queue
-import SocketServer
 import os.path
 import select
 import socket
 import threading
 
-from BaseHTTPServer import HTTPServer
-from SimpleHTTPServer import SimpleHTTPRequestHandler
-from SimpleXMLRPCServer import SimpleXMLRPCServer
+# several packages had different names in Python 2.x
+try:
+    import queue
+    import socketserver
+    from http.server import HTTPServer, SimpleHTTPRequestHandler
+    from xmlrpc.server import SimpleXMLRPCServer
+except ImportError:
+    import Queue as queue
+    import SocketServer as socketserver
+    from BaseHTTPServer import HTTPServer    
+    from SimpleHTTPServer import SimpleHTTPRequestHandler
+    from SimpleXMLRPCServer import SimpleXMLRPCServer
 
 from distutils2.tests import unittest
 
             self.server = HTTPServer(('127.0.0.1', 0), PyPIRequestHandler)
             self.server.RequestHandlerClass.pypi_server = self
 
-            self.request_queue = Queue.Queue()
+            self.request_queue = queue.Queue()
             self._requests = []
             self.default_response_status = 200
             self.default_response_headers = [('Content-type', 'text/plain')]
         while True:
             try:
                 self._requests.append(self.request_queue.get_nowait())
-            except Queue.Empty:
+            except queue.Empty:
                 break
         return self._requests
 
 class PyPIXMLRPCServer(SimpleXMLRPCServer):
     def server_bind(self):
         """Override server_bind to store the server name."""
-        SocketServer.TCPServer.server_bind(self)
+        socketserver.TCPServer.server_bind(self)
         host, port = self.socket.getsockname()[:2]
         self.server_name = socket.getfqdn(host)
         self.server_port = port
 # Python 3.x hook to run 2to3 automatically
 try:
     from distutils.command.build_py import build_py_2to3 as build_py
+    from distutils.core import setup, Extension
 except ImportError:
     # 2.x, try to use setuptools if available
     try :
+        from setuptools.command.build_py import build_py
         from setuptools import setup, Extension
-        from setuptools.command.build_py import build_py
     except ImportError:
+        from distutils.command.build_py import build_py
         from distutils.core import setup, Extension
-        from distutils.command.build_py import build_py
 
 
 f = open('README.txt')
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.