本文整理汇总了Python中autobahn.twisted.wamp.ApplicationRunner方法的典型用法代码示例。如果您正苦于以下问题:Python wamp.ApplicationRunner方法的具体用法?Python wamp.ApplicationRunner怎么用?Python wamp.ApplicationRunner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autobahn.twisted.wamp
的用法示例。
在下文中一共展示了wamp.ApplicationRunner方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_runner_no_run
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_runner_no_run(self, fakereactor):
fakereactor.connectTCP = Mock(side_effect=raise_error)
runner = ApplicationRunner(u'ws://fake:1234/ws', u'dummy realm')
try:
yield runner.run(raise_error, start_reactor=False)
self.fail() # should have raise an exception, via Deferred
except RuntimeError as e:
# make sure it's "our" exception
self.assertEqual(e.args[0], "we always fail")
# neither reactor.run() NOR reactor.stop() should have been called
# (just connectTCP() will have been called)
self.assertEqual(fakereactor.run.call_count, 0)
self.assertEqual(fakereactor.stop.call_count, 0)
示例2: test_runner_no_run_happypath
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_runner_no_run_happypath(self, fakereactor):
proto = Mock()
fakereactor.connectTCP = Mock(return_value=succeed(proto))
runner = ApplicationRunner(u'ws://fake:1234/ws', u'dummy realm')
d = runner.run(Mock(), start_reactor=False)
# shouldn't have actually connected to anything
# successfully, and the run() call shouldn't have inserted
# any of its own call/errbacks. (except the cleanup handler)
self.assertFalse(d.called)
self.assertEqual(1, len(d.callbacks))
# neither reactor.run() NOR reactor.stop() should have been called
# (just connectTCP() will have been called)
self.assertEqual(fakereactor.run.call_count, 0)
self.assertEqual(fakereactor.stop.call_count, 0)
示例3: test_runner_proxy
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_runner_proxy(self, fakereactor):
proto = Mock()
fakereactor.connectTCP = Mock(return_value=succeed(proto))
proxy = {'host': u'myproxy', 'port': 3128}
runner = ApplicationRunner(u'ws://fake:1234/ws', u'dummy realm', proxy=proxy)
d = runner.run(Mock(), start_reactor=False)
# shouldn't have actually connected to anything
# successfully, and the run() call shouldn't have inserted
# any of its own call/errbacks. (except the cleanup handler)
self.assertFalse(d.called)
self.assertEqual(1, len(d.callbacks))
# neither reactor.run() NOR reactor.stop() should have been called
# (just connectTCP() will have been called)
self.assertEqual(fakereactor.run.call_count, 0)
self.assertEqual(fakereactor.stop.call_count, 0)
示例4: boot_node
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def boot_node(websocket_uri, debug=False, trace=False):
print 'INFO: Starting node service, connecting to', websocket_uri
# connect to master service
"""
global node_manager
node_manager = NodeManager(websocket_uri, debug=debug)
reactor.callLater(0, node_manager.master_connect)
"""
runner = ApplicationRunner(websocket_uri, u'kotori-realm', debug=trace, debug_wamp=debug, debug_app=debug)
runner.run(KotoriNode, start_reactor=False)
#app = Application()
#app.run(url=websocket_uri, realm='kotori-realm', debug=True, debug_wamp=True, debug_app=True, start_reactor=False)
示例5: make
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def make(self):
# connect to crossbar router/broker
self.runner = ApplicationRunner(self.url, self.realm, extra=dict(self.config))
# run application session
self.deferred = self.runner.run(self.session_class, start_reactor=False)
def croak(ex, *args):
log.error('Problem in {name}, please check if "crossbar" WAMP broker is running. args={args}'.format(
name=self.__class__.__name__, args=args))
log.error("{ex}, args={args!s}", ex=ex.getTraceback(), args=args)
reactor.stop()
raise ex
self.deferred.addErrback(croak)
示例6: handle
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def handle(self, *args, **options):
runner = ApplicationRunner(
conf.WAMP_CONNECTION['URL'],
conf.WAMP_CONNECTION['REALM'],
)
runner.run(AppSession)
示例7: __init__
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def __init__(self):
self.ticker = poloniex.Poloniex().returnTicker()
# self._appRunner = ApplicationRunner(
# u"wss://api.poloniex.com:443", u"realm1"
# )
# self._appProcess, self._tickThread = None, None
# self._running = False
示例8: connect
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def connect(self, wamp_url, reconnect=False, **kwargs):
# NOTE: we would like connect to return immediately if there is an active connection, disconnect and
# connect if the connection url has changed, or reconnect if the connection has dropped
log.msg("CONNECT called: wamp_url={}".format(wamp_url))
self.log_status()
if (wamp_url != self._router_url) or reconnect or self._connection_dead:
yield self.set_connection(None)
if self._ready_to_connect:
self._connected = Deferred() # allocate a new deferred
self._router_url = wamp_url
_wamp_application_runner = ApplicationRunner(url=unicode(self._router_url), realm=unicode(self._realm), headers={"Authorization": "Bearer {}".format(self._token)})
try:
self._wamp_runner = yield _wamp_application_runner.run(build_bridge_class(self), start_reactor=False) # -> returns a deferred
self._wamp_runner.maxMessagePayloadSize = MAX_MESSAGE_PAYLOAD_SIZE
self._wamp_runner.maxFramePayloadSize = MAX_FRAME_PAYLOAD_SIZE
except Exception as e:
self._wamp_event_dispatcher(e)
yield self.set_connection(None)
else:
log.msg("Connecting to router: {}".format(self._router_url))
log.msg(" Project Realm: {}".format(self._realm))
log.msg("after connect called")
self.log_status()
res = yield self._connected # either the new or the old deferred, depending on if we have reconnected or not
returnValue(res)
示例9: test_runner_default
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_runner_default(self, fakereactor):
fakereactor.connectTCP = Mock(side_effect=raise_error)
runner = ApplicationRunner(u'ws://fake:1234/ws', u'dummy realm')
# we should get "our" RuntimeError when we call run
self.assertRaises(RuntimeError, runner.run, raise_error)
# both reactor.run and reactor.stop should have been called
self.assertEqual(fakereactor.run.call_count, 1)
self.assertEqual(fakereactor.stop.call_count, 1)
示例10: test_runner_bad_proxy
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_runner_bad_proxy(self, fakereactor):
proxy = u'myproxy'
self.assertRaises(
AssertionError,
ApplicationRunner,
u'ws://fake:1234/ws', u'dummy realm',
proxy=proxy
)
示例11: test_explicit_SSLContext
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_explicit_SSLContext(self):
'''
Ensure that loop.create_connection is called with the exact SSL
context object that is passed (as ssl) to the __init__ method of
ApplicationRunner.
'''
with replace_loop(Mock()) as loop:
with patch.object(asyncio, 'get_event_loop', return_value=loop):
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
ssl = {}
runner = ApplicationRunner(u'ws://127.0.0.1:8080/ws', u'realm',
ssl=ssl)
runner.run('_unused_')
self.assertIs(ssl, loop.create_connection.call_args[1]['ssl'])
示例12: test_omitted_SSLContext_insecure
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_omitted_SSLContext_insecure(self):
'''
Ensure that loop.create_connection is called with ssl=False
if no ssl argument is passed to the __init__ method of
ApplicationRunner and the websocket URL starts with "ws:".
'''
with replace_loop(Mock()) as loop:
with patch.object(asyncio, 'get_event_loop', return_value=loop):
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
runner = ApplicationRunner(u'ws://127.0.0.1:8080/ws', u'realm')
runner.run('_unused_')
self.assertIs(False, loop.create_connection.call_args[1]['ssl'])
示例13: test_omitted_SSLContext_secure
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_omitted_SSLContext_secure(self):
'''
Ensure that loop.create_connection is called with ssl=True
if no ssl argument is passed to the __init__ method of
ApplicationRunner and the websocket URL starts with "wss:".
'''
with replace_loop(Mock()) as loop:
with patch.object(asyncio, 'get_event_loop', return_value=loop):
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
runner = ApplicationRunner(u'wss://127.0.0.1:8080/wss', u'realm')
runner.run(self.fail)
self.assertIs(True, loop.create_connection.call_args[1]['ssl'])
示例14: test_conflict_SSL_True_with_ws_url
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_conflict_SSL_True_with_ws_url(self):
'''
ApplicationRunner must raise an exception if given an ssl value of True
but only a "ws:" URL.
'''
with replace_loop(Mock()) as loop:
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
runner = ApplicationRunner(u'ws://127.0.0.1:8080/wss', u'realm',
ssl=True)
error = ('^ssl argument value passed to ApplicationRunner '
'conflicts with the "ws:" prefix of the url '
'argument\. Did you mean to use "wss:"\?$')
self._assertRaisesRegex(Exception, error, runner.run, '_unused_')
示例15: test_conflict_SSLContext_with_ws_url
# 需要导入模块: from autobahn.twisted import wamp [as 别名]
# 或者: from autobahn.twisted.wamp import ApplicationRunner [as 别名]
def test_conflict_SSLContext_with_ws_url(self):
'''
ApplicationRunner must raise an exception if given an ssl value that is
an instance of SSLContext, but only a "ws:" URL.
'''
import ssl
try:
# Try to create an SSLContext, to be as rigorous as we can be
# by avoiding making assumptions about the ApplicationRunner
# implementation. If we happen to be on a Python that has no
# SSLContext, we pass ssl=True, which will simply cause this
# test to degenerate to the behavior of
# test_conflict_SSL_True_with_ws_url (above). In fact, at the
# moment (2015-05-10), none of this matters because the
# ApplicationRunner implementation does not check to require
# that its ssl argument is either a bool or an SSLContext. But
# that may change, so we should be careful.
ssl.create_default_context
except AttributeError:
context = True
else:
context = ssl.create_default_context()
with replace_loop(Mock()) as loop:
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
runner = ApplicationRunner(u'ws://127.0.0.1:8080/wss', u'realm',
ssl=context)
error = ('^ssl argument value passed to ApplicationRunner '
'conflicts with the "ws:" prefix of the url '
'argument\. Did you mean to use "wss:"\?$')
self._assertRaisesRegex(Exception, error, runner.run, '_unused_')