python: Fixed async module bug.
[ashd.git] / python3 / ashd / async.py
index 3493959..e30f858 100644 (file)
@@ -26,7 +26,7 @@ class epoller(object):
     def exception(self, ch, *exc):
         self.remove(ch)
         if self.exc_handler is None:
-            traceback.print_exception(exc)
+            traceback.print_exception(*exc)
         else:
             self.exc_handler(ch, *exc)
 
@@ -165,12 +165,25 @@ class epoller(object):
 def watcher():
     return epoller()
 
-class sockbuffer(object):
-    def __init__(self, sk):
-        self.sk = sk
+class channel(object):
+    readable = False
+    writable = False
+
+    def __init__(self):
+        self.watcher = None
+
+    def fileno(self):
+        raise NotImplementedError("fileno()")
+
+    def close(self):
+        pass
+
+class sockbuffer(channel):
+    def __init__(self, socket, **kwargs):
+        super().__init__(**kwargs)
+        self.sk = socket
         self.eof = False
         self.obuf = bytearray()
-        self.watcher = None
 
     def fileno(self):
         return self.sk.fileno()
@@ -211,8 +224,9 @@ class sockbuffer(object):
             self.obuf[:] = b""
             self.eof = True
 
-class callbuffer(object):
-    def __init__(self):
+class callbuffer(channel):
+    def __init__(self, **kwargs):
+        super().__init__(**kwargs)
         self.queue = []
         self.rp, self.wp = os.pipe()
         self.lock = threading.Lock()