This commit is contained in:
Tobias Oberstein
2014-04-11 01:07:11 +02:00
parent 0ac8fc5d0e
commit d4467b9dcc
36 changed files with 40 additions and 268 deletions

View File

@@ -321,14 +321,14 @@ class ApplicationSession(BaseSession):
""" """
Implements :func:`autobahn.wamp.interfaces.ISession.onConnect` Implements :func:`autobahn.wamp.interfaces.ISession.onConnect`
""" """
self.join(six.u(self.config.realm)) self.join(self.config.realm)
def join(self, realm): def join(self, realm):
""" """
Implements :func:`autobahn.wamp.interfaces.ISession.join` Implements :func:`autobahn.wamp.interfaces.ISession.join`
""" """
if True or six.PY2 and type(realm) == str: if six.PY2 and type(realm) == str:
realm = six.u(realm) realm = six.u(realm)
if self._session_id: if self._session_id:

View File

@@ -23,7 +23,10 @@ import six
class ComponentConfig: class ComponentConfig:
def __init__(self, realm = None, extra = None): def __init__(self, realm = None, extra = None):
self.realm = six.u(realm) if six.PY2 and type(realm) == str:
self.realm = six.u(realm)
else:
self.realm = realm
self.extra = extra self.extra = extra
@@ -125,7 +128,9 @@ class SubscribeOptions:
assert(details_arg is None or type(details_arg) == str) assert(details_arg is None or type(details_arg) == str)
self.details_arg = details_arg self.details_arg = details_arg
self.options = {'match': six.u(match)} if match and six.PY2 and type(match) == str:
match = six.u(match)
self.options = {'match': match}
@@ -207,7 +212,6 @@ class RegisterOptions:
in this keyword argument to the callable. in this keyword argument to the callable.
:type details_arg: str :type details_arg: str
""" """
assert(details_arg is None or type(details_arg) == six.text_type)
self.details_arg = details_arg self.details_arg = details_arg
self.options = { self.options = {
'pkeys': pkeys, 'pkeys': pkeys,

View File

@@ -32,6 +32,9 @@ if __name__ == '__main__':
parser.add_argument("-c", "--component", type = str, parser.add_argument("-c", "--component", type = str,
help = "Start WAMP client with this application component, e.g. 'timeservice.TimeServiceFrontend'") help = "Start WAMP client with this application component, e.g. 'timeservice.TimeServiceFrontend'")
parser.add_argument("-r", "--realm", type = str, default = "realm1",
help = "The WAMP realm to start the component in (if any).")
parser.add_argument("--host", type = str, default = "127.0.0.1", parser.add_argument("--host", type = str, default = "127.0.0.1",
help = 'IP or hostname to connect to.') help = 'IP or hostname to connect to.')
@@ -51,7 +54,7 @@ if __name__ == '__main__':
## ##
from autobahn.asyncio.wamp import ApplicationSessionFactory from autobahn.asyncio.wamp import ApplicationSessionFactory
from autobahn.wamp import types from autobahn.wamp import types
session_factory = ApplicationSessionFactory(types.ComponentConfig(realm = u"realm1")) session_factory = ApplicationSessionFactory(types.ComponentConfig(realm = args.realm))
## dynamically load the application component .. ## dynamically load the application component ..

View File

@@ -38,7 +38,7 @@ class Component(ApplicationSession):
print("{}: {} in {}".format(msg, res, duration)) print("{}: {} in {}".format(msg, res, duration))
t1 = time.clock() t1 = time.clock()
d1 = self.call('com.math.slowsquare', 3) d1 = self.call('com.math.slowsquare', 3, 2)
d1.add_done_callback(partial(got, t1, "Slow Square")) d1.add_done_callback(partial(got, t1, "Slow Square"))
t2 = time.clock() t2 = time.clock()

View File

@@ -32,6 +32,9 @@ if __name__ == '__main__':
parser.add_argument("-c", "--component", type = str, default = None, parser.add_argument("-c", "--component", type = str, default = None,
help = "Start WAMP server with this application component, e.g. 'timeservice.TimeServiceBackend', or None.") help = "Start WAMP server with this application component, e.g. 'timeservice.TimeServiceBackend', or None.")
parser.add_argument("-r", "--realm", type = str, default = "realm1",
help = "The WAMP realm to start the component in (if any).")
parser.add_argument("--interface", type = str, default = "127.0.0.1", parser.add_argument("--interface", type = str, default = "127.0.0.1",
help = 'IP of interface to listen on.') help = 'IP of interface to listen on.')
@@ -71,7 +74,7 @@ if __name__ == '__main__':
## run next to the router ## run next to the router
## ##
from autobahn.wamp import types from autobahn.wamp import types
session_factory.add(SessionKlass(types.ComponentConfig(realm = u"realm1"))) session_factory.add(SessionKlass(types.ComponentConfig(realm = args.realm)))
if args.transport == "websocket": if args.transport == "websocket":

View File

@@ -35,6 +35,9 @@ if __name__ == '__main__':
parser.add_argument("-c", "--component", type = str, parser.add_argument("-c", "--component", type = str,
help = "Start WAMP client with this application component, e.g. 'timeservice.TimeServiceFrontend'") help = "Start WAMP client with this application component, e.g. 'timeservice.TimeServiceFrontend'")
parser.add_argument("-r", "--realm", type = str, default = "realm1",
help = "The WAMP realm to start the component in (if any).")
parser.add_argument("--endpoint", type = str, default = "tcp:127.0.0.1:8080", parser.add_argument("--endpoint", type = str, default = "tcp:127.0.0.1:8080",
help = 'Twisted client endpoint descriptor, e.g. "tcp:127.0.0.1:8080" or "unix:/tmp/mywebsocket".') help = 'Twisted client endpoint descriptor, e.g. "tcp:127.0.0.1:8080" or "unix:/tmp/mywebsocket".')
@@ -64,7 +67,8 @@ if __name__ == '__main__':
## create a WAMP application session factory ## create a WAMP application session factory
## ##
from autobahn.twisted.wamp import ApplicationSessionFactory from autobahn.twisted.wamp import ApplicationSessionFactory
session_factory = ApplicationSessionFactory() from autobahn.wamp import types
session_factory = ApplicationSessionFactory(types.ComponentConfig(realm = args.realm))
## dynamically load the application component .. ## dynamically load the application component ..

View File

@@ -29,15 +29,6 @@ class Component(ApplicationSession):
An application component that publishes an event every second. An application component that publishes an event every second.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
counter = 0 counter = 0

View File

@@ -29,10 +29,6 @@ class Component(ApplicationSession):
and stop after having received 5 events. and stop after having received 5 events.
""" """
def onConnect(self):
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -47,9 +43,5 @@ class Component(ApplicationSession):
yield self.subscribe(on_event, 'com.myapp.topic1') yield self.subscribe(on_event, 'com.myapp.topic1')
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -33,15 +33,6 @@ class Component(ApplicationSession):
and with complex payloads every second. and with complex payloads every second.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):

View File

@@ -33,10 +33,6 @@ class Component(ApplicationSession):
of no payload and of complex payload, and stops after 5 seconds. of no payload and of complex payload, and stops after 5 seconds.
""" """
def onConnect(self):
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -57,9 +53,5 @@ class Component(ApplicationSession):
reactor.callLater(5, self.leave) reactor.callLater(5, self.leave)
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -29,15 +29,6 @@ class Component(ApplicationSession):
An application component that publishes an event every second. An application component that publishes an event every second.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
counter = 0 counter = 0

View File

@@ -30,16 +30,6 @@ class Component(ApplicationSession):
and stop after having received 5 events. and stop after having received 5 events.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
self.received = 0
def onConnect(self):
self.join(self._realm)
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -69,9 +59,5 @@ class Component(ApplicationSession):
print("Got event on topic2: {}".format(msg)) print("Got event on topic2: {}".format(msg))
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -30,15 +30,6 @@ class Component(ApplicationSession):
An application component that publishes an event every second. An application component that publishes an event every second.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):

