pygnetic / pygame_network / __init__.py

import logging
import message
import syncobject
import network
import serialization
from handler import Handler
from network import Server, Client

_logger = logging.getLogger(__name__)
register = message.message_factory.register


def init(events=False, event_val=1, logging_lvl=logging.INFO,
         n_module=('enet',), s_module=('msgpack', 'json')):
    """Initialize network library.

    events - allow sending Pygame events (default False)
    event_val - set event ID as event_val + pygame.USEREVENT (default 1)
    logging_lvl - level of logging messages (default logging.INFO, None to skip
                  initializing logging module
    n_module - string or list of strings with names of network
              library adapters, first available will be used
    s_module - string or list of strings with names of serialization
                    library adapters, first available will be used

    Note: Because of the dynamic loading of network library adapter, Client,
        Server and State classes will only be available after initialization.
    """
    global _network_module, _serialization_module
    if logging_lvl is not None:
        logging.basicConfig(level=logging_lvl,
                            format='%(asctime)-8s %(levelname)-8s %(message)s',
                            datefmt='%H:%M:%S')
    network.select_adapter(n_module)
    if network._selected_adapter is not None:
        _logger.info("Using %s",
            network._selected_adapter.__name__.split('.')[-1])
    else:
        _logger.critical("Can't find any network module")
    serialization.select_adapter(s_module)
    if serialization._selected_adapter is not None:
        _logger.info("Using %s",
            serialization._selected_adapter.__name__.split('.')[-1])
    else:
        _logger.critical("Can't find any serialization module")
    if events:
        _logger.info("Enabling pygame events")
        import event
        event.init(event_val)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.