def tick(self): #print('--> tick()') if self.script_running and not self.cmd_running: self.next_cmd() self.raise_action('TICK') self.after(self.tick_interval, self.tick) dispatcher.dispatch()
def __init__(self, server_type: str, host: str, port: int, max_connections: int, config: MainConfig): self.rndispatcher = EventDispatcher() self.rnserver = RNServer((host, port), max_connections, b'3.25 ND1', None, self.rndispatcher) self.rndispatcher.add_listener(RNMessage.UserPacket, self.on_user_packet) self.config = config self.type = server_type self.plugins = [] self.handlers = {} self.packets = {} if self.type not in ['auth', 'chat', 'char']: self.repman = ReplicaManager(self.rndispatcher) self.register_plugins('server.core') if self.type in ['auth', 'chat']: self.register_plugins('server.' + self.type) else: self.register_plugins('server.world') if self.type != 'char': self.register_plugins('server.world.zone') log.info(f'{self.type.upper()} - Started up')
class EventLoop: def __init__(self, window): self._event_dispatcher = EventDispatcher(self, window) self._running = False rotate_event = sdl2.SDL_Event() rotate_event.type = EventDispatcher.ROTATE_EVENT self._window = window self._rotate_event_pointer = ctypes.byref(rotate_event) def run(self): self._running = True while self._running: if self._window.can_rotate: sdl2.SDL_PushEvent(self._rotate_event_pointer) self._receive_events() def stop(self): self._running = False def _receive_events(self): event = sdl2.SDL_Event() event_pointer = ctypes.byref(event) while self._running and sdl2.SDL_PollEvent(event_pointer) != 0: self._event_dispatcher.dispatch(event)
def __init__(self, parent, width, height): self.tag = 'draws' self.stats_tag = 'stats' self.path_tag = 'tool_path' self.grid_tag = 'grid' super().__init__( parent) #, width = self.canvas_width, height = self.canvas_height) self.parent = parent self.width = width self.height = height self.bot_width = width self.bot_height = height self.x_scale = 1.0 self.y_scale = 1.0 self._last_tool_p = Point(0.0, 0.0) self._enable_tool = False self.configure(width=self.width, height=self.height, background="white", borderwidth=0) # self.bind('<Button-1>', self.on_click) print(dispatcher) print(type(dispatcher)) dispatcher.add_event('on_click')
def __init__(self, window): self._event_dispatcher = EventDispatcher(self, window) self._running = False rotate_event = sdl2.SDL_Event() rotate_event.type = EventDispatcher.ROTATE_EVENT self._window = window self._rotate_event_pointer = ctypes.byref(rotate_event)
def edXY_on_key_enter(self, event): #print(event) if event.keycode == 13: # "Enter" key pressed try: x = int(self.ed_x.get()) y = int(self.ed_y.get()) except Exception as e: showerror(message='invalid symbols in edit fields for X and Y') return #self.raise_action('MOVE_TO', x, y, self.on_move_done) dispatcher.trigger_event('go_coordinates', x, y, self.on_move_done)
def __init__(self, id, spr, microsteps): #, on_step_func): # stepper self._steps_per_revolution = spr self._microsteps = microsteps self._effective_steps = spr * microsteps self._rads_per_step = (2 * pi) / self._effective_steps # callback self._id = id #self._on_step = on_step_func # internal self._steps_to_move = 0 self._dir_to_move = 0 dispatcher.add_event('step')
def step(self): if self._steps_to_move == 0: #print('id={} no steps to move'.format(self._id)) pass else: # make one step in direction (-1 or +1) self._steps_to_move -= 1 #if self._on_step: # self._on_step(self._id, self._rads_per_step * self._dir_to_move) dispatcher.trigger_event('step', self._id, self._rads_per_step * self._dir_to_move) #print('id={}, s2m={}'.format(self._id, self._steps_to_move)) return self._steps_to_move
class Game: def __init__(self): self.running = False self.event_dispatcher = EventDispatcher() self.graphics = gamegraphics.Graphics(self, self.event_dispatcher) self.map = gamemap.Map() self.player = player.Player(self, self.event_dispatcher) self.ai = ai.AI(self, self.event_dispatcher) def sigint_handler(sig, frame): self.event_dispatcher.add_event("quit", "Ctrl-C") signal.signal(signal.SIGINT, sigint_handler) self.event_dispatcher.register("quit", self.quit) def quit(self, cause=None): logger.info("Stopping game, cause: {}".format(cause)) self.running = False def get_move(self): move = input(">> ") self.event_dispatcher.add_event("movePlayer", move) def run(self): self.running = True self.graphics.setup_sprites() utility.repeat(self.event_dispatcher, "ai_update", 0.1, self.ai.update) while self.running: self.graphics.update() self.event_dispatcher.dispatch()
def __init__(self): self.running = False self.event_dispatcher = EventDispatcher() self.graphics = gamegraphics.Graphics(self, self.event_dispatcher) self.map = gamemap.Map() self.player = player.Player(self, self.event_dispatcher) self.ai = ai.AI(self, self.event_dispatcher) def sigint_handler(sig, frame): self.event_dispatcher.add_event("quit", "Ctrl-C") signal.signal(signal.SIGINT, sigint_handler) self.event_dispatcher.register("quit", self.quit)
async def run(self): ''' shared_market_data = { "taker_fee": exchange_variables["taker_fee"], -> done "CRO_holding_backup": exchange_variables["CRO_holding_backup"], -> done "balance_USDT": 0, -> done "balance_BTC": 0, -> done "balance_CRO": 0, -> done "price_BTC_sell_to_USDT": 0, -> done "price_CRO_buy_for_BTC": 0, -> done "fee_BTC_sell_in_USDT": 0, "price_CRO_buy_for_USDT": 0, -> done "last_CRO_price_in_USDT": 0, -> done "last_CRO_price_in_BTC": 0, -> done "fee_BTC_sell_in_CRO": 0, "price_BTC_buy_for_USDT": 0, -> done "fee_BTC_buy_in_BTC": 0, "fee_BTC_buy_in_CRO": 0, } ''' event_dispatcher = EventDispatcher() event_dispatcher.register_channel_handling_method("user.balance", self.handle_channel_event_user_balance) event_dispatcher.register_response_handling_method("public/get-instruments", self.handle_response_get_instruments) async with CryptoClient( client_type=CryptoClient.USER, debug=self.debug, logger=self.logger, api_key=self.crypto_com_client.crypto_com_api_key, api_secret=self.crypto_com_client.crypto_com_secret_key, channels=[ "user.balance" ] ) as client: periodic_call_get_instruments = PeriodicAsync(5, lambda: self.get_instruments(client)) await periodic_call_get_instruments.start() try: while True: event_or_response = None try: event_or_response = await client.next_event_or_response() event_dispatcher.dispatch(event_or_response) except Exception as e: if event_or_response: message = "Exception during handling user api event or response: {}".format(repr(e)) self.logger.exception(message) self.logger.error("Event or response that failed: {}".format(event_or_response)) else: message = "Exception during parsing user api event or response: {}".format(repr(e)) self.logger.exception(message) # TODO: Send pushover notification here with message continue finally: self.logger.info("Cleanup before closing worker...") await periodic_call_get_instruments.stop()
class EventLoop: def __init__(self, window): self._event_dispatcher = EventDispatcher(self, window) self._running = False def run(self): self._running = True while self._running: self._receive_events() def stop(self): self._running = False def _receive_events(self): event = sdl2.SDL_Event() event_pointer = ctypes.byref(event) while self._running and sdl2.SDL_PollEvent(event_pointer) != 0: self._event_dispatcher.dispatch(event)
def __init__(self, parent, **kwargs): super().__init__( parent) #, width = self.canvas_width, height = self.canvas_height) self.parent = parent self._actions = {} self.tick_interval = kwargs.get('tick_interval', ControlPanel.TICK_INTERVAL) # self.width = width # self.height = height #self.configure(width = self.width, height = self.height) #self.pack() #ipadx = 10, ipady = 10) # self.script_running = False self.cmd_running = False self.program_line = 0 self.program_text_iter = None # create controls self.lb_x = TK.Label(self, text='GO TO X') self.lb_x.grid(row=0, column=0) self.ed_x = TK.Entry(self, width=5) self.ed_x.grid(row=0, column=1) self.lb_y = TK.Label(self, text='Y') self.lb_y.grid(row=0, column=2) self.ed_y = TK.Entry(self, width=5) self.ed_y.grid(row=0, column=3) # text fields self.txt_prog = TK.Text(self, width=20) self.txt_prog.grid(columnspan=4, sticky=TK.W + TK.E + TK.N + TK.S) # button - run self.btn_run = TK.Button(self, text='RUN') self.btn_run.grid(columnspan=4, sticky=TK.W + TK.E + TK.N + TK.S) # button clear self.btn_clear = TK.Button(self, text='CLEAR') self.btn_clear.grid(columnspan=4, sticky=TK.W + TK.E + TK.N + TK.S) # bindings self.ed_y.bind('<Key>', self.edXY_on_key_enter) self.ed_x.bind('<Key>', self.edXY_on_key_enter) self.btn_run.bind('<Button-1>', self.btnRun_on_click) self.btn_clear.bind('<Button-1>', self.btnClear_on_click) # events dispatcher.add_event('go_coordinates') dispatcher.on_click += self.on_mouse1_click # start ticking self.after(self.tick_interval, self.tick)
async def run(self): event_dispatcher = EventDispatcher() event_dispatcher.register_channel_handling_method( "ticker.BTC_USDT", self.handle_channel_event_ticker_BTC_USDT) event_dispatcher.register_channel_handling_method( "ticker.CRO_USDT", self.handle_channel_event_ticker_CRO_USDT) event_dispatcher.register_channel_handling_method( "ticker.CRO_BTC", self.handle_channel_event_ticker_CRO_BTC) async with CryptoClient(client_type=CryptoClient.MARKET, debug=self.debug, logger=self.logger, channels=[ "ticker.BTC_USDT", "ticker.CRO_USDT", "ticker.CRO_BTC", ]) as client: try: while True: event_or_response = None try: event_or_response = await client.next_event_or_response( ) event_dispatcher.dispatch(event_or_response) except Exception as e: if event_or_response: message = "Exception during handling market data event or response: {}".format( repr(e)) self.logger.exception(message) self.logger.error( "Event or response that failed: {}".format( event_or_response)) else: message = "Exception during parsing market data event or response: {}".format( repr(e)) self.logger.exception(message) # TODO: Send pushover notification here with message continue finally: self.logger.info("Cleanup before closing worker...")
class Server: """ Main server class """ def __init__(self, server_type: str, host: str, port: int, max_connections: int, config: MainConfig): self.rndispatcher = EventDispatcher() self.rnserver = RNServer((host, port), max_connections, b'3.25 ND1', None, self.rndispatcher) self.rndispatcher.add_listener(RNMessage.UserPacket, self.on_user_packet) self.config = config self.type = server_type self.plugins = [] self.handlers = {} self.packets = {} if self.type not in ['auth', 'chat', 'char']: self.repman = ReplicaManager(self.rndispatcher) self.register_plugins('server.core') if self.type in ['auth', 'chat']: self.register_plugins('server.' + self.type) else: self.register_plugins('server.world') if self.type != 'char': self.register_plugins('server.world.zone') log.info(f'{self.type.upper()} - Started up') def on_user_packet(self, data, conn): self.handle('rn:user_packet', data, conn) def register_plugins(self, package: str): """ Registers plugins """ new_plugins = [ UserPlugin(self) for UserPlugin in get_derivatives(package, Plugin) ] self.plugins += new_plugins for plugin in new_plugins: for (event, handler, priority) in plugin.actions(): self.handlers.setdefault(event, []).append((handler, priority)) for packet in plugin.packets(): existing = self.packets.get(packet.packet_name) if existing: mod = inspect.getmodule(existing) raise KeyError( f'Multiple packets cannot be registered for the same packet name. {mod} is already registered' ) self.packets[packet.packet_name] = packet for plugin in new_plugins: name = self.type.upper() mod = plugin.__module__ actions = [action.event for action in plugin.actions()] log.debug(f'{name} - Registered plugin: {mod} consuming {actions}') def get_ordered_handlers(self, event): """ Gets ordered handlers """ return sorted(self.handlers.get(event, []), key=lambda handler: handler[1]) def handle(self, event, *args, **kwargs): """ Registers a handler """ handlers = self.get_ordered_handlers(event) results = [] for handler, _ in handlers: results.append(handler(*args, **kwargs)) return results def handle_until_value(self, event, value, *args, value_method='equals', **kwargs): """ Handles something until a value matches """ handlers = self.get_ordered_handlers(event) for handler, _ in handlers: result = handler(*args, **kwargs) if ((value_method == 'equals' and result == value) or (value_method == 'not equals' and result != value) or (value_method == 'in' and result in value) or (value_method == 'not in' and not result in value)): return True return False def handle_until_return(self, event, *args, **kwargs): """ Handles something until a value returns """ handlers = self.get_ordered_handlers(event) for handler, _ in handlers: result = handler(*args, **kwargs) if result is not None: return result return None
def test_dispatch_event_to_listeners_without_any_registered_event_listeners( redis_client): """ GIVEN a StoreAFilesMd5MicroService instance WHEN the 'StoreAFilesMd5MicroService.get_device_id(db, device)' is invoked and given a new device as argument THEN that new device should be stored in the 'device_ids' db collection and the 'device_id_index' from 'globals' db collection should be incremented by 1 """ dispatcher = EventDispatcher() dispatcher.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] dispatcher.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] dispatcher.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] dispatcher.establish_redis_connection() dispatcher.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] dispatcher.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] dispatcher.establish_mongodb_connection() common_lib = dispatcher.get_common_lib_instance() common_lib.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] common_lib.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] common_lib.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] common_lib.establish_redis_connection() common_lib.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] common_lib.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] common_lib.establish_mongodb_connection() result = dispatcher.dispatch_event_to_listeners( "sequence_video_clips-melt_ended_event", "20200503223628.840265", { "return_code": 0, "file_path_name": "/video_clips/output-20200503-090308.mp4", "transaction_id": "20200503174008.553417", }) assert len(result) is 0
def test_dispatch_event_to_listeners_with_a_registered_event_listener_having_a_count_of_2( redis_event_listener_entry_with_a_count_of_2): """ GIVEN a StoreAFilesMd5MicroService instance WHEN the 'StoreAFilesMd5MicroService.get_device_id(db, device)' is invoked and given a new device as argument THEN that new device should be stored in the 'device_ids' db collection and the 'device_id_index' from 'globals' db collection should be incremented by 1 """ event_id = "sequence_video_clips-melt_ended_event" timestamp = "20200503223628.840265" url = 'http://some_url.com/' return_code = 0 transaction_id = "20200503174008.553417" dispatcher = EventDispatcher() dispatcher.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] dispatcher.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] dispatcher.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] dispatcher.establish_redis_connection() dispatcher.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] dispatcher.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] dispatcher.establish_mongodb_connection() common_lib = dispatcher.get_common_lib_instance() common_lib.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] common_lib.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] common_lib.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] common_lib.establish_redis_connection() common_lib.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] common_lib.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] common_lib.establish_mongodb_connection() result = dispatcher.dispatch_event_to_listeners( event_id, timestamp, { "return_code": return_code, "file_path_name": "/video_clips/output-20200503-090308a.mp4", "transaction_id": transaction_id, }) assert len(result) is 1 assert result[0] == (url, { "return_code": return_code, "file_path_name": "/video_clips/output-20200503-090308a.mp4", "transaction_id": transaction_id }, { "count": 1, }) result = dispatcher.dispatch_event_to_listeners( event_id, timestamp, { "return_code": return_code, "file_path_name": "/video_clips/output-20200503-090308b.mp4", "transaction_id": transaction_id, }) assert len(result) is 1 assert result[0] == (url, { "return_code": return_code, "file_path_name": "/video_clips/output-20200503-090308b.mp4", "transaction_id": transaction_id }, { "count": 0, }) result = dispatcher.dispatch_event_to_listeners( event_id, timestamp, { "return_code": 0, "file_path_name": "/video_clips/output-20200503-090308c.mp4", "transaction_id": transaction_id, }) assert len(result) is 0
def test_dispatch_event_to_listeners_with_a_registered_event_listener_having_several_required_data_but_1_that_does_not_exist_in_any_recent_related_events( redis_event_listener_entry_with_several_required_data_but_1_that_does_not_exist_in_any_recent_related_events, standard_db_event_entries): """ GIVEN a StoreAFilesMd5MicroService instance WHEN the 'StoreAFilesMd5MicroService.get_device_id(db, device)' is invoked and given a new device as argument THEN that new device should be stored in the 'device_ids' db collection and the 'device_id_index' from 'globals' db collection should be incremented by 1 """ event_id = "sequence_video_clips-melt_ended_event" return_code = 0 file_path_name = "/video_clips/output-20200503-090308.mp4" transaction_id = "20200503174008.553417" timestamp = "20200503223628.840266" dispatcher = EventDispatcher() dispatcher.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] dispatcher.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] dispatcher.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] dispatcher.establish_redis_connection() dispatcher.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] dispatcher.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] dispatcher.establish_mongodb_connection() common_lib = dispatcher.get_common_lib_instance() common_lib.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] common_lib.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] common_lib.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] common_lib.establish_redis_connection() common_lib.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] common_lib.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] common_lib.establish_mongodb_connection() result = dispatcher.dispatch_event_to_listeners( event_id, timestamp, { "return_code": return_code, "file_path_name": file_path_name, "transaction_id": transaction_id, }) assert len(result) is 0
def test_dispatch_event_to_listeners_with_a_registered_event_listener_that_is_offline( mocker, standard_redis_event_listener_entry): """ GIVEN a StoreAFilesMd5MicroService instance WHEN the 'StoreAFilesMd5MicroService.get_device_id(db, device)' is invoked and given a new device as argument THEN that new device should be stored in the 'device_ids' db collection and the 'device_id_index' from 'globals' db collection should be incremented by 1 """ timestamp = "20200503223628.840265" return_code = 0 file_path_name = "/video_clips/output-20200503-090308.mp4" transaction_id = "20200503174008.553417" event_id = 'sequence_video_clips-melt_ended_event' url = "http://some_url.com/" priority = 100 event_data = { "return_code": return_code, "file_path_name": file_path_name, "transaction_id": transaction_id, } expected_listener_attributes = { "url": url, "datetime_start": timestamp, "event_id": event_id, } dispatcher = EventDispatcher() dispatcher.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] dispatcher.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] dispatcher.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] redis_client = dispatcher.establish_redis_connection() dispatcher.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] dispatcher.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] dispatcher.establish_mongodb_connection() common_lib = dispatcher.get_common_lib_instance() common_lib.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] common_lib.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] common_lib.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] common_lib.establish_redis_connection() common_lib.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] common_lib.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] common_lib.establish_mongodb_connection() send_event_to_listener = mocker.patch.object(common_lib, 'send_event_to_listener') send_event_to_listener.return_value = False dispatcher.CONFIG['MOCKED'] = True result = dispatcher.dispatch_event_to_listeners(event_id, timestamp, event_data) dispatcher.CONFIG['MOCKED'] = False assert len(result) is 1 assert result[0] == (url, event_data, {}) send_event_to_listener.assert_called_with(url, event_data) assert redis_client.zcard(sorted_set_retro_event_listeners) == 1 assert redis_client.zrange( sorted_set_retro_event_listeners, 0, -1, withscores=True)[0] == ( url.encode('UTF-8'), # b'http://some_url.com/' priority) listener_attributes = json.loads( redis_client.hmget(hash_retro_event_listeners, url)[0].decode('UTF-8')) assert listener_attributes is not None assert listener_attributes == expected_listener_attributes
def test_dispatch_event_to_listeners_with_a_registered_event_listener_having_several_required_data_that_exists_in_recent_related_events( redis_event_listener_entry_with_several_required_data_that_exists_in_recent_related_events, standard_db_event_entries): """ GIVEN a StoreAFilesMd5MicroService instance WHEN the 'StoreAFilesMd5MicroService.get_device_id(db, device)' is invoked and given a new device as argument THEN that new device should be stored in the 'device_ids' db collection and the 'device_id_index' from 'globals' db collection should be incremented by 1 """ event_id = "sequence_video_clips-melt_ended_event" return_code = 0 file_path_name = "/video_clips/output-20200503-090308.mp4" transaction_id = "20200503174008.553417" url = 'http://some_url.com/' timestamp = "20200503223628.840266" required_data = [ "clips", "video_clips", "converted_video_clips", "sequenced_video_clips", "file_size" ] dispatcher = EventDispatcher() dispatcher.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] dispatcher.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] dispatcher.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] dispatcher.establish_redis_connection() dispatcher.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] dispatcher.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] dispatcher.establish_mongodb_connection() common_lib = dispatcher.get_common_lib_instance() common_lib.CONFIG['TESTING'] = conftest.CONFIG['TESTING'] common_lib.CONFIG['REDIS_HOST'] = conftest.CONFIG['REDIS_HOST'] common_lib.CONFIG['REDIS_DB'] = conftest.CONFIG['REDIS_DB'] common_lib.establish_redis_connection() common_lib.CONFIG['MONGODB_HOST'] = conftest.CONFIG['MONGODB_HOST'] common_lib.CONFIG['MONGODB_DB'] = conftest.CONFIG['MONGODB_DB'] common_lib.establish_mongodb_connection() result = dispatcher.dispatch_event_to_listeners( event_id, timestamp, { "return_code": return_code, "file_path_name": file_path_name, "transaction_id": transaction_id, }) assert len(result) is 1 assert result[0] == (url, { "return_code": return_code, "file_path_name": file_path_name, "transaction_id": transaction_id, 'clips': [{ 'clip_url': 'https://www.twitch.tv/ytmagma/clip/ShyFantasticPterodactylPogChamp', 'clip_title_text': 'im not gay', 'clip_player_name': 'YTMagMa', 'clip_player_url': 'https://www.twitch.tv/ytmagma', 'clip_image_url': 'https://clips-media-assets2.twitch.tv/AT-cm%7C766375085-preview-260x147.jpg', 'clip_duration': 12, 'clip_view_count': 3000, 'clip_hours_ago': '1 hour ago' }, { 'clip_url': 'https://www.twitch.tv/benjyfishy/clip/KawaiiDreamyKangarooThisIsSparta', 'clip_title_text': 'Benjy Music Timing', 'clip_player_name': 'benjyfishy', 'clip_player_url': 'https://www.twitch.tv/benjyfishy', 'clip_image_url': 'https://clips-media-assets2.twitch.tv/AT-cm%7C765635143-preview-260x147.jpg', 'clip_duration': 7, 'clip_view_count': 2400, 'clip_hours_ago': '15 hours ago' }], 'video_clips': { 'https://www.twitch.tv/benjyfishy/clip/KawaiiDreamyKangarooThisIsSparta': { 'file_path_name': '/video_clips/Benjy Music Timing.mp4', 'return_code': 0, 'std_errors': [], 'std_outputs': [] }, 'https://www.twitch.tv/ytmagma/clip/ShyFantasticPterodactylPogChamp': { 'file_path_name': '/video_clips/im not gay.mp4', 'return_code': 0, 'std_errors': [], 'std_outputs': [] } }, 'converted_video_clips': { 'https://www.twitch.tv/benjyfishy/clip/KawaiiDreamyKangarooThisIsSparta': { 'file_path_name': '/video_clips/Benjy Music Timing.Vimeo_YouTube_HQ_1080p60.mp4', 'return_code': 0, 'std_errors': [], 'std_outputs': [] }, 'https://www.twitch.tv/ytmagma/clip/ShyFantasticPterodactylPogChamp': { 'file_path_name': '/video_clips/im not gay.Vimeo_YouTube_HQ_1080p60.mp4', 'return_code': 0, 'std_errors': [], 'std_outputs': [] } }, 'sequenced_video_clips': { 'file_path_name': '/video_clips/output-20200628-084301.mp4', 'return_code': 0, 'std_errors': [], 'std_outputs': [], 'timecodes': { 'https://www.twitch.tv/benjyfishy/clip/KawaiiDreamyKangarooThisIsSparta': 12, 'https://www.twitch.tv/ytmagma/clip/ShyFantasticPterodactylPogChamp': 0 } }, "file_size": 68, }, { "required_data": required_data, })
import tornado.platform.kqueue else: import tornado.platform.select except ImportError: pass import tornado.process import tornado.ioloop import tornado.web import tornado.websocket import tornado.httpserver # Tornado server instance httpserver = None logger = logging.getLogger('livestyle') dispatcher = EventDispatcher() clients = set() # all connected clients patchers = set() # clients identified as 'patcher' editors = dict() # clients identified as 'editor' class MainHandler(tornado.web.RequestHandler): def get(self): self.render('index.html') class WebsocketHandler(tornado.websocket.WebSocketHandler): def open(self): dispatcher.emit('open', self) send(clients, message('client-connect'), self)
def main(): dispatcher = EventDispatcher() ninterface = NetworkInterface(dispatcher, -1, -1, "", 8888, "") login_app = LoginApp(dispatcher, ninterface, 1, 1) login_app.run()
def on_click(self, event): print(event) dispatcher.trigger_event('on_click', x=event.x, y=event.y)
def __init__(self, window): self._event_dispatcher = EventDispatcher(self, window) self._running = False