Skip to content
Snippets Groups Projects
Commit bb0e8209 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added protocols documentation.

parent 946f6991
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,17 @@
Core library
------------
Sub-packages
~~~~~~~~~~~~
.. toctree::
:maxdepth: 2
core.protocols
Module members
~~~~~~~~~~~~~~
.. automodule:: sjrpc.core
:members:
:inherited-members:
......@@ -18,7 +18,7 @@ It also contains a sub-package containing protocols: :mod:`core.protocols`.
.. toctree::
:hidden:
api/core.protocols
core.protocols
'''
......
'''
Protocols can be binded on a specific label of a :class:`RpcConnection` (see
`Multiplexing & protocols`_ for more informations).
Following protocols are provided with standard distribution of sjRpc, but you
can create yours if you needs:
- :class:`RpcProtocol`: the standard rpc protocol
- :class:`TunnelProtocol`: a protocol which allow to tunnel a socket traffic
through the sjRpc connection
- :class:`VpnProtocol` (experimental): like :class:`TunnelProtocol` but work
with a network interface instead of a socket.
'''
import logging
class Protocol(object):
'''
Base class for all protocols.
'''
def __init__(self, connection, label, logger=None):
self._connection = connection
self._label = label
......@@ -62,3 +82,5 @@ class Protocol(object):
from sjrpc.core.protocols.rpc import RpcProtocol
from sjrpc.core.protocols.tunnel import TunnelProtocol
__all__ = ['Protocol', 'RpcProtocol', 'TunnelProtocol']
......@@ -9,23 +9,24 @@ from sjrpc.core.callers import RpcCaller, ThreadedRpcCaller
from sjrpc.core.exceptions import RpcError
from sjrpc.core.protocols import Protocol
__all__ = ['RpcProtocol']
class RpcProtocol(Protocol):
REQUEST_MESSAGE = {'id': None, 'method': None, 'args': [], 'kwargs': {}}
RESPONSE_MESSAGE = {'id': None, 'return': None, 'error': None}
SPECIAL_MESSAGE = {'special': None}
'''
The standard protocol used to do RPC request/responses.
:param connection: the connection serving this :class:`RpcProtocol`
:param label: the label of this :class:`RpcProtocol` instance
:param handler: command handler to bind by default
:param on_disconnect: callback called when client disconnect
:param request_decorator: decorator applied on each handler function
:param timeout: global command timeout
:param logger: logging module :class:`Logger` instance
'''
REQUEST_MESSAGE = {'id': None, 'method': None, 'args': [], 'kwargs': {}}
RESPONSE_MESSAGE = {'id': None, 'return': None, 'error': None}
SPECIAL_MESSAGE = {'special': None}
def __init__(self, connection, label, handler=None, on_disconnect=None,
request_decorator=None, timeout=30, *args, **kwargs):
super(RpcProtocol, self).__init__(connection, label, *args, **kwargs)
......
......@@ -6,6 +6,8 @@ from sjrpc.core.protocols import Protocol
import pyev
__all__ = ['TunnelProtocol']
class TunnelProtocol(Protocol):
'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment