Pārlūkot izejas kodu

moved explanation of server.__init__ args to docsting

digital 7 gadi atpakaļ
vecāks
revīzija
92b3d486f8
1 mainītis faili ar 26 papildinājumiem un 17 dzēšanām
  1. 26 17
      network/__init__.py

+ 26 - 17
network/__init__.py

@@ -182,38 +182,47 @@ class ConnHandlerEcho(ConnHandler):
 
 class Server(object):
     """
-    Server opens either an unix or an inet connection. for every client which connects a new ClientHandler class is created.
+    Server opens either an unix or an inet connection. For every new client
+    a new ClientHandler object is created.
+    _string_ **host** and _int_ **port** are the filename, hostname or ip
+    address and the port respectively on which the connection will be opened.
+    If you make an AF_UNIX socket, port is ignored so simply pass None.
+    _object_ **handler_class** is the class (not an object of the class) used
+    for making connection handlers.
+    _dict_ **handler_kwargs** is a dict which will be passed as keyword
+    argumetns to the __init__ function of handler_class when creating a new
+    connection handler. Default is an emtpy dict.
+    _string_ **af_family** specifies the AF_FAMILY socket type, valid options
+    are: "AF_INET" for a inet socket and "AF_UNIX" for a unix (file) socket.
+    Default is "AF_INET".
+    _bool_ **log_ip** specifies wether the ip address of the server/client is logged.
+    Default is False.
+    _int_ **max_allowed_clients** specifies the maximum amount of clients
+    connected to the server at once. Default is 5 (for now. this will change
+    in the future).
     """
+    # set to true when the server shuts down, for instance after a
+    # fatal exception
+    self.exit_event = False
     def __init__(self,
             host,
-            port=None,
+            port,
+            handler_class,
+            handler_kwargs={},
             af_family="AF_INET",
             log_ip=False,
             max_allowed_clients=5,
-            handler_class=None,
-            handler_kwargs={},
             ):
         super(Server, self).__init__()
-        # set to true when the server shuts down, for instance after a
-        # fatal exception
-        self.exit_event =  False
-        # on which hostname or ip address the connection will be opened
         self.host = host
-        # on which port the connection will be opened
         self.port = port
-        # what AF_INET family to use, either AF_INET or AF_UNIX (file socket)
+        self.handler_class = handler_class
+        self.handler_kwargs = handler_kwargs
         self.af_family = af_family
-        # whether ip addresses will be logged
         self.log_ip = log_ip
-        # number of maximum client connection at a time
         self.max_allowed_clients = max_allowed_clients
-        # this handler class will be used when creating a new handler
-        self.handler_class = handler_class
-        # the kwargs passed to the handler's __init__ function
-        self.handler_kwargs = handler_kwargs
         # don't make the socket yet, we don't need right now. will be created
         # when the start method is called
-        # self.socket = self.make_socket()
         self.socket = None
         # create a task group for handlers, so we can easily cancel/terminate
         # them all at once