Commits

Miki Tebeka committed 71152c0

Starting py3 port

  • Participants
  • Parent commits 29e0b38
  • Branches py3

Comments (0)

Files changed (2)

 '''
 
 __author__ = 'Miki Tebeka <miki.tebeka@gmail.com>'
-__version__ = '0.1.2'
+__version__ = '0.2.0'
 
-from SocketServer import StreamRequestHandler, TCPServer, ThreadingMixIn
+from six import b, exec_
+from six.moves import socketserver as socksrv
 from threading import Thread
-from traceback import print_exc
+from traceback import format_exc
 import socket
 
 EOF = chr(4)
 DEFAULT_PORT = 9998
 
 
-class PyHandler(StreamRequestHandler):
+class PyHandler(socksrv.StreamRequestHandler):
     password = None
     env = {}
 
     def handle(self):
         env = self.env.copy()
-        self.wfile.write('Welcome to ingress (type "exit()" to exit)\n')
+        self.wfile.write(b('Welcome to ingress (type "exit()" to exit)\n'))
 
         if not self.login():
             return
 
         while True:
             try:
-                self.wfile.write('>>> ')
+                self.wfile.write(b('>>> '))
                 expr = self.rfile.readline().rstrip()
                 if expr == EOF:
                     return
                     value = eval(expr, globals(), env)
                     self.wfile.write(format(value) + '\n')
                 except:
-                    exec expr in env
+                    exec_(expr, env)
             except (EOFError, SystemExit, socket.error):
                 return
             except Exception:
-                print_exc(file=self.wfile)
+                error = format_exc()
+                self.wfile.write(b(error))
 
     def finish(self):
         try:
-            StreamRequestHandler.finish(self)
+            socksrv.StreamRequestHandler.finish(self)
         except socket.error:
             pass
 
         return False
 
 
-class ThreadedServer(ThreadingMixIn, TCPServer):
+class ThreadedServer(socksrv.ThreadingMixIn, socksrv.TCPServer):
     daemon_threads = True
     allow_reuse_address = True
 
     license='MIT License',
     platforms=['any'],
     zip_safe=True,
-    py_modules=['ingress']
+    py_modules=['ingress'],
+    install_requires=['six'],
 )