changeset 81:ed98ce70981e

Initial pass through 2to3.
author Allan Saddi <allan@saddi.com>
date Thu, 04 Dec 2008 09:55:21 -0800
parents 68112f6a2bb9
children 189e7ca3fbe2
files flup/client/fcgi_app.py flup/client/scgi_app.py flup/server/ajp.py flup/server/ajp_base.py flup/server/ajp_fork.py flup/server/cgi.py flup/server/fcgi.py flup/server/fcgi_base.py flup/server/fcgi_fork.py flup/server/preforkserver.py flup/server/scgi.py flup/server/scgi_base.py flup/server/scgi_fork.py flup/server/threadedserver.py flup/server/threadpool.py
diffstat 15 files changed, 155 insertions(+), 157 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/flup/client/fcgi_app.py	Wed Dec 03 10:43:53 2008 -0800
     1.2 +++ b/flup/client/fcgi_app.py	Thu Dec 04 09:55:21 2008 -0800
     1.3 @@ -136,13 +136,13 @@
     1.4      if nameLength < 128:
     1.5          s = chr(nameLength)
     1.6      else:
     1.7 -        s = struct.pack('!L', nameLength | 0x80000000L)
     1.8 +        s = struct.pack('!L', nameLength | 0x80000000)
     1.9  
    1.10      valueLength = len(value)
    1.11      if valueLength < 128:
    1.12          s += chr(valueLength)
    1.13      else:
    1.14 -        s += struct.pack('!L', valueLength | 0x80000000L)
    1.15 +        s += struct.pack('!L', valueLength | 0x80000000)
    1.16  
    1.17      return s + name + value
    1.18  
    1.19 @@ -170,7 +170,7 @@
    1.20          while length:
    1.21              try:
    1.22                  data = sock.recv(length)
    1.23 -            except socket.error, e:
    1.24 +            except socket.error as e:
    1.25                  if e[0] == errno.EAGAIN:
    1.26                      select.select([sock], [], [])
    1.27                      continue
    1.28 @@ -227,7 +227,7 @@
    1.29          while length:
    1.30              try:
    1.31                  sent = sock.send(data)
    1.32 -            except socket.error, e:
    1.33 +            except socket.error as e:
    1.34                  if e[0] == errno.EAGAIN:
    1.35                      select.select([], [sock], [])
    1.36                      continue
    1.37 @@ -394,7 +394,7 @@
    1.38              return sock
    1.39  
    1.40          # To be done when I have more time...
    1.41 -        raise NotImplementedError, 'Launching and managing FastCGI programs not yet implemented'
    1.42 +        raise NotImplementedError('Launching and managing FastCGI programs not yet implemented')
    1.43      
    1.44      def _fcgiGetValues(self, sock, vars):
    1.45          # Construct FCGI_GET_VALUES record
    1.46 @@ -421,7 +421,7 @@
    1.47      def _fcgiParams(self, sock, requestId, params):
    1.48          rec = Record(FCGI_PARAMS, requestId)
    1.49          data = []
    1.50 -        for name,value in params.items():
    1.51 +        for name,value in list(params.items()):
    1.52              data.append(encode_pair(name, value))
    1.53          data = ''.join(data)
    1.54          rec.contentData = data
    1.55 @@ -435,7 +435,7 @@
    1.56  
    1.57      def _defaultFilterEnviron(self, environ):
    1.58          result = {}
    1.59 -        for n in environ.keys():
    1.60 +        for n in list(environ.keys()):
    1.61              for p in self._environPrefixes:
    1.62                  if n.startswith(p):
    1.63                      result[n] = environ[n]
    1.64 @@ -448,7 +448,7 @@
    1.65  
    1.66      def _lightFilterEnviron(self, environ):
    1.67          result = {}
    1.68 -        for n in environ.keys():
    1.69 +        for n in list(environ.keys()):
    1.70              if n.upper() == n:
    1.71                  result[n] = environ[n]
    1.72          return result
     2.1 --- a/flup/client/scgi_app.py	Wed Dec 03 10:43:53 2008 -0800
     2.2 +++ b/flup/client/scgi_app.py	Thu Dec 04 09:55:21 2008 -0800
     2.3 @@ -65,11 +65,11 @@
     2.4          # TODO: Anything not from environ that needs to be sent also?
     2.5  
     2.6          content_length = int(environ.get('CONTENT_LENGTH') or 0)
     2.7 -        if headers.has_key('CONTENT_LENGTH'):
     2.8 +        if 'CONTENT_LENGTH' in headers:
     2.9              del headers['CONTENT_LENGTH']
    2.10              
    2.11          headers_out = ['CONTENT_LENGTH', str(content_length), 'SCGI', '1']
    2.12 -        for k,v in headers.items():
    2.13 +        for k,v in list(headers.items()):
    2.14              headers_out.append(k)
    2.15              headers_out.append(v)
    2.16          headers_out.append('') # For trailing NUL
    2.17 @@ -150,7 +150,7 @@
    2.18  
    2.19      def _defaultFilterEnviron(self, environ):
    2.20          result = {}
    2.21 -        for n in environ.keys():
    2.22 +        for n in list(environ.keys()):
    2.23              for p in self._environPrefixes:
    2.24                  if n.startswith(p):
    2.25                      result[n] = environ[n]
    2.26 @@ -163,7 +163,7 @@
    2.27  
    2.28      def _lightFilterEnviron(self, environ):
    2.29          result = {}
    2.30 -        for n in environ.keys():
    2.31 +        for n in list(environ.keys()):
    2.32              if n.upper() == n:
    2.33                  result[n] = environ[n]
    2.34          return result
     3.1 --- a/flup/server/ajp.py	Wed Dec 03 10:43:53 2008 -0800
     3.2 +++ b/flup/server/ajp.py	Thu Dec 04 09:55:21 2008 -0800
     3.3 @@ -82,8 +82,8 @@
     3.4  import socket
     3.5  import logging
     3.6  
     3.7 -from flup.server.ajp_base import BaseAJPServer, Connection
     3.8 -from flup.server.threadedserver import ThreadedServer
     3.9 +from .ajp_base import BaseAJPServer, Connection
    3.10 +from .threadedserver import ThreadedServer
    3.11  
    3.12  __all__ = ['WSGIServer']
    3.13  
    3.14 @@ -134,7 +134,7 @@
    3.15                                 loggingLevel=loggingLevel,
    3.16                                 debug=debug)
    3.17          for key in ('jobClass', 'jobArgs'):
    3.18 -            if kw.has_key(key):
    3.19 +            if key in kw:
    3.20                  del kw[key]
    3.21          ThreadedServer.__init__(self, jobClass=Connection, jobArgs=(self,),
    3.22                                  **kw)
    3.23 @@ -149,7 +149,7 @@
    3.24  
    3.25          try:
    3.26              sock = self._setupSocket()
    3.27 -        except socket.error, e:
    3.28 +        except socket.error as e:
    3.29              self.logger.error('Failed to bind socket (%s), exiting', e[1])
    3.30              return False
    3.31  
    3.32 @@ -163,7 +163,7 @@
    3.33          return ret
    3.34  
    3.35  def factory(global_conf, host=None, port=None, **local):
    3.36 -    import paste_factory
    3.37 +    from . import paste_factory
    3.38      return paste_factory.helper(WSGIServer, global_conf, host, port, **local)
    3.39  
    3.40  if __name__ == '__main__':
    3.41 @@ -175,11 +175,11 @@
    3.42                '<body>\n' \
    3.43                '<p>Hello World!</p>\n' \
    3.44                '<table border="1">'
    3.45 -        names = environ.keys()
    3.46 +        names = list(environ.keys())
    3.47          names.sort()
    3.48          for name in names:
    3.49              yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
    3.50 -                name, cgi.escape(`environ[name]`))
    3.51 +                name, cgi.escape(repr(environ[name])))
    3.52  
    3.53          form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
    3.54                                  keep_blank_values=1)
     4.1 --- a/flup/server/ajp_base.py	Wed Dec 03 10:43:53 2008 -0800
     4.2 +++ b/flup/server/ajp_base.py	Thu Dec 04 09:55:21 2008 -0800
     4.3 @@ -38,7 +38,7 @@
     4.4  import time
     4.5  
     4.6  # Unfortunately, for now, threads are required.
     4.7 -import thread
     4.8 +import _thread
     4.9  import threading
    4.10  
    4.11  __all__ = ['BaseAJPServer']
    4.12 @@ -170,8 +170,8 @@
    4.13              return '', pos
    4.14          s = data[pos:pos+length]
    4.15          return s, pos+length+1 # Don't forget NUL
    4.16 -    except Exception, e:
    4.17 -        raise ProtocolError, 'decodeString: '+str(e)
    4.18 +    except Exception as e:
    4.19 +        raise ProtocolError('decodeString: '+str(e))
    4.20  
    4.21  def decodeRequestHeader(data, pos=0):
    4.22      """Decode a request header/value pair."""
    4.23 @@ -181,14 +181,14 @@
    4.24              i = ord(data[pos+1])
    4.25              name = requestHeaderTable[i]
    4.26              if name is None:
    4.27 -                raise ValueError, 'bad request header code'
    4.28 +                raise ValueError('bad request header code')
    4.29              pos += 2
    4.30          else:
    4.31              name, pos = decodeString(data, pos)
    4.32          value, pos = decodeString(data, pos)
    4.33          return name, value, pos
    4.34 -    except Exception, e:
    4.35 -        raise ProtocolError, 'decodeRequestHeader: '+str(e)
    4.36 +    except Exception as e:
    4.37 +        raise ProtocolError('decodeRequestHeader: '+str(e))
    4.38  
    4.39  def decodeAttribute(data, pos=0):
    4.40      """Decode a request attribute."""
    4.41 @@ -210,11 +210,11 @@
    4.42          else:
    4.43              name = attributeTable[i]
    4.44              if name is None:
    4.45 -                raise ValueError, 'bad attribute code'
    4.46 +                raise ValueError('bad attribute code')
    4.47          value, pos = decodeString(data, pos)
    4.48          return name, value, pos
    4.49 -    except Exception, e:
    4.50 -        raise ProtocolError, 'decodeAttribute: '+str(e)
    4.51 +    except Exception as e:
    4.52 +        raise ProtocolError('decodeAttribute: '+str(e))
    4.53  
    4.54  def encodeString(s):
    4.55      """Encode a string."""
    4.56 @@ -249,7 +249,7 @@
    4.57          while length:
    4.58              try:
    4.59                  data = sock.recv(length)
    4.60 -            except socket.error, e:
    4.61 +            except socket.error as e:
    4.62                  if e[0] == errno.EAGAIN:
    4.63                      select.select([sock], [], [])
    4.64                      continue
    4.65 @@ -276,7 +276,7 @@
    4.66              raise EOFError
    4.67  
    4.68          if header[:2] != SERVER_PREFIX:
    4.69 -            raise ProtocolError, 'invalid header'
    4.70 +            raise ProtocolError('invalid header')
    4.71  
    4.72          self.length = struct.unpack('>H', header[2:4])[0]
    4.73          if self.length:
    4.74 @@ -296,7 +296,7 @@
    4.75          while length:
    4.76              try:
    4.77                  sent = sock.send(data)
    4.78 -            except socket.error, e:
    4.79 +            except socket.error as e:
    4.80                  if e[0] == errno.EAGAIN:
    4.81                      select.select([], [sock], [])
    4.82                      continue
    4.83 @@ -427,7 +427,7 @@
    4.84      def __iter__(self):
    4.85          return self
    4.86  
    4.87 -    def next(self):
    4.88 +    def __next__(self):
    4.89          r = self.readline()
    4.90          if not r:
    4.91              raise StopIteration
    4.92 @@ -446,12 +446,12 @@
    4.93          never send us an EOF (empty string argument).
    4.94          """
    4.95          if not data:
    4.96 -            raise ProtocolError, 'short data'
    4.97 +            raise ProtocolError('short data')
    4.98          self._bufList.append(data)
    4.99          length = len(data)
   4.100          self._avail += length
   4.101          if self._avail > self._length:
   4.102 -            raise ProtocolError, 'too much data'
   4.103 +            raise ProtocolError('too much data')
   4.104  
   4.105  class Request(object):
   4.106      """
   4.107 @@ -616,7 +616,7 @@
   4.108          while True:
   4.109              try:
   4.110                  self.processInput()
   4.111 -            except ProtocolError, e:
   4.112 +            except ProtocolError as e:
   4.113                  self.logger.error("Protocol error '%s'", str(e))
   4.114                  break
   4.115              except (EOFError, KeyboardInterrupt):
   4.116 @@ -642,7 +642,7 @@
   4.117              return
   4.118  
   4.119          if not pkt.length:
   4.120 -            raise ProtocolError, 'unexpected empty packet'
   4.121 +            raise ProtocolError('unexpected empty packet')
   4.122  
   4.123          pkttype = pkt.data[0]
   4.124          if pkttype == PKTTYPE_FWD_REQ:
   4.125 @@ -654,7 +654,7 @@
   4.126          elif pkttype == PKTTYPE_CPING:
   4.127              self._cping(pkt)
   4.128          else:
   4.129 -            raise ProtocolError, 'unknown packet type'
   4.130 +            raise ProtocolError('unknown packet type')
   4.131  
   4.132      def _forwardRequest(self, pkt):
   4.133          """
   4.134 @@ -666,7 +666,7 @@
   4.135          i = ord(pkt.data[1])
   4.136          method = methodTable[i]
   4.137          if method is None:
   4.138 -            raise ValueError, 'bad method field'
   4.139 +            raise ValueError('bad method field')
   4.140          req.setMethod(method)
   4.141          value, pos = decodeString(pkt.data, 2)
   4.142          req.setProtocol(value)
   4.143 @@ -794,7 +794,7 @@
   4.144          self._allowedServers = allowedServers
   4.145  
   4.146          # Used to force single-threadedness.
   4.147 -        self._appLock = thread.allocate_lock()
   4.148 +        self._appLock = _thread.allocate_lock()
   4.149  
   4.150          self.logger = logging.getLogger(LoggerName)
   4.151          self.logger.setLevel(loggingLevel)
   4.152 @@ -873,7 +873,7 @@
   4.153                  try:
   4.154                      if headers_sent:
   4.155                          # Re-raise if too late
   4.156 -                        raise exc_info[0], exc_info[1], exc_info[2]
   4.157 +                        raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
   4.158                  finally:
   4.159                      exc_info = None # avoid dangling circular ref
   4.160              else:
   4.161 @@ -906,7 +906,7 @@
   4.162                  finally:
   4.163                      if hasattr(result, 'close'):
   4.164                          result.close()
   4.165 -            except socket.error, e:
   4.166 +            except socket.error as e:
   4.167                  if e[0] != errno.EPIPE:
   4.168                      raise # Don't let EPIPE propagate beyond server
   4.169          finally:
   4.170 @@ -925,10 +925,10 @@
   4.171          environ['SCRIPT_NAME'] = scriptName
   4.172  
   4.173          reqUri = None
   4.174 -        if environ.has_key('REQUEST_URI'):
   4.175 +        if 'REQUEST_URI' in environ:
   4.176              reqUri = environ['REQUEST_URI'].split('?', 1)
   4.177  
   4.178 -        if not environ.has_key('QUERY_STRING') or not environ['QUERY_STRING']:
   4.179 +        if 'QUERY_STRING' not in environ or not environ['QUERY_STRING']:
   4.180              if reqUri is not None and len(reqUri) > 1:
   4.181                  environ['QUERY_STRING'] = reqUri[1]
   4.182              else:
     5.1 --- a/flup/server/ajp_fork.py	Wed Dec 03 10:43:53 2008 -0800
     5.2 +++ b/flup/server/ajp_fork.py	Thu Dec 04 09:55:21 2008 -0800
     5.3 @@ -82,8 +82,8 @@
     5.4  import socket
     5.5  import logging
     5.6  
     5.7 -from flup.server.ajp_base import BaseAJPServer, Connection
     5.8 -from flup.server.preforkserver import PreforkServer
     5.9 +from .ajp_base import BaseAJPServer, Connection
    5.10 +from .preforkserver import PreforkServer
    5.11  
    5.12  __all__ = ['WSGIServer']
    5.13  
    5.14 @@ -133,7 +133,7 @@
    5.15                                 loggingLevel=loggingLevel,
    5.16                                 debug=debug)
    5.17          for key in ('multithreaded', 'multiprocess', 'jobClass', 'jobArgs'):
    5.18 -            if kw.has_key(key):
    5.19 +            if key in kw:
    5.20                  del kw[key]
    5.21          PreforkServer.__init__(self, jobClass=Connection, jobArgs=(self,), **kw)
    5.22  
    5.23 @@ -147,7 +147,7 @@
    5.24  
    5.25          try:
    5.26              sock = self._setupSocket()
    5.27 -        except socket.error, e:
    5.28 +        except socket.error as e:
    5.29              self.logger.error('Failed to bind socket (%s), exiting', e[1])
    5.30              return False
    5.31  
    5.32 @@ -161,23 +161,23 @@
    5.33          return ret
    5.34  
    5.35  def factory(global_conf, host=None, port=None, **local):
    5.36 -    import paste_factory
    5.37 +    from . import paste_factory
    5.38      return paste_factory.helper(WSGIServer, global_conf, host, port, **local)
    5.39  
    5.40  if __name__ == '__main__':
    5.41      def test_app(environ, start_response):
    5.42          """Probably not the most efficient example."""
    5.43 -        import cgi
    5.44 +        from . import cgi
    5.45          start_response('200 OK', [('Content-Type', 'text/html')])
    5.46          yield '<html><head><title>Hello World!</title></head>\n' \
    5.47                '<body>\n' \
    5.48                '<p>Hello World!</p>\n' \
    5.49                '<table border="1">'
    5.50 -        names = environ.keys()
    5.51 +        names = list(environ.keys())
    5.52          names.sort()
    5.53          for name in names:
    5.54              yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
    5.55 -                name, cgi.escape(`environ[name]`))
    5.56 +                name, cgi.escape(repr(environ[name])))
    5.57  
    5.58          form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
    5.59                                  keep_blank_values=1)
     6.1 --- a/flup/server/cgi.py	Wed Dec 03 10:43:53 2008 -0800
     6.2 +++ b/flup/server/cgi.py	Thu Dec 04 09:55:21 2008 -0800
     6.3 @@ -14,7 +14,7 @@
     6.4  
     6.5      def run(self):
     6.6  
     6.7 -        environ = dict(os.environ.items())
     6.8 +        environ = dict(list(os.environ.items()))
     6.9          environ['wsgi.input']        = sys.stdin
    6.10          environ['wsgi.errors']       = sys.stderr
    6.11          environ['wsgi.version']      = (1,0)
    6.12 @@ -50,7 +50,7 @@
    6.13                  try:
    6.14                      if headers_sent:
    6.15                          # Re-raise original exception if headers sent
    6.16 -                        raise exc_info[0], exc_info[1], exc_info[2]
    6.17 +                        raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
    6.18                  finally:
    6.19                      exc_info = None     # avoid dangling circular ref
    6.20              elif headers_set:
     7.1 --- a/flup/server/fcgi.py	Wed Dec 03 10:43:53 2008 -0800
     7.2 +++ b/flup/server/fcgi.py	Thu Dec 04 09:55:21 2008 -0800
     7.3 @@ -51,8 +51,8 @@
     7.4  
     7.5  import os
     7.6  
     7.7 -from flup.server.fcgi_base import BaseFCGIServer, FCGI_RESPONDER
     7.8 -from flup.server.threadedserver import ThreadedServer
     7.9 +from .fcgi_base import BaseFCGIServer, FCGI_RESPONDER
    7.10 +from .threadedserver import ThreadedServer
    7.11  
    7.12  __all__ = ['WSGIServer']
    7.13  
    7.14 @@ -89,7 +89,7 @@
    7.15                                  debug=debug,
    7.16                                  roles=roles)
    7.17          for key in ('jobClass', 'jobArgs'):
    7.18 -            if kw.has_key(key):
    7.19 +            if key in kw:
    7.20                  del kw[key]
    7.21          ThreadedServer.__init__(self, jobClass=self._connectionClass,
    7.22                                  jobArgs=(self,), **kw)
    7.23 @@ -105,8 +105,7 @@
    7.24          """
    7.25          self._web_server_addrs = os.environ.get('FCGI_WEB_SERVER_ADDRS')
    7.26          if self._web_server_addrs is not None:
    7.27 -            self._web_server_addrs = map(lambda x: x.strip(),
    7.28 -                                         self._web_server_addrs.split(','))
    7.29 +            self._web_server_addrs = [x.strip() for x in self._web_server_addrs.split(',')]
    7.30  
    7.31          sock = self._setupSocket()
    7.32  
    7.33 @@ -117,7 +116,7 @@
    7.34          return ret
    7.35  
    7.36  def factory(global_conf, host=None, port=None, **local):
    7.37 -    import paste_factory
    7.38 +    from . import paste_factory
    7.39      return paste_factory.helper(WSGIServer, global_conf, host, port, **local)
    7.40  
    7.41  if __name__ == '__main__':
    7.42 @@ -129,11 +128,11 @@
    7.43                '<body>\n' \
    7.44                '<p>Hello World!</p>\n' \
    7.45                '<table border="1">'
    7.46 -        names = environ.keys()
    7.47 +        names = list(environ.keys())
    7.48          names.sort()
    7.49          for name in names:
    7.50              yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
    7.51 -                name, cgi.escape(`environ[name]`))
    7.52 +                name, cgi.escape(repr(environ[name])))
    7.53  
    7.54          form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
    7.55                                  keep_blank_values=1)
     8.1 --- a/flup/server/fcgi_base.py	Wed Dec 03 10:43:53 2008 -0800
     8.2 +++ b/flup/server/fcgi_base.py	Thu Dec 04 09:55:21 2008 -0800
     8.3 @@ -31,18 +31,18 @@
     8.4  import os
     8.5  import signal
     8.6  import struct
     8.7 -import cStringIO as StringIO
     8.8 +import io as StringIO
     8.9  import select
    8.10  import socket
    8.11  import errno
    8.12  import traceback
    8.13  
    8.14  try:
    8.15 -    import thread
    8.16 +    import _thread
    8.17      import threading
    8.18      thread_available = True
    8.19  except ImportError:
    8.20 -    import dummy_thread as thread
    8.21 +    import _dummy_thread as thread
    8.22      import dummy_threading as threading
    8.23      thread_available = False
    8.24  
    8.25 @@ -218,7 +218,7 @@
    8.26      def __iter__(self):
    8.27          return self
    8.28  
    8.29 -    def next(self):
    8.30 +    def __next__(self):
    8.31          r = self.readline()
    8.32          if not r:
    8.33              raise StopIteration
    8.34 @@ -414,13 +414,13 @@
    8.35      if nameLength < 128:
    8.36          s = chr(nameLength)
    8.37      else:
    8.38 -        s = struct.pack('!L', nameLength | 0x80000000L)
    8.39 +        s = struct.pack('!L', nameLength | 0x80000000)
    8.40  
    8.41      valueLength = len(value)
    8.42      if valueLength < 128:
    8.43          s += chr(valueLength)
    8.44      else:
    8.45 -        s += struct.pack('!L', valueLength | 0x80000000L)
    8.46 +        s += struct.pack('!L', valueLength | 0x80000000)
    8.47  
    8.48      return s + name + value
    8.49      
    8.50 @@ -448,7 +448,7 @@
    8.51          while length:
    8.52              try:
    8.53                  data = sock.recv(length)
    8.54 -            except socket.error, e:
    8.55 +            except socket.error as e:
    8.56                  if e[0] == errno.EAGAIN:
    8.57                      select.select([sock], [], [])
    8.58                      continue
    8.59 @@ -505,7 +505,7 @@
    8.60          while length:
    8.61              try:
    8.62                  sent = sock.send(data)
    8.63 -            except socket.error, e:
    8.64 +            except socket.error as e:
    8.65                  if e[0] == errno.EAGAIN:
    8.66                      select.select([], [sock], [])
    8.67                      continue
    8.68 @@ -570,11 +570,11 @@
    8.69          try:
    8.70              self._flush()
    8.71              self._end(appStatus, protocolStatus)
    8.72 -        except socket.error, e:
    8.73 +        except socket.error as e:
    8.74              if e[0] != errno.EPIPE:
    8.75                  raise
    8.76  
    8.77 -    def _end(self, appStatus=0L, protocolStatus=FCGI_REQUEST_COMPLETE):
    8.78 +    def _end(self, appStatus=0, protocolStatus=FCGI_REQUEST_COMPLETE):
    8.79          self._conn.end_request(self, appStatus, protocolStatus)
    8.80          
    8.81      def _flush(self):
    8.82 @@ -597,7 +597,7 @@
    8.83          self.stderr = sys.stderr
    8.84          self.data = StringIO.StringIO()
    8.85          
    8.86 -    def _end(self, appStatus=0L, protocolStatus=FCGI_REQUEST_COMPLETE):
    8.87 +    def _end(self, appStatus=0, protocolStatus=FCGI_REQUEST_COMPLETE):
    8.88          sys.exit(appStatus)
    8.89  
    8.90      def _flush(self):
    8.91 @@ -646,7 +646,7 @@
    8.92                  self.process_input()
    8.93              except (EOFError, KeyboardInterrupt):
    8.94                  break
    8.95 -            except (select.error, socket.error), e:
    8.96 +            except (select.error, socket.error) as e:
    8.97                  if e[0] == errno.EBADF: # Socket was closed by Request.
    8.98                      break
    8.99                  raise
   8.100 @@ -696,7 +696,7 @@
   8.101          """
   8.102          rec.write(self._sock)
   8.103  
   8.104 -    def end_request(self, req, appStatus=0L,
   8.105 +    def end_request(self, req, appStatus=0,
   8.106                      protocolStatus=FCGI_REQUEST_COMPLETE, remove=True):
   8.107          """
   8.108          End a Request.
   8.109 @@ -745,7 +745,7 @@
   8.110  
   8.111          if not self._multiplexed and self._requests:
   8.112              # Can't multiplex requests.
   8.113 -            self.end_request(req, 0L, FCGI_CANT_MPX_CONN, remove=False)
   8.114 +            self.end_request(req, 0, FCGI_CANT_MPX_CONN, remove=False)
   8.115          else:
   8.116              self._requests[inrec.requestId] = req
   8.117  
   8.118 @@ -836,7 +836,7 @@
   8.119          finally:
   8.120              self._lock.release()
   8.121  
   8.122 -    def end_request(self, req, appStatus=0L,
   8.123 +    def end_request(self, req, appStatus=0,
   8.124                      protocolStatus=FCGI_REQUEST_COMPLETE, remove=True):
   8.125          self._lock.acquire()
   8.126          try:
   8.127 @@ -862,7 +862,7 @@
   8.128              self._lock.release()
   8.129  
   8.130      def _start_request(self, req):
   8.131 -        thread.start_new_thread(req.run, ())
   8.132 +        _thread.start_new_thread(req.run, ())
   8.133  
   8.134      def _do_params(self, inrec):
   8.135          self._lock.acquire()
   8.136 @@ -939,7 +939,7 @@
   8.137          self._umask = umask
   8.138          
   8.139          # Used to force single-threadedness
   8.140 -        self._appLock = thread.allocate_lock()
   8.141 +        self._appLock = _thread.allocate_lock()
   8.142  
   8.143          if thread_available:
   8.144              try:
   8.145 @@ -977,7 +977,7 @@
   8.146                                   socket.SOCK_STREAM)
   8.147              try:
   8.148                  sock.getpeername()
   8.149 -            except socket.error, e:
   8.150 +            except socket.error as e:
   8.151                  if e[0] == errno.ENOTSOCK:
   8.152                      # Not a socket, assume CGI context.
   8.153                      isFCGI = False
   8.154 @@ -1090,7 +1090,7 @@
   8.155                  try:
   8.156                      if headers_sent:
   8.157                          # Re-raise if too late
   8.158 -                        raise exc_info[0], exc_info[1], exc_info[2]
   8.159 +                        raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
   8.160                  finally:
   8.161                      exc_info = None # avoid dangling circular ref
   8.162              else:
   8.163 @@ -1123,7 +1123,7 @@
   8.164                  finally:
   8.165                      if hasattr(result, 'close'):
   8.166                          result.close()
   8.167 -            except socket.error, e:
   8.168 +            except socket.error as e:
   8.169                  if e[0] != errno.EPIPE:
   8.170                      raise # Don't let EPIPE propagate beyond server
   8.171          finally:
   8.172 @@ -1134,19 +1134,19 @@
   8.173  
   8.174      def _sanitizeEnv(self, environ):
   8.175          """Ensure certain values are present, if required by WSGI."""
   8.176 -        if not environ.has_key('SCRIPT_NAME'):
   8.177 +        if 'SCRIPT_NAME' not in environ:
   8.178              environ['SCRIPT_NAME'] = ''
   8.179  
   8.180          reqUri = None
   8.181 -        if environ.has_key('REQUEST_URI'):
   8.182 +        if 'REQUEST_URI' in environ:
   8.183              reqUri = environ['REQUEST_URI'].split('?', 1)
   8.184  
   8.185 -        if not environ.has_key('PATH_INFO') or not environ['PATH_INFO']:
   8.186 +        if 'PATH_INFO' not in environ or not environ['PATH_INFO']:
   8.187              if reqUri is not None:
   8.188                  environ['PATH_INFO'] = reqUri[0]
   8.189              else:
   8.190                  environ['PATH_INFO'] = ''
   8.191 -        if not environ.has_key('QUERY_STRING') or not environ['QUERY_STRING']:
   8.192 +        if 'QUERY_STRING' not in environ or not environ['QUERY_STRING']:
   8.193              if reqUri is not None and len(reqUri) > 1:
   8.194                  environ['QUERY_STRING'] = reqUri[1]
   8.195              else:
   8.196 @@ -1158,7 +1158,7 @@
   8.197                               ('SERVER_NAME', 'localhost'),
   8.198                               ('SERVER_PORT', '80'),
   8.199                               ('SERVER_PROTOCOL', 'HTTP/1.0')]:
   8.200 -            if not environ.has_key(name):
   8.201 +            if name not in environ:
   8.202                  environ['wsgi.errors'].write('%s: missing FastCGI param %s '
   8.203                                               'required by WSGI!\n' %
   8.204                                               (self.__class__.__name__, name))
     9.1 --- a/flup/server/fcgi_fork.py	Wed Dec 03 10:43:53 2008 -0800
     9.2 +++ b/flup/server/fcgi_fork.py	Thu Dec 04 09:55:21 2008 -0800
     9.3 @@ -51,9 +51,9 @@
     9.4  
     9.5  import os
     9.6  
     9.7 -from flup.server.fcgi_base import BaseFCGIServer, \
     9.8 +from .fcgi_base import BaseFCGIServer, \
     9.9       FCGI_MAX_CONNS, FCGI_MAX_REQS, FCGI_MPXS_CONNS
    9.10 -from flup.server.preforkserver import PreforkServer
    9.11 +from .preforkserver import PreforkServer
    9.12  
    9.13  __all__ = ['WSGIServer']
    9.14  
    9.15 @@ -88,7 +88,7 @@
    9.16                                  multiplexed=multiplexed,
    9.17                                  debug=debug)
    9.18          for key in ('multithreaded', 'multiprocess', 'jobClass', 'jobArgs'):
    9.19 -            if kw.has_key(key):
    9.20 +            if key in kw:
    9.21                  del kw[key]
    9.22          PreforkServer.__init__(self, jobClass=self._connectionClass,
    9.23                                 jobArgs=(self,), **kw)
    9.24 @@ -123,8 +123,7 @@
    9.25          """
    9.26          self._web_server_addrs = os.environ.get('FCGI_WEB_SERVER_ADDRS')
    9.27          if self._web_server_addrs is not None:
    9.28 -            self._web_server_addrs = map(lambda x: x.strip(),
    9.29 -                                         self._web_server_addrs.split(','))
    9.30 +            self._web_server_addrs = [x.strip() for x in self._web_server_addrs.split(',')]
    9.31  
    9.32          sock = self._setupSocket()
    9.33  
    9.34 @@ -135,23 +134,23 @@
    9.35          return ret
    9.36  
    9.37  def factory(global_conf, host=None, port=None, **local):
    9.38 -    import paste_factory
    9.39 +    from . import paste_factory
    9.40      return paste_factory.helper(WSGIServer, global_conf, host, port, **local)
    9.41  
    9.42  if __name__ == '__main__':
    9.43      def test_app(environ, start_response):
    9.44          """Probably not the most efficient example."""
    9.45 -        import cgi
    9.46 +        from . import cgi
    9.47          start_response('200 OK', [('Content-Type', 'text/html')])
    9.48          yield '<html><head><title>Hello World!</title></head>\n' \
    9.49                '<body>\n' \
    9.50                '<p>Hello World!</p>\n' \
    9.51                '<table border="1">'
    9.52 -        names = environ.keys()
    9.53 +        names = list(environ.keys())
    9.54          names.sort()
    9.55          for name in names:
    9.56              yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
    9.57 -                name, cgi.escape(`environ[name]`))
    9.58 +                name, cgi.escape(repr(environ[name])))
    9.59  
    9.60          form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
    9.61                                  keep_blank_values=1)
    10.1 --- a/flup/server/preforkserver.py	Wed Dec 03 10:43:53 2008 -0800
    10.2 +++ b/flup/server/preforkserver.py	Thu Dec 04 09:55:21 2008 -0800
    10.3 @@ -52,7 +52,7 @@
    10.4          import eunuchs.socketpair
    10.5      except ImportError:
    10.6          # TODO: Other alternatives? Perhaps using os.pipe()?
    10.7 -        raise ImportError, 'Requires eunuchs module for Python < 2.4'
    10.8 +        raise ImportError('Requires eunuchs module for Python < 2.4')
    10.9  
   10.10      def socketpair():
   10.11          s1, s2 = eunuchs.socketpair.socketpair()
   10.12 @@ -123,7 +123,7 @@
   10.13                  if not self._spawnChild(sock): break
   10.14  
   10.15              # Wait on any socket activity from live children.
   10.16 -            r = [x['file'] for x in self._children.values()
   10.17 +            r = [x['file'] for x in list(self._children.values())
   10.18                   if x['file'] is not None]
   10.19  
   10.20              if len(r) == len(self._children):
   10.21 @@ -135,7 +135,7 @@
   10.22  
   10.23              try:
   10.24                  r, w, e = select.select(r, [], [], timeout)
   10.25 -            except select.error, e:
   10.26 +            except select.error as e:
   10.27                  if e[0] != errno.EINTR:
   10.28                      raise
   10.29  
   10.30 @@ -144,13 +144,13 @@
   10.31                  # Receive status byte.
   10.32                  try:
   10.33                      state = child.recv(1)
   10.34 -                except socket.error, e:
   10.35 +                except socket.error as e:
   10.36                      if e[0] in (errno.EAGAIN, errno.EINTR):
   10.37                          # Guess it really didn't need attention?
   10.38                          continue
   10.39                      raise
   10.40                  # Try to match it with a child. (Do we need a reverse map?)
   10.41 -                for pid,d in self._children.items():
   10.42 +                for pid,d in list(self._children.items()):
   10.43                      if child is d['file']:
   10.44                          if state:
   10.45                              # Set availability status accordingly.
   10.46 @@ -167,7 +167,7 @@
   10.47              self._reapChildren()
   10.48  
   10.49              # See who and how many children are available.
   10.50 -            availList = filter(lambda x: x[1]['avail'], self._children.items())
   10.51 +            availList = [x for x in list(self._children.items()) if x[1]['avail']]
   10.52              avail = len(availList)
   10.53  
   10.54              if avail < self._minSpare:
   10.55 @@ -205,7 +205,7 @@
   10.56          Any children remaining after 10 seconds is SIGKILLed.
   10.57          """
   10.58          # Let all children know it's time to go.
   10.59 -        for pid,d in self._children.items():
   10.60 +        for pid,d in list(self._children.items()):
   10.61              if d['file'] is not None:
   10.62                  d['file'].close()
   10.63                  d['file'] = None
   10.64 @@ -213,7 +213,7 @@
   10.65                  # Child is unavailable. SIGINT it.
   10.66                  try:
   10.67                      os.kill(pid, signal.SIGINT)
   10.68 -                except OSError, e:
   10.69 +                except OSError as e:
   10.70                      if e[0] != errno.ESRCH:
   10.71                          raise
   10.72  
   10.73 @@ -229,19 +229,19 @@
   10.74          while len(self._children):
   10.75              try:
   10.76                  pid, status = os.wait()
   10.77 -            except OSError, e:
   10.78 +            except OSError as e:
   10.79                  if e[0] in (errno.ECHILD, errno.EINTR):
   10.80                      break
   10.81 -            if self._children.has_key(pid):
   10.82 +            if pid in self._children:
   10.83                  del self._children[pid]
   10.84  
   10.85          signal.signal(signal.SIGALRM, oldSIGALRM)
   10.86  
   10.87          # Forcefully kill any remaining children.
   10.88 -        for pid in self._children.keys():
   10.89 +        for pid in list(self._children.keys()):
   10.90              try:
   10.91                  os.kill(pid, signal.SIGKILL)
   10.92 -            except OSError, e:
   10.93 +            except OSError as e:
   10.94                  if e[0] != errno.ESRCH:
   10.95                      raise
   10.96  
   10.97 @@ -250,13 +250,13 @@
   10.98          while True:
   10.99              try:
  10.100                  pid, status = os.waitpid(-1, os.WNOHANG)
  10.101 -            except OSError, e:
  10.102 +            except OSError as e:
  10.103                  if e[0] == errno.ECHILD:
  10.104                      break
  10.105                  raise
  10.106              if pid <= 0:
  10.107                  break
  10.108 -            if self._children.has_key(pid): # Sanity check.
  10.109 +            if pid in self._children: # Sanity check.
  10.110                  if self._children[pid]['file'] is not None:
  10.111                      self._children[pid]['file'].close()
  10.112                  del self._children[pid]
  10.113 @@ -274,7 +274,7 @@
  10.114          setCloseOnExec(child)
  10.115          try:
  10.116              pid = os.fork()
  10.117 -        except OSError, e:
  10.118 +        except OSError as e:
  10.119              if e[0] in (errno.EAGAIN, errno.ENOMEM):
  10.120                  return False # Can't fork anymore.
  10.121              raise
  10.122 @@ -287,7 +287,7 @@
  10.123              # Restore signal handlers.
  10.124              self._restoreSignalHandlers()
  10.125              # Close copies of child sockets.
  10.126 -            for f in [x['file'] for x in self._children.values()
  10.127 +            for f in [x['file'] for x in list(self._children.values())
  10.128                        if x['file'] is not None]:
  10.129                  f.close()
  10.130              self._children = {}
  10.131 @@ -339,7 +339,7 @@
  10.132              # Otherwise, there's activity on the main socket...
  10.133              try:
  10.134                  clientSock, addr = sock.accept()
  10.135 -            except socket.error, e:
  10.136 +            except socket.error as e:
  10.137                  if e[0] == errno.EAGAIN:
  10.138                      # Or maybe not.
  10.139                      continue
  10.140 @@ -355,7 +355,7 @@
  10.141              # Notify parent we're no longer available.
  10.142              try:
  10.143                  parent.send('\x00')
  10.144 -            except socket.error, e:
  10.145 +            except socket.error as e:
  10.146                  # If parent is gone, finish up this request.
  10.147                  if e[0] != errno.EPIPE:
  10.148                      raise
  10.149 @@ -372,7 +372,7 @@
  10.150              # Tell parent we're free again.
  10.151              try:
  10.152                  parent.send('\xff')
  10.153 -            except socket.error, e:
  10.154 +            except socket.error as e:
  10.155                  if e[0] == errno.EPIPE:
  10.156                      # Parent is gone.
  10.157                      return
  10.158 @@ -415,12 +415,12 @@
  10.159              self._sock = sock
  10.160              self._addr = addr
  10.161          def run(self):
  10.162 -            print "Client connection opened from %s:%d" % self._addr
  10.163 +            print("Client connection opened from %s:%d" % self._addr)
  10.164              self._sock.send('Hello World!\n')
  10.165              self._sock.setblocking(1)
  10.166              self._sock.recv(1)
  10.167              self._sock.close()
  10.168 -            print "Client connection closed from %s:%d" % self._addr
  10.169 +            print("Client connection closed from %s:%d" % self._addr)
  10.170      sock = socket.socket()
  10.171      sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  10.172      sock.bind(('', 8080))
    11.1 --- a/flup/server/scgi.py	Wed Dec 03 10:43:53 2008 -0800
    11.2 +++ b/flup/server/scgi.py	Thu Dec 04 09:55:21 2008 -0800
    11.3 @@ -66,8 +66,8 @@
    11.4  import logging
    11.5  import socket
    11.6  
    11.7 -from flup.server.scgi_base import BaseSCGIServer, Connection, NoDefault
    11.8 -from flup.server.threadedserver import ThreadedServer
    11.9 +from .scgi_base import BaseSCGIServer, Connection, NoDefault
   11.10 +from .threadedserver import ThreadedServer
   11.11  
   11.12  __all__ = ['WSGIServer']
   11.13  
   11.14 @@ -129,7 +129,7 @@
   11.15                                  loggingLevel=loggingLevel,
   11.16                                  debug=debug)
   11.17          for key in ('jobClass', 'jobArgs'):
   11.18 -            if kw.has_key(key):
   11.19 +            if key in kw:
   11.20                  del kw[key]
   11.21          ThreadedServer.__init__(self, jobClass=Connection, jobArgs=(self,),
   11.22                                  **kw)
   11.23 @@ -144,7 +144,7 @@
   11.24  
   11.25          try:
   11.26              sock = self._setupSocket()
   11.27 -        except socket.error, e:
   11.28 +        except socket.error as e:
   11.29              self.logger.error('Failed to bind socket (%s), exiting', e[1])
   11.30              return False
   11.31  
   11.32 @@ -158,7 +158,7 @@
   11.33          return ret
   11.34  
   11.35  def factory(global_conf, host=None, port=None, **local):
   11.36 -    import paste_factory
   11.37 +    from . import paste_factory
   11.38      return paste_factory.helper(WSGIServer, global_conf, host, port, **local)
   11.39  
   11.40  if __name__ == '__main__':
   11.41 @@ -170,11 +170,11 @@
   11.42                '<body>\n' \
   11.43                '<p>Hello World!</p>\n' \
   11.44                '<table border="1">'
   11.45 -        names = environ.keys()
   11.46 +        names = list(environ.keys())
   11.47          names.sort()
   11.48          for name in names:
   11.49              yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
   11.50 -                name, cgi.escape(`environ[name]`))
   11.51 +                name, cgi.escape(repr(environ[name])))
   11.52  
   11.53          form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
   11.54                                  keep_blank_values=1)
    12.1 --- a/flup/server/scgi_base.py	Wed Dec 03 10:43:53 2008 -0800
    12.2 +++ b/flup/server/scgi_base.py	Thu Dec 04 09:55:21 2008 -0800
    12.3 @@ -32,7 +32,7 @@
    12.4  import socket
    12.5  import select
    12.6  import errno
    12.7 -import cStringIO as StringIO
    12.8 +import io as StringIO
    12.9  import signal
   12.10  import datetime
   12.11  import os
   12.12 @@ -40,7 +40,7 @@
   12.13  
   12.14  # Threads are required. If you want a non-threaded (forking) version, look at
   12.15  # SWAP <http://www.idyll.org/~t/www-tools/wsgi/>.
   12.16 -import thread
   12.17 +import _thread
   12.18  import threading
   12.19  
   12.20  __all__ = ['BaseSCGIServer']
   12.21 @@ -76,7 +76,7 @@
   12.22      while length:
   12.23          try:
   12.24              data = sock.recv(length)
   12.25 -        except socket.error, e:
   12.26 +        except socket.error as e:
   12.27              if e[0] == errno.EAGAIN:
   12.28                  select.select([sock], [], [])
   12.29                  continue
   12.30 @@ -99,7 +99,7 @@
   12.31      while True:
   12.32          try:
   12.33              c = sock.recv(1)
   12.34 -        except socket.error, e:
   12.35 +        except socket.error as e:
   12.36              if e[0] == errno.EAGAIN:
   12.37                  select.select([sock], [], [])
   12.38                  continue
   12.39 @@ -117,7 +117,7 @@
   12.40          if size < 0:
   12.41              raise ValueError
   12.42      except ValueError:
   12.43 -        raise ProtocolError, 'invalid netstring length'
   12.44 +        raise ProtocolError('invalid netstring length')
   12.45  
   12.46      # Now read the string.
   12.47      s, length = recvall(sock, size)
   12.48 @@ -132,7 +132,7 @@
   12.49          raise EOFError
   12.50  
   12.51      if trailer != ',':
   12.52 -        raise ProtocolError, 'invalid netstring trailer'
   12.53 +        raise ProtocolError('invalid netstring trailer')
   12.54  
   12.55      return s
   12.56  
   12.57 @@ -219,7 +219,7 @@
   12.58              self.processInput()
   12.59          except (EOFError, KeyboardInterrupt):
   12.60              pass
   12.61 -        except ProtocolError, e:
   12.62 +        except ProtocolError as e:
   12.63              self.logger.error("Protocol error '%s'", str(e))
   12.64          except:
   12.65              self.logger.exception('Exception caught in Connection')
   12.66 @@ -236,20 +236,20 @@
   12.67          headers = readNetstring(self._sock)
   12.68          headers = headers.split('\x00')[:-1]
   12.69          if len(headers) % 2 != 0:
   12.70 -            raise ProtocolError, 'invalid headers'
   12.71 +            raise ProtocolError('invalid headers')
   12.72          environ = {}
   12.73          for i in range(len(headers) / 2):
   12.74              environ[headers[2*i]] = headers[2*i+1]
   12.75  
   12.76          clen = environ.get('CONTENT_LENGTH')
   12.77          if clen is None:
   12.78 -            raise ProtocolError, 'missing CONTENT_LENGTH'
   12.79 +            raise ProtocolError('missing CONTENT_LENGTH')
   12.80          try:
   12.81              clen = int(clen)
   12.82              if clen < 0:
   12.83                  raise ValueError
   12.84          except ValueError:
   12.85 -            raise ProtocolError, 'invalid CONTENT_LENGTH'
   12.86 +            raise ProtocolError('invalid CONTENT_LENGTH')
   12.87  
   12.88          self._sock.setblocking(1)
   12.89          if clen:
   12.90 @@ -327,7 +327,7 @@
   12.91          self._allowedServers = allowedServers
   12.92  
   12.93          # Used to force single-threadedness.
   12.94 -        self._appLock = thread.allocate_lock()
   12.95 +        self._appLock = _thread.allocate_lock()
   12.96  
   12.97          self.logger = logging.getLogger(LoggerName)
   12.98          self.logger.setLevel(loggingLevel)
   12.99 @@ -430,7 +430,7 @@
  12.100                  try:
  12.101                      if headers_sent:
  12.102                          # Re-raise if too late
  12.103 -                        raise exc_info[0], exc_info[1], exc_info[2]
  12.104 +                        raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
  12.105                  finally:
  12.106                      exc_info = None # avoid dangling circular ref
  12.107              else:
  12.108 @@ -463,7 +463,7 @@
  12.109                  finally:
  12.110                      if hasattr(result, 'close'):
  12.111                          result.close()
  12.112 -            except socket.error, e:
  12.113 +            except socket.error as e:
  12.114                  if e[0] != errno.EPIPE:
  12.115                      raise # Don't let EPIPE propagate beyond server
  12.116          finally:
  12.117 @@ -473,11 +473,11 @@
  12.118      def _sanitizeEnv(self, environ):
  12.119          """Fill-in/deduce missing values in environ."""
  12.120          reqUri = None
  12.121 -        if environ.has_key('REQUEST_URI'):
  12.122 +        if 'REQUEST_URI' in environ:
  12.123              reqUri = environ['REQUEST_URI'].split('?', 1)
  12.124  
  12.125          # Ensure QUERY_STRING exists
  12.126 -        if not environ.has_key('QUERY_STRING') or not environ['QUERY_STRING']:
  12.127 +        if 'QUERY_STRING' not in environ or not environ['QUERY_STRING']:
  12.128              if reqUri is not None and len(reqUri) > 1:
  12.129                  environ['QUERY_STRING'] = reqUri[1]
  12.130              else:
  12.131 @@ -500,9 +500,9 @@
  12.132  
  12.133          if scriptName is NoDefault:
  12.134              # Pull SCRIPT_NAME/PATH_INFO from environment, with empty defaults
  12.135 -            if not environ.has_key('SCRIPT_NAME'):
  12.136 +            if 'SCRIPT_NAME' not in environ:
  12.137                  environ['SCRIPT_INFO'] = ''
  12.138 -            if not environ.has_key('PATH_INFO') or not environ['PATH_INFO']:
  12.139 +            if 'PATH_INFO' not in environ or not environ['PATH_INFO']:
  12.140                  if reqUri is not None:
  12.141                      environ['PATH_INFO'] = reqUri[0]
  12.142                  else:
    13.1 --- a/flup/server/scgi_fork.py	Wed Dec 03 10:43:53 2008 -0800
    13.2 +++ b/flup/server/scgi_fork.py	Thu Dec 04 09:55:21 2008 -0800
    13.3 @@ -66,8 +66,8 @@
    13.4  import logging
    13.5  import socket
    13.6  
    13.7 -from flup.server.scgi_base import BaseSCGIServer, Connection, NoDefault
    13.8 -from flup.server.preforkserver import PreforkServer
    13.9 +from .scgi_base import BaseSCGIServer, Connection, NoDefault
   13.10 +from .preforkserver import PreforkServer
   13.11  
   13.12  __all__ = ['WSGIServer']
   13.13  
   13.14 @@ -128,7 +128,7 @@
   13.15                                  loggingLevel=loggingLevel,
   13.16                                  debug=debug)
   13.17          for key in ('multithreaded', 'multiprocess', 'jobClass', 'jobArgs'):
   13.18 -            if kw.has_key(key):
   13.19 +            if key in kw:
   13.20                  del kw[key]
   13.21          PreforkServer.__init__(self, jobClass=Connection, jobArgs=(self,), **kw)
   13.22  
   13.23 @@ -142,7 +142,7 @@
   13.24  
   13.25          try:
   13.26              sock = self._setupSocket()
   13.27 -        except socket.error, e:
   13.28 +        except socket.error as e:
   13.29              self.logger.error('Failed to bind socket (%s), exiting', e[1])
   13.30              return False
   13.31  
   13.32 @@ -156,23 +156,23 @@
   13.33          return ret
   13.34  
   13.35  def factory(global_conf, host=None, port=None, **local):
   13.36 -    import paste_factory
   13.37 +    from . import paste_factory
   13.38      return paste_factory.helper(WSGIServer, global_conf, host, port, **local)
   13.39  
   13.40  if __name__ == '__main__':
   13.41      def test_app(environ, start_response):
   13.42          """Probably not the most efficient example."""
   13.43 -        import cgi
   13.44 +        from . import cgi
   13.45          start_response('200 OK', [('Content-Type', 'text/html')])
   13.46          yield '<html><head><title>Hello World!</title></head>\n' \
   13.47                '<body>\n' \
   13.48                '<p>Hello World!</p>\n' \
   13.49                '<table border="1">'
   13.50 -        names = environ.keys()
   13.51 +        names = list(environ.keys())
   13.52          names.sort()
   13.53          for name in names:
   13.54              yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
   13.55 -                name, cgi.escape(`environ[name]`))
   13.56 +                name, cgi.escape(repr(environ[name])))
   13.57  
   13.58          form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
   13.59                                  keep_blank_values=1)
    14.1 --- a/flup/server/threadedserver.py	Wed Dec 03 10:43:53 2008 -0800
    14.2 +++ b/flup/server/threadedserver.py	Thu Dec 04 09:55:21 2008 -0800
    14.3 @@ -42,7 +42,7 @@
    14.4      def setCloseOnExec(sock):
    14.5          fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
    14.6  
    14.7 -from flup.server.threadpool import ThreadPool
    14.8 +from .threadpool import ThreadPool
    14.9  
   14.10  __all__ = ['ThreadedServer']
   14.11  
   14.12 @@ -74,7 +74,7 @@
   14.13          while self._keepGoing:
   14.14              try:
   14.15                  r, w, e = select.select([sock], [], [], timeout)
   14.16 -            except select.error, e:
   14.17 +            except select.error as e:
   14.18                  if e[0] == errno.EINTR:
   14.19                      continue
   14.20                  raise
   14.21 @@ -82,7 +82,7 @@
   14.22              if r:
   14.23                  try:
   14.24                      clientSock, addr = sock.accept()
   14.25 -                except socket.error, e:
   14.26 +                except socket.error as e:
   14.27                      if e[0] in (errno.EINTR, errno.EAGAIN):
   14.28                          continue
   14.29                      raise
   14.30 @@ -162,12 +162,12 @@
   14.31              self._sock = sock
   14.32              self._addr = addr
   14.33          def run(self):
   14.34 -            print "Client connection opened from %s:%d" % self._addr
   14.35 +            print("Client connection opened from %s:%d" % self._addr)
   14.36              self._sock.send('Hello World!\n')
   14.37              self._sock.setblocking(1)
   14.38              self._sock.recv(1)
   14.39              self._sock.close()
   14.40 -            print "Client connection closed from %s:%d" % self._addr
   14.41 +            print("Client connection closed from %s:%d" % self._addr)
   14.42      sock = socket.socket()
   14.43      sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
   14.44      sock.bind(('', 8080))
    15.1 --- a/flup/server/threadpool.py	Wed Dec 03 10:43:53 2008 -0800
    15.2 +++ b/flup/server/threadpool.py	Thu Dec 04 09:55:21 2008 -0800
    15.3 @@ -28,7 +28,7 @@
    15.4  __version__ = '$Revision$'
    15.5  
    15.6  import sys
    15.7 -import thread
    15.8 +import _thread
    15.9  import threading
   15.10  
   15.11  class ThreadPool(object):
   15.12 @@ -38,7 +38,7 @@
   15.13      the number of threads that can be started, but this can be controlled
   15.14      by maxThreads.
   15.15      """
   15.16 -    def __init__(self, minSpare=1, maxSpare=5, maxThreads=sys.maxint):
   15.17 +    def __init__(self, minSpare=1, maxSpare=5, maxThreads=sys.maxsize):
   15.18          self._minSpare = minSpare
   15.19          self._maxSpare = maxSpare
   15.20          self._maxThreads = max(minSpare, maxThreads)
   15.21 @@ -49,7 +49,7 @@
   15.22  
   15.23          # Start the minimum number of worker threads.
   15.24          for i in range(maxSpare):
   15.25 -            thread.start_new_thread(self._worker, ())
   15.26 +            _thread.start_new_thread(self._worker, ())
   15.27  
   15.28      def addJob(self, job, allowQueuing=True):
   15.29          """
   15.30 @@ -71,7 +71,7 @@
   15.31                    self._workerCount < self._maxThreads:
   15.32                  self._workerCount += 1
   15.33                  self._idleCount += 1
   15.34 -                thread.start_new_thread(self._worker, ())
   15.35 +                _thread.start_new_thread(self._worker, ())
   15.36  
   15.37              # Hand off the job.
   15.38              if self._idleCount or allowQueuing: