Commits

Szymon Wróblewski committed 439fee2

small bugs fixed

Comments (0)

Files changed (6)

doc/source/api/index.rst

       
          Called when ``message_name`` message is received
          
+         :param message: received message
          :param kwargs:
             additional keyword arguments from :term:`network adapter`
       
    The only drawback of this method is the need to register the same messages
    in the same order in client and server.
 
-**Why order of creating messages is important?**
+**Why order of registration messages is important?**
    As You may noticed in previous example, there is no string with type of
    message in packed data. That's because type is encoded as integer,
-   depending on order of creation.
+   depending on order of registration.
 
 
 Glossary

pygnetic/__init__.py

 """Network library for Pygame."""
 
 import logging
+import event
 import message
 import network
 import serialization
 register = message.message_factory.register
 
 
-def init(events=False, event_val=1, logging_lvl=logging.INFO,
+def init(events=False, event_val=None, logging_lvl=logging.INFO,
          n_module=('enet', 'socket'), s_module=('msgpack', 'json')):
     """Initialize network library.
 
     :param events: allow sending Pygame events (default False)
     :param event_val:
         set :const:`event.NETWORK` as
-        :const:`pygame.USEREVENT` + :attr:`event_val` (default: 1)
+        :const:`pygame.USEREVENT` + :attr:`event_val` (default: None)
     :param logging_lvl:
         level of logging messages (default :const:`logging.INFO`
         (see: :ref:`logging-basic-tutorial`), None to skip initializing
         return False
     if events:
         _logger.info("Enabling pygame events")
-        import event
         event.init(event_val)
     return True

pygnetic/event.py

     pass
 
 
-def init(event_val=1):
+def init(event_val=None):
     global NETWORK, connected, disconnected, received
     import pygame
     from pygame.event import Event
     from pygame.locals import USEREVENT
-    NETWORK = USEREVENT + event_val
+    if event_val is not None:
+        NETWORK = USEREVENT + event_val
 
     def _accepted(connection):
         pygame.event.post(Event(NETWORK, {

pygnetic/handler.py

         """Called when message is received, but no corresponding
         net_message_name method exist.
 
+        :param message: received message
         :param kwargs:
             additional keyword arguments from :term:`network adapter`
         """

pygnetic/network/__init__.py

     def __new__(cls, *args, **kwargs):
         "Create instance of Client class depending on selected network adapter"
         b = cls.__bases__
+        if selected_adapter is None:
+            raise AttributeError("Client adapter is not selected")
         if Client in b:  # creation by inheritance
             i = b.index(Client) + 1
             cls.__bases__ = b[:i] + (selected_adapter.Client,) + b[i:]
     def __new__(cls, *args, **kwargs):
         "Create instance of Server class depending on selected network adapter"
         b = cls.__bases__
+        if selected_adapter is None:
+            raise AttributeError("Client adapter is not selected")
         if Server in b:  # creation by inheritance
             i = b.index(Server) + 1
             cls.__bases__ = b[:i] + (selected_adapter.Server,) + b[i:]

pygnetic/network/enet_adapter.py

 
 
 class Server(server.Server):
-    def __init__(self, host='', port=0, con_limit=4, *args, **kwargs):
-        super(Server, self).__init__(host, port, con_limit, *args, **kwargs)
+    def __init__(self, host='', port=0, conn_limit=4, *args, **kwargs):
+        super(Server, self).__init__(host, port, conn_limit, *args, **kwargs)
         host = enet.Address(host, port)
-        self.host = enet.Host(host, con_limit, *args, **kwargs)
+        self.host = enet.Host(host, conn_limit, *args, **kwargs)
         self._peer_cnt = 0
 
     def update(self, timeout=0):