renamed autobahn _module_ to wamp; dito for classes
@@ -20,10 +20,10 @@ import sys
|
|||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.internet.defer import Deferred, DeferredList
|
from twisted.internet.defer import Deferred, DeferredList
|
||||||
from autobahn.autobahn import AutobahnClientFactory, AutobahnClientProtocol
|
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||||
|
|
||||||
|
|
||||||
class ClientProtocol(AutobahnClientProtocol):
|
class MyClientProtocol(WampClientProtocol):
|
||||||
"""
|
"""
|
||||||
Demonstrates simple Publish & Subscribe (PubSub) with
|
Demonstrates simple Publish & Subscribe (PubSub) with
|
||||||
Autobahn WebSockets and Twisted Deferreds.
|
Autobahn WebSockets and Twisted Deferreds.
|
||||||
@@ -60,7 +60,7 @@ class ClientProtocol(AutobahnClientProtocol):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
log.startLogging(sys.stdout)
|
log.startLogging(sys.stdout)
|
||||||
factory = AutobahnClientFactory(debug = False)
|
factory = WampClientFactory(debug = False)
|
||||||
factory.protocol = ClientProtocol
|
factory.protocol = MyClientProtocol
|
||||||
reactor.connectTCP("localhost", 9000, factory)
|
reactor.connectTCP("localhost", 9000, factory)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
import sys, math
|
import sys, math
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
from autobahn.autobahn import exportSub, exportPub, AutobahnServerFactory, AutobahnServerProtocol
|
from autobahn.wamp import exportSub, exportPub, WampServerFactory, WampServerProtocol
|
||||||
|
|
||||||
|
|
||||||
class TopicService:
|
class MyTopicService:
|
||||||
|
|
||||||
def __init__(self, allowedTopicIds):
|
def __init__(self, allowedTopicIds):
|
||||||
self.allowedTopicIds = allowedTopicIds
|
self.allowedTopicIds = allowedTopicIds
|
||||||
@@ -73,7 +73,7 @@ class TopicService:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class SimpleServerProtocol(AutobahnServerProtocol):
|
class MyServerProtocol(WampServerProtocol):
|
||||||
|
|
||||||
def onConnect(self, connectionRequest):
|
def onConnect(self, connectionRequest):
|
||||||
|
|
||||||
@@ -87,14 +87,14 @@ class SimpleServerProtocol(AutobahnServerProtocol):
|
|||||||
#self.registerForPubSub("", True)
|
#self.registerForPubSub("", True)
|
||||||
|
|
||||||
## register a topic handler to control topic subscriptions/publications
|
## register a topic handler to control topic subscriptions/publications
|
||||||
self.topicservice = TopicService([1, 3, 7])
|
self.topicservice = MyTopicService([1, 3, 7])
|
||||||
self.registerHandlerForPubSub(self.topicservice, "http://example.com/event/")
|
self.registerHandlerForPubSub(self.topicservice, "http://example.com/event/")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
log.startLogging(sys.stdout)
|
log.startLogging(sys.stdout)
|
||||||
factory = AutobahnServerFactory(debug_autobahn = True)
|
factory = WampServerFactory(debug_autobahn = True)
|
||||||
factory.protocol = SimpleServerProtocol
|
factory.protocol = MyServerProtocol
|
||||||
reactor.listenTCP(9000, factory)
|
reactor.listenTCP(9000, factory)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
import sys, decimal
|
import sys, decimal
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from autobahn.autobahn import exportRpc, AutobahnServerFactory, AutobahnServerProtocol
|
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
|
||||||
|
|
||||||
|
|
||||||
class CalculatorServerProtocol(AutobahnServerProtocol):
|
class CalculatorServerProtocol(WampServerProtocol):
|
||||||
|
|
||||||
def onConnect(self, connectionRequest):
|
def onConnect(self, connectionRequest):
|
||||||
self.registerForRpc(self, "http://example.com/simple/calculator#")
|
self.registerForRpc(self, "http://example.com/simple/calculator#")
|
||||||
@@ -70,7 +70,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
log.startLogging(sys.stdout)
|
log.startLogging(sys.stdout)
|
||||||
decimal.getcontext().prec = 20
|
decimal.getcontext().prec = 20
|
||||||
factory = AutobahnServerFactory(debug = False)
|
factory = WampServerFactory(debug = False)
|
||||||
factory.protocol = CalculatorServerProtocol
|
factory.protocol = CalculatorServerProtocol
|
||||||
reactor.listenTCP(9000, factory)
|
reactor.listenTCP(9000, factory)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
import sys
|
import sys
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from autobahn.autobahn import AutobahnClientFactory, AutobahnClientProtocol
|
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||||
|
|
||||||
|
|
||||||
class KeyValueClientProtocol(AutobahnClientProtocol):
|
class KeyValueClientProtocol(WampClientProtocol):
|
||||||
|
|
||||||
def done(self, *args):
|
def done(self, *args):
|
||||||
self.sendClose()
|
self.sendClose()
|
||||||
@@ -42,7 +42,7 @@ class KeyValueClientProtocol(AutobahnClientProtocol):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
log.startLogging(sys.stdout)
|
log.startLogging(sys.stdout)
|
||||||
factory = AutobahnClientFactory(debug = False)
|
factory = WampClientFactory(debug = False)
|
||||||
factory.protocol = KeyValueClientProtocol
|
factory.protocol = KeyValueClientProtocol
|
||||||
reactor.connectTCP("localhost", 9000, factory)
|
reactor.connectTCP("localhost", 9000, factory)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
import sys, shelve
|
import sys, shelve
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
from autobahn.autobahn import exportRpc, AutobahnServerFactory, AutobahnServerProtocol
|
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
|
||||||
|
|
||||||
|
|
||||||
class KeyValue:
|
class KeyValue:
|
||||||
@@ -48,7 +48,7 @@ class KeyValue:
|
|||||||
return self.store.keys()
|
return self.store.keys()
|
||||||
|
|
||||||
|
|
||||||
class KeyValueServerProtocol(AutobahnServerProtocol):
|
class KeyValueServerProtocol(WampServerProtocol):
|
||||||
"""
|
"""
|
||||||
Demonstrates creating a server with Autobahn WebSockets that provides
|
Demonstrates creating a server with Autobahn WebSockets that provides
|
||||||
a persistent key-value store which can we access via RPCs.
|
a persistent key-value store which can we access via RPCs.
|
||||||
@@ -60,12 +60,12 @@ class KeyValueServerProtocol(AutobahnServerProtocol):
|
|||||||
self.registerForRpc(self.factory.keyvalue, "http://example.com/simple/keyvalue#")
|
self.registerForRpc(self.factory.keyvalue, "http://example.com/simple/keyvalue#")
|
||||||
|
|
||||||
|
|
||||||
class KeyValueServerFactory(AutobahnServerFactory):
|
class KeyValueServerFactory(WampServerFactory):
|
||||||
|
|
||||||
protocol = KeyValueServerProtocol
|
protocol = KeyValueServerProtocol
|
||||||
|
|
||||||
def __init__(self, debug = False):
|
def __init__(self, debug = False):
|
||||||
AutobahnServerFactory.__init__(self, debug)
|
WampServerFactory.__init__(self, debug)
|
||||||
|
|
||||||
## the key-value store resides on the factory object, since it is to
|
## the key-value store resides on the factory object, since it is to
|
||||||
## be shared among all client connections
|
## be shared among all client connections
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import sys
|
|||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.internet.defer import Deferred, DeferredList
|
from twisted.internet.defer import Deferred, DeferredList
|
||||||
from autobahn.autobahn import AutobahnClientFactory, AutobahnClientProtocol
|
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||||
|
|
||||||
|
|
||||||
class SimpleClientProtocol(AutobahnClientProtocol):
|
class SimpleClientProtocol(WampClientProtocol):
|
||||||
"""
|
"""
|
||||||
Demonstrates simple Remote Procedure Calls (RPC) with
|
Demonstrates simple Remote Procedure Calls (RPC) with
|
||||||
Autobahn WebSockets and Twisted Deferreds.
|
Autobahn WebSockets and Twisted Deferreds.
|
||||||
@@ -66,7 +66,7 @@ class SimpleClientProtocol(AutobahnClientProtocol):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
log.startLogging(sys.stdout)
|
log.startLogging(sys.stdout)
|
||||||
factory = AutobahnClientFactory(debug = False)
|
factory = WampClientFactory(debug = False)
|
||||||
factory.protocol = SimpleClientProtocol
|
factory.protocol = SimpleClientProtocol
|
||||||
reactor.connectTCP("localhost", 9000, factory)
|
reactor.connectTCP("localhost", 9000, factory)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import sys
|
|||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.internet.defer import Deferred, returnValue, inlineCallbacks
|
from twisted.internet.defer import Deferred, returnValue, inlineCallbacks
|
||||||
from autobahn.autobahn import AutobahnClientFactory, AutobahnClientProtocol
|
from autobahn.wamp import WampClientFactory, WampClientProtocol
|
||||||
|
|
||||||
|
|
||||||
class SimpleClientProtocol(AutobahnClientProtocol):
|
class SimpleClientProtocol(WampClientProtocol):
|
||||||
"""
|
"""
|
||||||
Demonstrates simple Remote Procedure Calls (RPC) with
|
Demonstrates simple Remote Procedure Calls (RPC) with
|
||||||
Autobahn WebSockets and Twisted Inline Callbacks.
|
Autobahn WebSockets and Twisted Inline Callbacks.
|
||||||
@@ -71,7 +71,7 @@ class SimpleClientProtocol(AutobahnClientProtocol):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
log.startLogging(sys.stdout)
|
log.startLogging(sys.stdout)
|
||||||
factory = AutobahnClientFactory(debug = False)
|
factory = WampClientFactory(debug = False)
|
||||||
factory.protocol = SimpleClientProtocol
|
factory.protocol = SimpleClientProtocol
|
||||||
reactor.connectTCP("localhost", 9000, factory)
|
reactor.connectTCP("localhost", 9000, factory)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
import sys, math
|
import sys, math
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
from autobahn.autobahn import exportRpc, AutobahnServerFactory, AutobahnServerProtocol
|
from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol
|
||||||
|
|
||||||
|
|
||||||
class Calc:
|
class Calc:
|
||||||
@@ -66,7 +66,7 @@ class Calc:
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class SimpleServerProtocol(AutobahnServerProtocol):
|
class SimpleServerProtocol(WampServerProtocol):
|
||||||
"""
|
"""
|
||||||
Demonstrates creating a simple server with Autobahn WebSockets that
|
Demonstrates creating a simple server with Autobahn WebSockets that
|
||||||
responds to RPC calls.
|
responds to RPC calls.
|
||||||
@@ -86,7 +86,7 @@ class SimpleServerProtocol(AutobahnServerProtocol):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
log.startLogging(sys.stdout)
|
log.startLogging(sys.stdout)
|
||||||
factory = AutobahnServerFactory(debug = False)
|
factory = WampServerFactory(debug = False)
|
||||||
factory.protocol = SimpleServerProtocol
|
factory.protocol = SimpleServerProtocol
|
||||||
reactor.listenTCP(9000, factory)
|
reactor.listenTCP(9000, factory)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 213 KiB After Width: | Height: | Size: 213 KiB |
@@ -41,7 +41,7 @@ Contents
|
|||||||
websocketprotocol
|
websocketprotocol
|
||||||
websocketclient
|
websocketclient
|
||||||
websocketserver
|
websocketserver
|
||||||
autobahnprotocol
|
wamp
|
||||||
|
|
||||||
|
|
||||||
Protocol Classes
|
Protocol Classes
|
||||||
@@ -50,8 +50,8 @@ Protocol Classes
|
|||||||
* :class:`autobahn.websocket.WebSocketProtocol`
|
* :class:`autobahn.websocket.WebSocketProtocol`
|
||||||
* :class:`autobahn.websocket.WebSocketClientProtocol`
|
* :class:`autobahn.websocket.WebSocketClientProtocol`
|
||||||
* :class:`autobahn.websocket.WebSocketServerProtocol`
|
* :class:`autobahn.websocket.WebSocketServerProtocol`
|
||||||
* :class:`autobahn.autobahn.AutobahnClientProtocol`
|
* :class:`autobahn.wamp.WampClientProtocol`
|
||||||
* :class:`autobahn.autobahn.AutobahnServerProtocol`
|
* :class:`autobahn.wamp.WampServerProtocol`
|
||||||
|
|
||||||
.. image:: protocolclasses.png
|
.. image:: protocolclasses.png
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@ Factory Classes
|
|||||||
|
|
||||||
* :class:`autobahn.websocket.WebSocketClientFactory`
|
* :class:`autobahn.websocket.WebSocketClientFactory`
|
||||||
* :class:`autobahn.websocket.WebSocketServerFactory`
|
* :class:`autobahn.websocket.WebSocketServerFactory`
|
||||||
* :class:`autobahn.autobahn.AutobahnClientFactory`
|
* :class:`autobahn.wamp.WampClientFactory`
|
||||||
* :class:`autobahn.autobahn.AutobahnServerFactory`
|
* :class:`autobahn.wamp.WampServerFactory`
|
||||||
|
|
||||||
.. image:: factoryclasses.png
|
.. image:: factoryclasses.png
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 199 KiB After Width: | Height: | Size: 197 KiB |
@@ -1,45 +1,45 @@
|
|||||||
Autobahn RPC/PubSub
|
Autobahn WebSockets RPC/PubSub
|
||||||
===================
|
==============================
|
||||||
|
|
||||||
RPC/PubSub Servers
|
RPC/PubSub Servers
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
The classes :class:`autobahn.autobahn.AutobahnServerProtocol` and
|
The classes :class:`autobahn.wamp.WampServerProtocol` and
|
||||||
:class:`autobahn.autobahn.AutobahnServerFactory` are the base classes
|
:class:`autobahn.wamp.WampServerFactory` are the base classes
|
||||||
you derive from to implement Autobahn RPC/PubSub servers.
|
you derive from to implement Autobahn WebSockets RPC/PubSub servers.
|
||||||
|
|
||||||
|
|
||||||
.. autoclass:: autobahn.autobahn.AutobahnServerProtocol
|
.. autoclass:: autobahn.wamp.WampServerProtocol
|
||||||
:members: registerForRpc,
|
:members: registerForRpc,
|
||||||
registerMethodForRpc,
|
registerMethodForRpc,
|
||||||
registerProcedureForRpc
|
registerProcedureForRpc
|
||||||
|
|
||||||
.. autoclass:: autobahn.autobahn.AutobahnServerFactory
|
.. autoclass:: autobahn.wamp.WampServerFactory
|
||||||
|
|
||||||
|
|
||||||
RPC/PubSub Clients
|
RPC/PubSub Clients
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
The classes :class:`autobahn.autobahn.AutobahnClientProtocol` and
|
The classes :class:`autobahn.wamp.WampClientProtocol` and
|
||||||
:class:`autobahn.autobahn.AutobahnClientFactory` are the base classes
|
:class:`autobahn.wamp.WampClientFactory` are the base classes
|
||||||
you derive from to implement Autobahn RPC/PubSub clients.
|
you derive from to implement Autobahn WebSockets RPC/PubSub clients.
|
||||||
|
|
||||||
|
|
||||||
.. autoclass:: autobahn.autobahn.AutobahnClientProtocol
|
.. autoclass:: autobahn.wamp.WampClientProtocol
|
||||||
:members: prefix,
|
:members: prefix,
|
||||||
call,
|
call,
|
||||||
subscribe,
|
subscribe,
|
||||||
unsubscribe,
|
unsubscribe,
|
||||||
publish
|
publish
|
||||||
|
|
||||||
.. autoclass:: autobahn.autobahn.AutobahnClientFactory
|
.. autoclass:: autobahn.wamp.WampClientFactory
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RPC/PubSub Protocol
|
RPC/PubSub Protocol
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
.. autoclass:: autobahn.autobahn.AutobahnProtocol
|
.. autoclass:: autobahn.wamp.WampProtocol
|
||||||
:members: MESSAGE_TYPEID_NULL,
|
:members: MESSAGE_TYPEID_NULL,
|
||||||
MESSAGE_TYPEID_PREFIX,
|
MESSAGE_TYPEID_PREFIX,
|
||||||
MESSAGE_TYPEID_CALL,
|
MESSAGE_TYPEID_CALL,
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import websocket
|
import websocket
|
||||||
import autobahn
|
import wamp
|
||||||
import fuzzing
|
import fuzzing
|
||||||
import case
|
import case
|
||||||
import prefixmap
|
import prefixmap
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ def exportPub(arg, prefixMatch = False):
|
|||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
|
||||||
class AutobahnProtocol:
|
class WampProtocol:
|
||||||
"""
|
"""
|
||||||
Base protocol class for Autobahn RPC/PubSub.
|
Base protocol class for Wamp RPC/PubSub.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
MESSAGE_TYPEID_NULL = 0
|
MESSAGE_TYPEID_NULL = 0
|
||||||
@@ -132,9 +132,9 @@ class AutobahnProtocol:
|
|||||||
|
|
||||||
def _protocolError(self, reason):
|
def _protocolError(self, reason):
|
||||||
if self.debug_autobahn:
|
if self.debug_autobahn:
|
||||||
log.msg("Closing Autobahn session on protocol violation : %s" % reason)
|
log.msg("Closing Wamp session on protocol violation : %s" % reason)
|
||||||
#self.failConnection()
|
#self.failConnection()
|
||||||
self.sendClose(WebSocketProtocol.CLOSE_STATUS_CODE_PROTOCOL_ERROR, "Autobahn RPC/PubSub protocol violation ('%s')" % reason)
|
self.sendClose(WebSocketProtocol.CLOSE_STATUS_CODE_PROTOCOL_ERROR, "Wamp RPC/PubSub protocol violation ('%s')" % reason)
|
||||||
|
|
||||||
|
|
||||||
def shrink(self, uri):
|
def shrink(self, uri):
|
||||||
@@ -173,14 +173,14 @@ class AutobahnProtocol:
|
|||||||
return self.prefixes.resolveOrPass(curieOrUri)
|
return self.prefixes.resolveOrPass(curieOrUri)
|
||||||
|
|
||||||
|
|
||||||
class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
class WampServerProtocol(WebSocketServerProtocol, WampProtocol):
|
||||||
"""
|
"""
|
||||||
Server factory for Autobahn RPC/PubSub.
|
Server factory for Wamp RPC/PubSub.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def connectionMade(self):
|
def connectionMade(self):
|
||||||
WebSocketServerProtocol.connectionMade(self)
|
WebSocketServerProtocol.connectionMade(self)
|
||||||
AutobahnProtocol.connectionMade(self)
|
WampProtocol.connectionMade(self)
|
||||||
|
|
||||||
## RPCs registered in this session (a URI map of (object, procedure)
|
## RPCs registered in this session (a URI map of (object, procedure)
|
||||||
## pairs for object methods or (None, procedure) for free standing procedures)
|
## pairs for object methods or (None, procedure) for free standing procedures)
|
||||||
@@ -198,7 +198,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
|||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
self.factory._unsubscribeClient(self)
|
self.factory._unsubscribeClient(self)
|
||||||
|
|
||||||
AutobahnProtocol.connectionLost(self, reason)
|
WampProtocol.connectionLost(self, reason)
|
||||||
WebSocketServerProtocol.connectionLost(self, reason)
|
WebSocketServerProtocol.connectionLost(self, reason)
|
||||||
|
|
||||||
|
|
||||||
@@ -382,7 +382,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
|||||||
def _sendCallResult(self, result, callid):
|
def _sendCallResult(self, result, callid):
|
||||||
## Internal method for marshaling/sending an RPC success result.
|
## Internal method for marshaling/sending an RPC success result.
|
||||||
|
|
||||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_CALL_RESULT, callid, result]
|
msg = [WampProtocol.MESSAGE_TYPEID_CALL_RESULT, callid, result]
|
||||||
try:
|
try:
|
||||||
o = json.dumps(msg)
|
o = json.dumps(msg)
|
||||||
except:
|
except:
|
||||||
@@ -397,12 +397,12 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
|||||||
eargs = error.value.args
|
eargs = error.value.args
|
||||||
|
|
||||||
if len(eargs) == 0:
|
if len(eargs) == 0:
|
||||||
erroruri = AutobahnProtocol.ERROR_URI_GENERIC
|
erroruri = WampProtocol.ERROR_URI_GENERIC
|
||||||
errordesc = AutobahnProtocol.ERROR_DESC_GENERIC
|
errordesc = WampProtocol.ERROR_DESC_GENERIC
|
||||||
elif len(eargs) == 1:
|
elif len(eargs) == 1:
|
||||||
if type(eargs[0]) not in [str, unicode]:
|
if type(eargs[0]) not in [str, unicode]:
|
||||||
raise Exception("invalid type for exception description")
|
raise Exception("invalid type for exception description")
|
||||||
erroruri = AutobahnProtocol.ERROR_URI_GENERIC
|
erroruri = WampProtocol.ERROR_URI_GENERIC
|
||||||
errordesc = eargs[0]
|
errordesc = eargs[0]
|
||||||
else:
|
else:
|
||||||
if type(eargs[0]) not in [str, unicode]:
|
if type(eargs[0]) not in [str, unicode]:
|
||||||
@@ -412,15 +412,15 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
|||||||
erroruri = eargs[0]
|
erroruri = eargs[0]
|
||||||
errordesc = eargs[1]
|
errordesc = eargs[1]
|
||||||
|
|
||||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_CALL_ERROR, callid, self.prefixes.shrink(erroruri), errordesc]
|
msg = [WampProtocol.MESSAGE_TYPEID_CALL_ERROR, callid, self.prefixes.shrink(erroruri), errordesc]
|
||||||
self.sendMessage(json.dumps(msg))
|
self.sendMessage(json.dumps(msg))
|
||||||
|
|
||||||
|
|
||||||
def onMessage(self, msg, binary):
|
def onMessage(self, msg, binary):
|
||||||
## Internal method handling Autobahn messages received from client.
|
## Internal method handling Wamp messages received from client.
|
||||||
|
|
||||||
if self.debug_autobahn:
|
if self.debug_autobahn:
|
||||||
log.msg("AutobahnServerProtocol message received : %s" % str(msg))
|
log.msg("WampServerProtocol message received : %s" % str(msg))
|
||||||
|
|
||||||
if not binary:
|
if not binary:
|
||||||
try:
|
try:
|
||||||
@@ -429,7 +429,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
|||||||
|
|
||||||
## Call Message
|
## Call Message
|
||||||
##
|
##
|
||||||
if obj[0] == AutobahnProtocol.MESSAGE_TYPEID_CALL:
|
if obj[0] == WampProtocol.MESSAGE_TYPEID_CALL:
|
||||||
callid = obj[1]
|
callid = obj[1]
|
||||||
procuri = self.prefixes.resolveOrPass(obj[2])
|
procuri = self.prefixes.resolveOrPass(obj[2])
|
||||||
arg = obj[3:]
|
arg = obj[3:]
|
||||||
@@ -439,7 +439,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
|||||||
|
|
||||||
## Subscribe Message
|
## Subscribe Message
|
||||||
##
|
##
|
||||||
elif obj[0] == AutobahnProtocol.MESSAGE_TYPEID_SUBSCRIBE:
|
elif obj[0] == WampProtocol.MESSAGE_TYPEID_SUBSCRIBE:
|
||||||
topicuri = self.prefixes.resolveOrPass(obj[1])
|
topicuri = self.prefixes.resolveOrPass(obj[1])
|
||||||
h = self._getSubHandler(topicuri)
|
h = self._getSubHandler(topicuri)
|
||||||
if h:
|
if h:
|
||||||
@@ -476,13 +476,13 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
|||||||
|
|
||||||
## Unsubscribe Message
|
## Unsubscribe Message
|
||||||
##
|
##
|
||||||
elif obj[0] == AutobahnProtocol.MESSAGE_TYPEID_UNSUBSCRIBE:
|
elif obj[0] == WampProtocol.MESSAGE_TYPEID_UNSUBSCRIBE:
|
||||||
topicuri = self.prefixes.resolveOrPass(obj[1])
|
topicuri = self.prefixes.resolveOrPass(obj[1])
|
||||||
self.factory._unsubscribeClient(self, topicuri)
|
self.factory._unsubscribeClient(self, topicuri)
|
||||||
|
|
||||||
## Publish Message
|
## Publish Message
|
||||||
##
|
##
|
||||||
elif obj[0] == AutobahnProtocol.MESSAGE_TYPEID_PUBLISH:
|
elif obj[0] == WampProtocol.MESSAGE_TYPEID_PUBLISH:
|
||||||
topicuri = self.prefixes.resolveOrPass(obj[1])
|
topicuri = self.prefixes.resolveOrPass(obj[1])
|
||||||
h = self._getPubHandler(topicuri)
|
h = self._getPubHandler(topicuri)
|
||||||
if h:
|
if h:
|
||||||
@@ -521,7 +521,7 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
|||||||
|
|
||||||
## Define prefix to be used in CURIEs
|
## Define prefix to be used in CURIEs
|
||||||
##
|
##
|
||||||
elif obj[0] == AutobahnProtocol.MESSAGE_TYPEID_PREFIX:
|
elif obj[0] == WampProtocol.MESSAGE_TYPEID_PREFIX:
|
||||||
prefix = obj[1]
|
prefix = obj[1]
|
||||||
uri = obj[2]
|
uri = obj[2]
|
||||||
self.prefixes.set(prefix, uri)
|
self.prefixes.set(prefix, uri)
|
||||||
@@ -536,12 +536,12 @@ class AutobahnServerProtocol(WebSocketServerProtocol, AutobahnProtocol):
|
|||||||
log.msg("binary message")
|
log.msg("binary message")
|
||||||
|
|
||||||
|
|
||||||
class AutobahnServerFactory(WebSocketServerFactory):
|
class WampServerFactory(WebSocketServerFactory):
|
||||||
"""
|
"""
|
||||||
Server factory for Autobahn RPC/PubSub.
|
Server factory for Wamp RPC/PubSub.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
protocol = AutobahnServerProtocol
|
protocol = WampServerProtocol
|
||||||
|
|
||||||
def __init__(self, debug = False, debug_autobahn = False):
|
def __init__(self, debug = False, debug_autobahn = False):
|
||||||
WebSocketServerFactory.__init__(self, debug = debug)
|
WebSocketServerFactory.__init__(self, debug = debug)
|
||||||
@@ -583,7 +583,7 @@ class AutobahnServerFactory(WebSocketServerFactory):
|
|||||||
|
|
||||||
if self.subscriptions.has_key(topicuri):
|
if self.subscriptions.has_key(topicuri):
|
||||||
if len(self.subscriptions[topicuri]) > 0:
|
if len(self.subscriptions[topicuri]) > 0:
|
||||||
o = [AutobahnProtocol.MESSAGE_TYPEID_EVENT, topicuri, event]
|
o = [WampProtocol.MESSAGE_TYPEID_EVENT, topicuri, event]
|
||||||
try:
|
try:
|
||||||
msg = json.dumps(o)
|
msg = json.dumps(o)
|
||||||
if self.debug_autobahn:
|
if self.debug_autobahn:
|
||||||
@@ -603,35 +603,35 @@ class AutobahnServerFactory(WebSocketServerFactory):
|
|||||||
|
|
||||||
def startFactory(self):
|
def startFactory(self):
|
||||||
if self.debug_autobahn:
|
if self.debug_autobahn:
|
||||||
log.msg("AutobahnServerFactory starting")
|
log.msg("WampServerFactory starting")
|
||||||
self.subscriptions = {}
|
self.subscriptions = {}
|
||||||
|
|
||||||
|
|
||||||
def stopFactory(self):
|
def stopFactory(self):
|
||||||
if self.debug_autobahn:
|
if self.debug_autobahn:
|
||||||
log.msg("AutobahnServerFactory stopped")
|
log.msg("WampServerFactory stopped")
|
||||||
|
|
||||||
|
|
||||||
class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
class WampClientProtocol(WebSocketClientProtocol, WampProtocol):
|
||||||
"""
|
"""
|
||||||
Client protocol for Autobahn RPC/PubSub.
|
Client protocol for Wamp RPC/PubSub.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def connectionMade(self):
|
def connectionMade(self):
|
||||||
WebSocketClientProtocol.connectionMade(self)
|
WebSocketClientProtocol.connectionMade(self)
|
||||||
AutobahnProtocol.connectionMade(self)
|
WampProtocol.connectionMade(self)
|
||||||
|
|
||||||
self.calls = {}
|
self.calls = {}
|
||||||
self.subscriptions = {}
|
self.subscriptions = {}
|
||||||
|
|
||||||
|
|
||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
AutobahnProtocol.connectionLost(self, reason)
|
WampProtocol.connectionLost(self, reason)
|
||||||
WebSocketClientProtocol.connectionLost(self, reason)
|
WebSocketClientProtocol.connectionLost(self, reason)
|
||||||
|
|
||||||
|
|
||||||
def onMessage(self, msg, binary):
|
def onMessage(self, msg, binary):
|
||||||
## Internal method to handle received Autobahn messages.
|
## Internal method to handle received Wamp messages.
|
||||||
|
|
||||||
if binary:
|
if binary:
|
||||||
self._protocolError("binary message received")
|
self._protocolError("binary message received")
|
||||||
@@ -655,10 +655,10 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
|||||||
|
|
||||||
msgtype = obj[0]
|
msgtype = obj[0]
|
||||||
|
|
||||||
if msgtype not in [AutobahnProtocol.MESSAGE_TYPEID_CALL_RESULT, AutobahnProtocol.MESSAGE_TYPEID_CALL_ERROR, AutobahnProtocol.MESSAGE_TYPEID_EVENT]:
|
if msgtype not in [WampProtocol.MESSAGE_TYPEID_CALL_RESULT, WampProtocol.MESSAGE_TYPEID_CALL_ERROR, WampProtocol.MESSAGE_TYPEID_EVENT]:
|
||||||
self._protocolError("invalid message type '%d'" % msgtype)
|
self._protocolError("invalid message type '%d'" % msgtype)
|
||||||
|
|
||||||
if msgtype in [AutobahnProtocol.MESSAGE_TYPEID_CALL_RESULT, AutobahnProtocol.MESSAGE_TYPEID_CALL_ERROR]:
|
if msgtype in [WampProtocol.MESSAGE_TYPEID_CALL_RESULT, WampProtocol.MESSAGE_TYPEID_CALL_ERROR]:
|
||||||
if len(obj) < 2:
|
if len(obj) < 2:
|
||||||
self._protocolError("call result/error message without callid")
|
self._protocolError("call result/error message without callid")
|
||||||
return
|
return
|
||||||
@@ -668,13 +668,13 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
|||||||
callid = str(obj[1])
|
callid = str(obj[1])
|
||||||
d = self.calls.pop(callid, None)
|
d = self.calls.pop(callid, None)
|
||||||
if d:
|
if d:
|
||||||
if msgtype == AutobahnProtocol.MESSAGE_TYPEID_CALL_RESULT:
|
if msgtype == WampProtocol.MESSAGE_TYPEID_CALL_RESULT:
|
||||||
if len(obj) != 3:
|
if len(obj) != 3:
|
||||||
self._protocolError("call result message invalid length")
|
self._protocolError("call result message invalid length")
|
||||||
return
|
return
|
||||||
result = obj[2]
|
result = obj[2]
|
||||||
d.callback(result)
|
d.callback(result)
|
||||||
elif msgtype == AutobahnProtocol.MESSAGE_TYPEID_CALL_ERROR:
|
elif msgtype == WampProtocol.MESSAGE_TYPEID_CALL_ERROR:
|
||||||
if len(obj) != 4:
|
if len(obj) != 4:
|
||||||
self._protocolError("call error message invalid length")
|
self._protocolError("call error message invalid length")
|
||||||
return
|
return
|
||||||
@@ -694,7 +694,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
|||||||
else:
|
else:
|
||||||
if self.debug_autobahn:
|
if self.debug_autobahn:
|
||||||
log.msg("callid not found for received call result/error message")
|
log.msg("callid not found for received call result/error message")
|
||||||
elif msgtype == AutobahnProtocol.MESSAGE_TYPEID_EVENT:
|
elif msgtype == WampProtocol.MESSAGE_TYPEID_EVENT:
|
||||||
if len(obj) != 3:
|
if len(obj) != 3:
|
||||||
self._protocolError("event message invalid length")
|
self._protocolError("event message invalid length")
|
||||||
return
|
return
|
||||||
@@ -733,7 +733,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
|||||||
break
|
break
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
self.calls[callid] = d
|
self.calls[callid] = d
|
||||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_CALL, callid, procuri]
|
msg = [WampProtocol.MESSAGE_TYPEID_CALL, callid, procuri]
|
||||||
msg.extend(args[1:])
|
msg.extend(args[1:])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -767,7 +767,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
|||||||
|
|
||||||
self.prefixes.set(prefix, uri)
|
self.prefixes.set(prefix, uri)
|
||||||
|
|
||||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_PREFIX, prefix, uri]
|
msg = [WampProtocol.MESSAGE_TYPEID_PREFIX, prefix, uri]
|
||||||
|
|
||||||
self.sendMessage(json.dumps(msg))
|
self.sendMessage(json.dumps(msg))
|
||||||
|
|
||||||
@@ -787,7 +787,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
|||||||
if type(topicuri) not in [unicode, str]:
|
if type(topicuri) not in [unicode, str]:
|
||||||
raise Exception("invalid type for URI")
|
raise Exception("invalid type for URI")
|
||||||
|
|
||||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_PUBLISH, topicuri, event]
|
msg = [WampProtocol.MESSAGE_TYPEID_PUBLISH, topicuri, event]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
o = json.dumps(msg)
|
o = json.dumps(msg)
|
||||||
@@ -807,7 +807,7 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
|||||||
"""
|
"""
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
self.subscriptions[self.prefixes.resolveOrPass(topicuri)] = d
|
self.subscriptions[self.prefixes.resolveOrPass(topicuri)] = d
|
||||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_SUBSCRIBE, topicuri]
|
msg = [WampProtocol.MESSAGE_TYPEID_SUBSCRIBE, topicuri]
|
||||||
o = json.dumps(msg)
|
o = json.dumps(msg)
|
||||||
self.sendMessage(o)
|
self.sendMessage(o)
|
||||||
return d
|
return d
|
||||||
@@ -821,18 +821,18 @@ class AutobahnClientProtocol(WebSocketClientProtocol, AutobahnProtocol):
|
|||||||
:type topicuri: str
|
:type topicuri: str
|
||||||
"""
|
"""
|
||||||
del self.subscriptions[topicuri]
|
del self.subscriptions[topicuri]
|
||||||
msg = [AutobahnProtocol.MESSAGE_TYPEID_UNSUBSCRIBE, topicuri]
|
msg = [WampProtocol.MESSAGE_TYPEID_UNSUBSCRIBE, topicuri]
|
||||||
o = json.dumps(msg)
|
o = json.dumps(msg)
|
||||||
self.sendMessage(o)
|
self.sendMessage(o)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class AutobahnClientFactory(WebSocketClientFactory):
|
class WampClientFactory(WebSocketClientFactory):
|
||||||
"""
|
"""
|
||||||
Client factory for Autobahn RPC/PubSub.
|
Client factory for Wamp RPC/PubSub.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
protocol = AutobahnClientProtocol
|
protocol = WampClientProtocol
|
||||||
|
|
||||||
def __init__(self, debug = False, debug_autobahn = False):
|
def __init__(self, debug = False, debug_autobahn = False):
|
||||||
WebSocketClientFactory.__init__(self, debug = debug)
|
WebSocketClientFactory.__init__(self, debug = debug)
|
||||||