Want more features on Pastebin? Sign Up, it's FREE!
Guest

illume

By: a guest on Sep 19th, 2009  |  syntax: None  |  size: 1.77 KB  |  views: 67  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. --- sneaky.py (original)
  2. +++ sneaky.py (refactored)
  3.  -112,8 +112,8 @@
  4.  import traceback
  5.  import copy
  6.  
  7. -from cStringIO import StringIO
  8. -from Queue import Queue
  9. +from io import StringIO
  10. +from queue import Queue
  11.  regex_head = re.compile('^((http|https|HTTP|HTTPS)\://[^/]+)?(?P<method>\w+)\s+(?P<uri>\S+)\s+(?P<protocol>\S+)')
  12.  regex_header = re.compile('\s*(?P<key>.*?)\s*\:\s*(?P<value>.*?)\s*$')
  13.  regex_chunk = re.compile('^(?P<size>\w+)')
  14.  -255,7 +255,7 @@
  15.              if not match:
  16.                  continue
  17.              key = match.group('key').upper().replace('-','_')
  18. -            if isinstance(key,unicode):
  19. +            if isinstance(key,str):
  20.                  key = key.encode('ISO-8859-1')
  21.              value = match.group('value')
  22.              try:
  23.  -300,7 +300,7 @@
  24.                      client_socket.sendall('%x\r\n%s\r\n' % (len(data),data))
  25.                  else:
  26.                      client_socket.sendall(data)
  27. -            except socket.error, e:
  28. +            except socket.error as e:
  29.                  if e.args[0] not in socket_errors_to_ignore:
  30.                      raise
  31.          if chunked:
  32.  -383,7 +383,7 @@
  33.  
  34.      def start(self):
  35.          """starts the server"""
  36. -        print 'Experimental "Sneaky" WSGI web server. Starting...'
  37. +        print('Experimental "Sneaky" WSGI web server. Starting...')
  38.          for thread in Worker.threads:
  39.              thread.start()
  40.          self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  41.  -454,7 +454,7 @@
  42.  
  43.      address = ([a for a in sys.argv[1:] if a[0]!='-'] + ['127.0.0.1:8000'])[0]
  44.  
  45. -    print 'serving from: '+address
  46. +    print('serving from: '+address)
  47.  
  48.      server = Sneaky(address, # the ip:port
  49.                      test_wsgi_app,  # the SWGI application
clone this paste RAW Paste Data