home · contact · privacy
Simplify PlomSocket code.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 2 Nov 2020 03:35:58 +0000 (04:35 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 2 Nov 2020 03:35:58 +0000 (04:35 +0100)
new2/plomrogue/io_tcp.py

index 5dd2508a8708d5cca43836aceb396d9231ed1d0a..203021cd06b9b7c34e2eab8efa8749c1e6188155 100644 (file)
@@ -115,8 +115,7 @@ class PlomSocketSSL(PlomSocket):
 
 class IO_Handler(socketserver.BaseRequestHandler):
 
-    def __init__(self, *args, socket_class=PlomSocket, **kwargs):
-        self.socket_class = socket_class
+    def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
 
     def handle(self):
@@ -147,12 +146,13 @@ class IO_Handler(socketserver.BaseRequestHandler):
         import uuid
         import queue
         import threading
-        if self.socket_class == PlomSocketSSL:
-            plom_socket = self.socket_class(self.request, server_side=True,
-                                            certfile=self.server.certfile,
-                                            keyfile=self.server.keyfile)
+        if self.server.socket_class == PlomSocketSSL:
+            plom_socket = self.server.socket_class(self.request,
+                                                   server_side=True,
+                                                   certfile=self.server.certfile,
+                                                   keyfile=self.server.keyfile)
         else:
-            plom_socket = self.socket_class(self.request)
+            plom_socket = self.server.socket_class(self.request)
         print('CONNECTION FROM:', str(self.client_address))
         connection_id = uuid.uuid4()
         queue_in = queue.Queue()
@@ -176,13 +176,6 @@ class IO_Handler(socketserver.BaseRequestHandler):
 
 
 
-class IO_HandlerSSL(IO_Handler):
-
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, socket_class=PlomSocketSSL, **kwargs)
-
-
-
 class PlomTCPServer(socketserver.ThreadingTCPServer):
     """Bind together threaded IO handling server and message queue.
 
@@ -192,8 +185,9 @@ class PlomTCPServer(socketserver.ThreadingTCPServer):
 
     """
 
-    def __init__(self, queue, port, host='127.0.0.1', io_handler=IO_Handler, *args, **kwargs):
-        super().__init__((host, port), io_handler, *args, **kwargs)
+    def __init__(self, queue, port, host='127.0.0.1', *args, **kwargs):
+        super().__init__((host, port), IO_Handler, *args, **kwargs)
+        self.socket_class = PlomSocket
         self.queue_out = queue
         self.daemon_threads = True  # Else, server's threads have daemon=False.
         self.clients = {}
@@ -203,6 +197,7 @@ class PlomTCPServer(socketserver.ThreadingTCPServer):
 class PlomTCPServerSSL(PlomTCPServer):
 
     def __init__(self, *args, certfile=None, keyfile=None, **kwargs):
+        super().__init__(*args, host='0.0.0.0', **kwargs)
         self.certfile = certfile
         self.keyfile = keyfile
-        super().__init__(*args, host='0.0.0.0', io_handler=IO_HandlerSSL, **kwargs)
+        self.socket_class = PlomSocketSSL