Skip to content

Commit

Permalink
polish generated code, type hints and docs (#1465)
Browse files Browse the repository at this point in the history
* polish generated code, type hints and docs
* generate invocation handler
  • Loading branch information
oberstet committed Feb 25, 2021
1 parent 5e5cbe4 commit d76cf87
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 79 deletions.
2 changes: 1 addition & 1 deletion autobahn/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
#
###############################################################################

__version__ = '21.2.2.dev4'
__version__ = '21.2.2'
8 changes: 4 additions & 4 deletions autobahn/twisted/wamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,15 +445,15 @@ def __init__(self, config, app):
@inlineCallbacks
def onConnect(self):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onConnect`
Implements :meth:`autobahn.wamp.interfaces.ISession.onConnect`
"""
yield self.app._fire_signal('onconnect')
self.join(self.config.realm)

@inlineCallbacks
def onJoin(self, details):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onJoin`
Implements :meth:`autobahn.wamp.interfaces.ISession.onJoin`
"""
for uri, proc in self.app._procs:
yield self.register(proc, uri)
Expand All @@ -466,15 +466,15 @@ def onJoin(self, details):
@inlineCallbacks
def onLeave(self, details):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onLeave`
Implements :meth:`autobahn.wamp.interfaces.ISession.onLeave`
"""
yield self.app._fire_signal('onleave')
self.disconnect()

@inlineCallbacks
def onDisconnect(self):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onDisconnect`
Implements :meth:`autobahn.wamp.interfaces.ISession.onDisconnect`
"""
yield self.app._fire_signal('ondisconnect')

Expand Down
18 changes: 9 additions & 9 deletions autobahn/wamp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,13 +1289,13 @@ def onChallenge(self, challenge):
@public
def onJoin(self, details):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onJoin`
Implements :meth:`autobahn.wamp.interfaces.ISession.onJoin`
"""

@public
def onWelcome(self, msg):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onWelcome`
Implements :meth:`autobahn.wamp.interfaces.ISession.onWelcome`
"""

def _errback_outstanding_requests(self, exc):
Expand Down Expand Up @@ -1339,7 +1339,7 @@ def _errback_outstanding_requests(self, exc):
@public
def onLeave(self, details):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onLeave`
Implements :meth:`autobahn.wamp.interfaces.ISession.onLeave`
"""
if details.reason != CloseDetails.REASON_DEFAULT:
self.log.warn('session closed with reason {reason} [{message}]', reason=details.reason, message=details.message)
Expand All @@ -1357,7 +1357,7 @@ def disconnect(_):
@public
def leave(self, reason=None, message=None):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.leave`
Implements :meth:`autobahn.wamp.interfaces.ISession.leave`
"""
if not self._session_id:
raise SessionNotReady("session hasn't joined a realm")
Expand All @@ -1378,7 +1378,7 @@ def leave(self, reason=None, message=None):
@public
def onDisconnect(self):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onDisconnect`
Implements :meth:`autobahn.wamp.interfaces.ISession.onDisconnect`
"""
# fire TransportLost on any _still_ outstanding requests
# (these should have been already cleaned up in onLeave() - when
Expand All @@ -1389,7 +1389,7 @@ def onDisconnect(self):
@public
def publish(self, topic, *args, **kwargs):
"""
Implements :func:`autobahn.wamp.interfaces.IPublisher.publish`
Implements :meth:`autobahn.wamp.interfaces.IPublisher.publish`
"""
assert(type(topic) == str)
assert(args is None or type(args) in (list, tuple))
Expand Down Expand Up @@ -1480,7 +1480,7 @@ def publish(self, topic, *args, **kwargs):
@public
def subscribe(self, handler, topic=None, options=None, check_types=False):
"""
Implements :func:`autobahn.wamp.interfaces.ISubscriber.subscribe`
Implements :meth:`autobahn.wamp.interfaces.ISubscriber.subscribe`
"""
assert((callable(handler) and topic is not None) or (hasattr(handler, '__class__') and not check_types))
assert(topic is None or type(topic) == str)
Expand Down Expand Up @@ -1583,7 +1583,7 @@ def _unsubscribe(self, subscription):
@public
def call(self, procedure, *args, **kwargs):
"""
Implements :func:`autobahn.wamp.interfaces.ICaller.call`
Implements :meth:`autobahn.wamp.interfaces.ICaller.call`
"""
assert(type(procedure) == str)
assert(args is None or type(args) in (list, tuple))
Expand Down Expand Up @@ -1681,7 +1681,7 @@ def canceller(d):
@public
def register(self, endpoint, procedure=None, options=None, prefix=None, check_types=False):
"""
Implements :func:`autobahn.wamp.interfaces.ICallee.register`
Implements :meth:`autobahn.wamp.interfaces.ICallee.register`
"""
assert((callable(endpoint) and procedure is not None) or (hasattr(endpoint, '__class__') and not check_types))
assert(procedure is None or type(procedure) == str)
Expand Down
16 changes: 8 additions & 8 deletions autobahn/wamp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class SessionDetails(object):
"""
Provides details for a WAMP session upon open.
.. seealso:: :func:`autobahn.wamp.interfaces.ISession.onJoin`
.. seealso:: :meth:`autobahn.wamp.interfaces.ISession.onJoin`
"""

__slots__ = (
Expand Down Expand Up @@ -538,7 +538,7 @@ class CloseDetails(object):
"""
Provides details for a WAMP session upon close.
.. seealso:: :func:`autobahn.wamp.interfaces.ISession.onLeave`
.. seealso:: :meth:`autobahn.wamp.interfaces.ISession.onLeave`
"""
REASON_DEFAULT = "wamp.close.normal"
REASON_TRANSPORT_LOST = "wamp.close.transport_lost"
Expand Down Expand Up @@ -578,7 +578,7 @@ def __str__(self):
class SubscribeOptions(object):
"""
Used to provide options for subscribing in
:func:`autobahn.wamp.interfaces.ISubscriber.subscribe`.
:meth:`autobahn.wamp.interfaces.ISubscriber.subscribe`.
"""

__slots__ = (
Expand Down Expand Up @@ -752,7 +752,7 @@ def __str__(self):
class PublishOptions(object):
"""
Used to provide options for subscribing in
:func:`autobahn.wamp.interfaces.IPublisher.publish`.
:meth:`autobahn.wamp.interfaces.IPublisher.publish`.
"""

__slots__ = (
Expand Down Expand Up @@ -904,7 +904,7 @@ def __str__(self):
class RegisterOptions(object):
"""
Used to provide options for registering in
:func:`autobahn.wamp.interfaces.ICallee.register`.
:meth:`autobahn.wamp.interfaces.ICallee.register`.
"""

__slots__ = (
Expand Down Expand Up @@ -1098,7 +1098,7 @@ def __str__(self):
@public
class CallOptions(object):
"""
Used to provide options for calling with :func:`autobahn.wamp.interfaces.ICaller.call`.
Used to provide options for calling with :meth:`autobahn.wamp.interfaces.ICaller.call`.
"""

__slots__ = (
Expand Down Expand Up @@ -1326,7 +1326,7 @@ def active(self):
def unsubscribe(self):
"""
Unsubscribe this subscription that was previously created from
:func:`autobahn.wamp.interfaces.ISubscriber.subscribe`.
:meth:`autobahn.wamp.interfaces.ISubscriber.subscribe`.
After a subscription has been unsubscribed successfully, no events
will be routed to the event handler anymore.
Expand Down Expand Up @@ -1364,7 +1364,7 @@ def active(self):
def unregister(self):
"""
Unregister this registration that was previously created from
:func:`autobahn.wamp.interfaces.ICallee.register`.
:meth:`autobahn.wamp.interfaces.ICallee.register`.
After a registration has been unregistered successfully, no calls
will be routed to the endpoint anymore.
Expand Down
2 changes: 1 addition & 1 deletion autobahn/xbr/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ def _main():
if fn not in initialized and os.path.exists(fn):
os.remove(fn)
with open(fn, 'wb') as fd:
fd.write('# Copyright (c) ...'.encode('utf8'))
fd.write('# Generated by Autobahn v{}\n'.format(__version__).encode('utf8'))
initialized.add(fn)

with open(fn, 'ab') as fd:
Expand Down
8 changes: 5 additions & 3 deletions autobahn/xbr/templates/obj.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import uuid
import pprint
from typing import Dict, List, Optional, TypeVar

from autobahn.wamp.request import Publication, Subscription, Registration

import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()
Expand Down Expand Up @@ -130,7 +132,7 @@ class {{ metadata.classname }}(object):
"""
Parse generic, native language object into a typed, native language object.

:param data: Generic native language object to parse, eg output of ``cbor2.loads``.
:param data: Generic native language object to parse, e.g. output of ``cbor2.loads``.

:returns: Typed object of this class.
"""
Expand Down Expand Up @@ -176,7 +178,7 @@ class {{ metadata.classname }}(object):
"""
Marshal all data contained in this typed native object into a generic object.

:returns: Generic object that can be serialized to bytes using eg ``cbor2.dumps``.
:returns: Generic object that can be serialized to bytes using e.g. ``cbor2.dumps``.
"""
obj = {
{% for field_name in metadata.fields_by_id %}
Expand All @@ -195,7 +197,7 @@ class {{ metadata.classname }}(object):

def __str__(self) -> str:
"""
Return string representation of this object, suitable for eg logging.
Return string representation of this object, suitable for e.g. logging.

:returns: String representation of this object.
"""
Expand Down

0 comments on commit d76cf87

Please sign in to comment.