View File

@@ -31,10 +31,6 @@ class Component(ApplicationSession):
and stop after having received 5 events. and stop after having received 5 events.
""" """
def onConnect(self):
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -50,9 +46,5 @@ class Component(ApplicationSession):
options = SubscribeOptions(details_arg = 'details')) options = SubscribeOptions(details_arg = 'details'))
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -29,15 +29,6 @@ class Component(ApplicationSession):
An application component that publishes an event every second. An application component that publishes an event every second.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):

View File

@@ -53,10 +53,6 @@ class Component(ApplicationSession):
print("Subscribed with subscription ID {}".format(self.subscription.id)) print("Subscribed with subscription ID {}".format(self.subscription.id))
def onConnect(self):
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -64,9 +60,5 @@ class Component(ApplicationSession):
yield self.test() yield self.test()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -28,10 +28,6 @@ class Component(ApplicationSession):
An application component providing procedures with different kinds of arguments. An application component providing procedures with different kinds of arguments.
""" """
def onConnect(self):
self.join(u"realm1")
def onJoin(self, details): def onJoin(self, details):
def ping(): def ping():

View File

@@ -28,10 +28,6 @@ class Component(ApplicationSession):
An application component calling the different backend procedures. An application component calling the different backend procedures.
""" """
def onConnect(self):
self.join(u"realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -74,9 +70,5 @@ class Component(ApplicationSession):
self.leave() self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -30,15 +30,6 @@ class Component(ApplicationSession):
return complex results. return complex results.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
def onJoin(self, details): def onJoin(self, details):
def add_complex(a, ai, b, bi): def add_complex(a, ai, b, bi):

View File

@@ -30,10 +30,6 @@ class Component(ApplicationSession):
produce complex results and showing how to access those. produce complex results and showing how to access those.
""" """
def onConnect(self):
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -46,9 +42,5 @@ class Component(ApplicationSession):
self.leave() self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -30,17 +30,9 @@ class Component(ApplicationSession):
An application component registering RPC endpoints using decorators. An application component registering RPC endpoints using decorators.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
print("273423")
## register all methods on this object decorated with "@wamp.procedure" ## register all methods on this object decorated with "@wamp.procedure"
## as a RPC endpoint ## as a RPC endpoint

View File

@@ -28,21 +28,13 @@ class Component(ApplicationSession):
An application component calling the different backend procedures. An application component calling the different backend procedures.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
print("SDFJSDLF")
procs = ['com.mathservice.add2', procs = [u'com.mathservice.add2',
'com.mathservice.mul2', u'com.mathservice.mul2',
'com.mathservice.div2'] u'com.mathservice.div2']
try: try:
for proc in procs: for proc in procs:
@@ -54,9 +46,5 @@ class Component(ApplicationSession):
self.leave() self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -41,15 +41,6 @@ class Component(ApplicationSession):
Example WAMP application backend that raised exceptions. Example WAMP application backend that raised exceptions.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
def onJoin(self, details): def onJoin(self, details):
## raising standard exceptions ## raising standard exceptions

View File

@@ -41,10 +41,6 @@ class Component(ApplicationSession):
Example WAMP application frontend that catches exceptions. Example WAMP application frontend that catches exceptions.
""" """
def onConnect(self):
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -83,9 +79,5 @@ class Component(ApplicationSession):
self.leave() self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -30,15 +30,6 @@ class Component(ApplicationSession):
different kinds of arguments. different kinds of arguments.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
def onJoin(self, details): def onJoin(self, details):
def square(val, details = None): def square(val, details = None):

View File

@@ -29,10 +29,6 @@ class Component(ApplicationSession):
An application component calling the different backend procedures. An application component calling the different backend procedures.
""" """
def onConnect(self):
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -48,9 +44,5 @@ class Component(ApplicationSession):
self.leave() self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -30,14 +30,6 @@ class Component(ApplicationSession):
Application component that produces progressive results. Application component that produces progressive results.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
def onJoin(self, details): def onJoin(self, details):

View File

@@ -30,10 +30,6 @@ class Component(ApplicationSession):
Application component that consumes progressive results. Application component that consumes progressive results.
""" """
def onConnect(self):
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
@@ -47,9 +43,5 @@ class Component(ApplicationSession):
self.leave() self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -30,15 +30,6 @@ class Component(ApplicationSession):
A math service application component. A math service application component.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
def onJoin(self, details): def onJoin(self, details):
def square(x): def square(x):

View File

@@ -30,10 +30,6 @@ class Component(ApplicationSession):
An application component using the time service. An application component using the time service.
""" """
def onConnect(self):
self.join("realm1")
def onJoin(self, details): def onJoin(self, details):
def got(res, started, msg): def got(res, started, msg):
@@ -55,9 +51,5 @@ class Component(ApplicationSession):
DeferredList ([d1, d2]).addBoth(done) DeferredList ([d1, d2]).addBoth(done)
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -27,15 +27,6 @@ class Component(ApplicationSession):
A simple time service application component. A simple time service application component.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
def onJoin(self, details): def onJoin(self, details):
def utcnow(): def utcnow():

View File

@@ -30,10 +30,6 @@ class Component(ApplicationSession):
An application component using the time service. An application component using the time service.
""" """
def onConnect(self):
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
try: try:
@@ -46,9 +42,5 @@ class Component(ApplicationSession):
self.leave() self.leave()
def onLeave(self, details):
self.disconnect()
def onDisconnect(self): def onDisconnect(self):
reactor.stop() reactor.stop()

View File

@@ -35,6 +35,9 @@ if __name__ == '__main__':
parser.add_argument("-c", "--component", type = str, default = None, parser.add_argument("-c", "--component", type = str, default = None,
help = "Start WAMP server with this application component, e.g. 'timeservice.TimeServiceBackend', or None.") help = "Start WAMP server with this application component, e.g. 'timeservice.TimeServiceBackend', or None.")
parser.add_argument("-r", "--realm", type = str, default = "realm1",
help = "The WAMP realm to start the component in (if any).")
parser.add_argument("--endpoint", type = str, default = "tcp:8080", parser.add_argument("--endpoint", type = str, default = "tcp:8080",
help = 'Twisted server endpoint descriptor, e.g. "tcp:8080" or "unix:/tmp/mywebsocket".') help = 'Twisted server endpoint descriptor, e.g. "tcp:8080" or "unix:/tmp/mywebsocket".')
@@ -84,7 +87,8 @@ if __name__ == '__main__':
## .. and create and add an WAMP application session to ## .. and create and add an WAMP application session to
## run next to the router ## run next to the router
## ##
session_factory.add(SessionKlass()) from autobahn.wamp import types
session_factory.add(SessionKlass(types.ComponentConfig(realm = args.realm)))
if args.transport == "websocket": if args.transport == "websocket":

View File

@@ -26,13 +26,6 @@ from autobahn.twisted.wamp import ApplicationSession
class MyAppComponent(ApplicationSession): class MyAppComponent(ApplicationSession):
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
def onJoin(self, details): def onJoin(self, details):
if not self.factory._myAppSession: if not self.factory._myAppSession:
self.factory._myAppSession = self self.factory._myAppSession = self

View File

@@ -30,15 +30,6 @@ class Component(ApplicationSession):
A simple time service application component. A simple time service application component.
""" """
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
def onJoin(self, details): def onJoin(self, details):
def utcnow(): def utcnow():

View File

@@ -31,17 +31,11 @@ class Component(ApplicationSession):
during 3 subsequent WAMP sessions, while the during 3 subsequent WAMP sessions, while the
underlying transport continues to exist. underlying transport continues to exist.
""" """
def __init__(self, config):
def __init__(self): ApplicationSession.__init__(self, config)
ApplicationSession.__init__(self)
self.count = 0 self.count = 0
def onConnect(self):
print("Transport connected.")
self.join("realm1")
@inlineCallbacks @inlineCallbacks
def onJoin(self, details): def onJoin(self, details):
print("Realm joined (WAMP session started).") print("Realm joined (WAMP session started).")