本文整理汇总了Python中neubot.notify.NOTIFIER.publish方法的典型用法代码示例。如果您正苦于以下问题:Python NOTIFIER.publish方法的具体用法?Python NOTIFIER.publish怎么用?Python NOTIFIER.publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.notify.NOTIFIER
的用法示例。
在下文中一共展示了NOTIFIER.publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_queue
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def run_queue(self):
''' If possible run the first test in queue '''
# Adapted from neubot/rendezvous/client.py
if not self.queue:
return
if self.running:
return
#
# Subscribe BEFORE starting the test, otherwise we
# may miss the 'testdone' event if the connection
# to the negotiator service fails, and we will stay
# stuck forever.
#
NOTIFIER.subscribe('testdone', self.test_done)
# Prevent concurrent tests
self.running = True
# Safely run first element in queue
try:
self._do_run_queue()
except (SystemExit, KeyboardInterrupt):
raise
except:
exc = asyncore.compact_traceback()
error = str(exc)
LOG.error('runner_core: catched exception: %s' % error)
NOTIFIER.publish('testdone')
示例2: handle_connection_lost
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def handle_connection_lost(stream):
''' Invoked when the connection is lost '''
final_state = 0
context = stream.opaque
if context:
extra = context.extra
if extra:
final_state = extra['final_state']
if not final_state:
logging.warning('skype_negotiate: not reached final state')
NOTIFIER.publish('testdone') # Tell the runner we're done
示例3: test_bittorrent_invokation_good
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def test_bittorrent_invokation_good(self):
''' Verify run_queue() behavior when bittorrent is invoked
and there is a URI for bittorrent '''
#
# The whole point of this test is to make sure that
# bittorrent.run() is invoked when privacy is OK and
# we have a negotiate URI. We also want to check that
# the "testdone" event is subscribed after run_queue(),
# i.e. that someone is waiting for the event that
# signals the end of the test.
#
# We need to ensure bittorrent.run() is invoked
bittorrent_run = [0]
def on_bittorrent_run(poller, conf):
''' Register bittorrent.run() invokation '''
# pylint: disable=W0613
bittorrent_run[0] += 1
# Setup (we will restore that later)
saved_run = bittorrent.run
bittorrent.run = on_bittorrent_run
RUNNER_TESTS.update({'bittorrent': '/'})
CONFIG.conf['privacy.can_publish'] = 1
CONFIG.conf['privacy.informed'] = 1
CONFIG.conf['privacy.can_collect'] = 1
core = RunnerCore()
core.queue.append(('bittorrent', Deferred(), None))
core.run_queue()
# Restore
bittorrent.run = saved_run
RUNNER_TESTS.update({})
# Worked as expected?
self.assertTrue(bittorrent_run[0])
self.assertTrue(NOTIFIER.is_subscribed("testdone"))
#
# Clear the "testdone" because otherwise it will
# screw up other tests and we don't want that
#
NOTIFIER.publish("testdone")
示例4: run_queue
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def run_queue(self):
''' If possible run the first test in queue '''
# Adapted from neubot/rendezvous/client.py
if not self.queue:
return
if self.running:
return
#
# Subscribe BEFORE starting the test, otherwise we
# may miss the 'testdone' event if the connection
# to the negotiator service fails, and we will stay
# stuck forever.
#
NOTIFIER.subscribe('testdone', self.test_done)
# Prevent concurrent tests
self.running = True
# Make a copy of current settings
conf = CONFIG.copy()
# Make sure we abide to M-Lab policy
if privacy.count_valid(conf, 'privacy.') != 3:
privacy.complain()
NOTIFIER.publish('testdone')
# Run speedtest
elif self.queue[0][0] == 'speedtest':
conf['speedtest.client.uri'] = self.queue[0][1]
client = ClientSpeedtest(POLLER)
client.configure(conf)
client.connect_uri()
# Run bittorrent
elif self.queue[0][0] == 'bittorrent':
conf['bittorrent._uri'] = self.queue[0][1]
bittorrent.run(POLLER, conf)
# Safety net
else:
LOG.error('Asked to run an unknown test')
NOTIFIER.publish('testdone')
示例5: connection_lost
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def connection_lost(self, stream):
logging.info("dash: negotiate connection closed: test done")
NOTIFIER.publish("testdone")
self.client = None
self.stream = None
示例6: connection_lost
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def connection_lost(self, stream):
''' Invoked when the connection is closed or lost '''
NOTIFIER.publish('testdone')
示例7: connection_failed
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def connection_failed(self, connector, exception):
''' Invoked when the connection fails '''
STATE.update('rendezvous', {'status': 'failed'})
NOTIFIER.publish('testdone')
logging.error('runner_rendezvous: connection failed: %s', exception)
示例8: handle_connection_lost
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def handle_connection_lost(stream):
''' Invoked when the connection is lost '''
logging.info('runner_mlabns: server discovery... complete')
NOTIFIER.publish('testdone') # Tell the runner we're done
示例9: handle_connect_error
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def handle_connect_error(self, connector):
logging.info('runner_mlabns: server discovery... connect() failed')
NOTIFIER.publish('testdone') # Tell the runner we're done
示例10: connection_lost
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def connection_lost(self, stream):
TRACKER.unregister_connection(stream)
NOTIFIER.publish(RENEGOTIATE)
示例11: connection_failed
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def connection_failed(self, connector, exception):
""" Invoked when the connection fails """
logging.error("runner_dload: connection failed: %s", exception)
self.ctx["result"] = (-1, None, exception)
NOTIFIER.publish("testdone")
示例12: connection_failed
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def connection_failed(self, connector, exception):
uri = "http://%s/" % self.host_header
logging.info("BitTorrent: connecting to %s ... failure (error: %s)",
uri, str(exception))
NOTIFIER.publish(TESTDONE)
示例13: got_response
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def got_response(self, stream, request, response):
if response.code != "200":
LOG.complete("bad response")
self._schedule()
else:
LOG.complete()
s = response.body.read()
try:
m1 = marshal.unmarshal_object(s, "application/json",
compat.RendezvousResponse)
except ValueError:
LOG.exception()
self._schedule()
else:
if "version" in m1.update and "uri" in m1.update:
ver, uri = m1.update["version"], m1.update["uri"]
LOG.info("Version %s available at %s" % (ver, uri))
STATE.update("update", {"version": ver, "uri": uri})
#
# Choose the test we would like to run even if
# we're not going to run it because we're running
# in debug mode or tests are disabled.
# This allows us to print to the logger the test
# we /would/ have choosen if we were allowed to run
# it.
#
tests = []
if "speedtest" in m1.available:
tests.append("speedtest")
if "bittorrent" in m1.available:
tests.append("bittorrent")
#XXX alternate the two tests
if self._latest:
tests.remove(self._latest)
test = random.choice(tests)
self._latest = test
LOG.info("* Chosen test: %s" % test)
# Are we allowed to run a test?
if not CONFIG["enabled"] or CONFIG["rendezvous.client.debug"]:
LOG.info("Tests are disabled... not running")
self._schedule()
else:
if (CONFIG["privacy.informed"] and
not CONFIG["privacy.can_collect"]):
LOG.warning("cannot run test without permission "
"to save the results")
self._schedule()
else:
conf = self.conf.copy()
#
# Subscribe _before_ connecting. This way we
# immediately see "testdone" if the connection fails
# and we can _schedule the next attempt.
#
NOTIFIER.subscribe("testdone", lambda *a, **kw: \
self._schedule())
if test == "speedtest":
conf["speedtest.client.uri"] = m1.available[
"speedtest"][0]
client = ClientSpeedtest(POLLER)
client.configure(conf)
client.connect_uri()
elif test == "bittorrent":
conf["bittorrent._uri"] = m1.available[
"bittorrent"][0]
bittorrent.run(POLLER, conf)
else:
NOTIFIER.publish("testdone")
示例14: handle_connect_error
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def handle_connect_error(self, connector):
logging.warning('skype_negotiate: connect() failed')
NOTIFIER.publish('testdone')
示例15: connection_failed
# 需要导入模块: from neubot.notify import NOTIFIER [as 别名]
# 或者: from neubot.notify.NOTIFIER import publish [as 别名]
def connection_failed(self, connector, exception):
LOG.complete("failure (error: %s)" % str(exception))
NOTIFIER.publish(TESTDONE)