本文整理汇总了Python中event.Event类的典型用法代码示例。如果您正苦于以下问题:Python Event类的具体用法?Python Event怎么用?Python Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
def init():
commands = {
'product.add': {'handler': Product.productAddCmd, 'args':2, 'help':'productAdd sku stock'},
'product.info': {'handler': Product.productInfoCmd, 'args':1, 'help':'productInfo sku'},
'reservation.add': {'handler': Product.reservationAddCmd, 'args':3, 'help':'reservationAdd client_id sku qty'},
'reservation.del': {'handler': Product.reservationDelCmd, 'args':3, 'help':'reservationDel client_id sku qty'},
'reservation.set': {'handler': Product.reservationSetCmd, 'args':3, 'help':'reservationSet client_id sku qty'},
'stock.set': {'handler': Product.stockSetCmd, 'args':2, 'help':'stockSet sku stock'},
'stock.dec': {'handler': Product.stockDecCmd, 'args':2, 'help':'stockDec sku qty'},
'stock.get': {'handler': Product.stockGetCmd, 'args':1, 'help':'stockGet sku'},
'product.total': {'handler': Product.totalCmd, 'args':0, 'help':'status'}
}
for c in commands:
Command.register(
commands[c]['handler'],
c,
commands[c]['args'],
commands[c]['help']
)
Event.register('db.save', Product.saveDb)
Event.register('db.load', Product.loadDb)
示例2: __init__
def __init__(self, url, app_key, app_secret, group_name='default', query_message_interval=50, heartbeat_interval=30,
sdk_version='top-sdk-java-201403304', *args, **kwargs):
super(TmcClient, self).__init__(url, *args, **kwargs)
Event.__init__(self)
self.on('on_init', lambda: logger.info('WebSocket Start Connect: %[email protected]%s' % (url, group_name)))
assert isinstance(url, (str, unicode)) and len(url) > 0
assert isinstance(app_key, (str, unicode)) and len(app_key) > 0
assert isinstance(app_secret, (str, unicode)) and len(app_secret) > 0
assert isinstance(group_name, (str, unicode)) and len(group_name) > 0
assert isinstance(query_message_interval, int) and 0 < query_message_interval < 60
assert isinstance(heartbeat_interval, int) and 0 < heartbeat_interval < 60
self.sdk_version = sdk_version
self.url = url
self.app_secret = app_secret
self.app_key = app_key
self.group_name = group_name
self.query_message_interval = query_message_interval
self.heartbeat_interval = heartbeat_interval
self.token = None
self.fire('on_init')
self.on('on_handshake_success', self._start_query_loop)
self.on('on_confirm_message', self._on_confirm_message)
示例3: test_a_listener_is_notified_when_an_event_is_raised
def test_a_listener_is_notified_when_an_event_is_raised(self):
""""""
listener = Mock()
event = Event()
event.connect(listener)
event.fire()
self.assertTrue(listener.called)
示例4: post_init
def post_init(self):
"""
Because of the way this module works we have to make sure to set our
event like we normally would with __.tell__, but we cannot define our
event with "^\.tell" like we normally would as it will only look for that
line to trigger the event and the user being told will never receive his message
since the bot is only looking for .tell and not the user in the PRIVMSG
We will set the .tell trigger in our handle function "if event.msg.startswith(".tell"):"
and set define to PRIVMSG so it searches all lines from users. While simultaneously looking
for the .tell trigger from the user.
This is because we actually need 2 things for this module to work.
1.) The user needs to be able to leave a message for someone else using ".tell someuser <Insert message here>"
2.) The user who the .tell message is directed towards will be determined by the PRIVMSG definition.
This is determined in the "else" block that searches every line not starting with .tell.
If the user matches the stored user from the previous tell trigger, the event will be triggered and pybot will spit out text into
the proper channel every time the intended user says something in chat until the buffer is out of .tell events.
"""
tell = Event("__.tell__")
tell.define("PRIVMSG")
tell.subscribe(self)
# register ourself to our new custom event
self.bot.register_event(tell, self)
示例5: join
def join(self):
try:
stdout, stderr, returncode = SubProcessTask.join(self)
event = Event()
event.service = self.name
event.ttl = self.ttl * self.ttl_multiplier
event.host = self.host
event.tags = self.tags
event.attributes = self.attributes
output, attributes = self.parse_nagios_output(stdout)
event.description = "Note: %s\nCommand: %s\nOutput: %s\n" % (self.note, self.raw_command, output)
if returncode in self.exitcodes:
event.state = self.exitcodes[returncode]
else:
event.state = 'unknown'
if attributes:
if 'metric' in self.config and self.config['metric'] in attributes:
metric_key = self.config['metric']
else:
metric_key = attributes.keys()[0]
event.attributes.update(attributes)
event.metric = float(NUMERIC_REGEX.match(attributes[metric_key]).group(1))
self.events.append(event)
except Exception as e:
log.error("Exception joining task '%s':\n%s" % (self.name, str(e)))
示例6: post_init
def post_init(self):
kanbo = Event("__.custom__")
kanbo.define(msg_definition="^\.kanbo")
kanbo.subscribe(self)
self.help = ".kanbo (kanbo face)"
self.bot.register_event(kanbo, self)
self.messages = [u'( ͡° ͜ʖ ͡°)', u'( ͡0 ͜ʖ ͡0)', u'|╲/( ͡° ͡° ͜ʖ ͡° ͡°)/\╱\\', u'┬┴┬┴┤( ͡° ͜ʖ├┬┴┬┴']
示例7: deploy_event
def deploy_event(self, extend_eventtype=None, event=None, **kwargs):
eventtype = self._importname if not extend_eventtype else self._importname + extend_eventtype
if not event:
event = Event(self, eventtype, **kwargs)
else:
event.eventtype = eventtype
self._eventhandler.deploy_event(event)
示例8: post_init
def post_init(self):
youtube = Event("__.youtubes__")
youtube.define(msg_definition="youtube\.com[\S]+")
youtube2 = Event("__.youtubeshort__")
youtube2.define(msg_definition="(?<!=)youtu\.be[\S]+")
youtube.subscribe(self)
youtube2.subscribe(self)
self.bot.register_event(youtube, self)
self.bot.register_event(youtube2, self)
self.bot.mem_store['youtube'] = OrderedDict()
# for the new v3 google api >:(
try:
from youtube_credentials import YoutubeCredentials as yc
except ImportError:
print "Warning: youtube module requires credentials in modules/youtube_credentials.py"
class PhonyYc:
api_key = "None"
yc = PhonyYc()
self.api_key = yc.api_key
self.api_url = "https://www.googleapis.com/youtube/v3/videos?id="
示例9: main
def main():
frame_duration = 1.0/60.0
for level in LEVELS:
load_level(level)
while not Player.main.at_exit():
frame_start_time = time.time()
key = Drawable._window.checkKey()
if key in KEYMAP:
eval(KEYMAP[key])
Event.update()
if not Config.hidden_flag:
if Gold.all_taken():
HiddenLadder.showAll()
Player.main.redraw()
for baddie in Baddie.baddies:
baddie.redraw()
Config.hidden_flag = True
# baddies should probably move here
frame_time = time.time() - frame_start_time
if frame_time < frame_duration:
time.sleep(frame_duration - frame_time)
Drawable.won()
示例10: __init__
class World:
def __init__(self):
self.connections = []
self.connection_added = Event()
self.channel_opened = Event()
def get_connections(self):
ret = []
for c in self.connections:
ret.append(c)
return ret
def remove_connection(self, connection):
if connection.is_connected:
raise "I don't think so, tim"
self.connections.remove(connection)
def new_connection(self):
conn = Connection()
self.connections.append(conn)
conn.channel_opened += self.handle_channel_opened
self.connection_added.fire(self, conn)
return conn
def shut_it_down(self):
for c in self.connections:
c.shut_it_down()
def handle_channel_opened(self, channel):
self.channel_opened.fire(self, channel)
示例11: _start_sending
def _start_sending(self):
_logger.debug('%s, _start_sending', str(self))
if self._close_ev is not None:
return
if not Event.isEventSet(self._wev):
_logger.debug('%s, _start_sending::addEvent', str(self))
Event.addEvent(self._wev)
示例12: test_Event_SubscribeAndFireWithDupplicateKeyword_RaisesException
def test_Event_SubscribeAndFireWithDupplicateKeyword_RaisesException(self):
mockListener = mock.Mock()
event = Event()
event.subscribe(mockListener, kword1="value1")
with self.assertRaises(DuplicateKeywordArgument):
event.fire(kword1="value2")
示例13: notify
def notify(self, **attrs):
e = Event()
e.source = self
for k, v in attrs.iteritems():
setattr(e, k, v)
for fn in self.callbacks:
fn(e)
示例14: __init__
def __init__(self, bot, raw):
Event.__init__(self, bot, raw)
if not self.is_a(*UPDATE_EVENTS):
self.channel = models.Channel(self.raw["channel"])
else:
self.channel = bot.get_channel(self.raw["channel"])
示例15: get
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
asa_number_str = self.request.get('asa_number')
if asa_number_str == '':
self.response.out.write( "Missing asa_number" )
self.response.set_status( 400 )
return
stroke_code_str = self.request.get('stroke_code')
if stroke_code_str == '':
# If there's no stroke code, then we assume that we want the entire swim history
swimlist = SwimList.get( int(asa_number_str) )
if swimlist is not None:
self.response.out.write( str( swimlist ) )
else:
distance_str = self.request.get('distance')
if distance_str == '':
self.response.out.write( "Missing distance" )
self.response.set_status( 400 )
return
asa_number = int(asa_number_str)
stroke_code = int(stroke_code_str)
distance = int(distance_str)
swims = Swim.fetch_all( asa_number, Event.create( stroke_code, distance, "S" ) )
swims.extend( Swim.fetch_all( asa_number, Event.create( stroke_code, distance, "L" ) ) )
swims.extend( UnofficialSwim.fetch_all( asa_number, Event.create( stroke_code, distance, "S" ) ) )
swims.extend( UnofficialSwim.fetch_all( asa_number, Event.create( stroke_code, distance, "L" ) ) )
for swim in swims:
self.response.out.write( str( swim ) + "\n" )