--- sneaky.py (original) +++ sneaky.py (refactored) @@ -112,8 +112,8 @@ import traceback import copy -from cStringIO import StringIO -from Queue import Queue +from io import StringIO +from queue import Queue regex_head = re.compile('^((http|https|HTTP|HTTPS)\://[^/]+)?(?P\w+)\s+(?P\S+)\s+(?P\S+)') regex_header = re.compile('\s*(?P.*?)\s*\:\s*(?P.*?)\s*$') regex_chunk = re.compile('^(?P\w+)') @@ -255,7 +255,7 @@ if not match: continue key = match.group('key').upper().replace('-','_') - if isinstance(key,unicode): + if isinstance(key,str): key = key.encode('ISO-8859-1') value = match.group('value') try: @@ -300,7 +300,7 @@ client_socket.sendall('%x\r\n%s\r\n' % (len(data),data)) else: client_socket.sendall(data) - except socket.error, e: + except socket.error as e: if e.args[0] not in socket_errors_to_ignore: raise if chunked: @@ -383,7 +383,7 @@ def start(self): """starts the server""" - print 'Experimental "Sneaky" WSGI web server. Starting...' + print('Experimental "Sneaky" WSGI web server. Starting...') for thread in Worker.threads: thread.start() self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -454,7 +454,7 @@ address = ([a for a in sys.argv[1:] if a[0]!='-'] + ['127.0.0.1:8000'])[0] - print 'serving from: '+address + print('serving from: '+address) server = Sneaky(address, # the ip:port test_wsgi_app, # the SWGI application