def __init__(self, translator): self.on_dht = Event('Protocol.on_dht') self.on_dht_ping = Event('Protocol.on_dht_ping') self.on_net_ping = Event('Protocol.on_net_ping') self.proto = None self.set_proto(translator) self.messages = self.get_messages(self.proto)
def __init__(self, own_hash, K, A): self.K = K self.A = A self._own_hash = own_hash self._shortlists = {} # {hash : shortlist} self._task_queue = Queue() self.on_search = Event('Shortlists.on_search') self.on_full_or_found = Event('Shortlists.on_full_or_found') self._watcher_thread = Thread(target=self._watcher) self._watcher_thread.daemon = True self._watcher_thread.start()
def __init__(self, msg_name, *, mode='', is_pongable=False, is_pong=False, pong_msg=None, tags=None, submessages=None, dht_func=None): """ :param msg_name: The name for this message. :type msg_name: str. :param mode: The protobol mode for children of this message. :type mode: str. :param is_pongable: If this message is is_pongable. :type is_pongable: bool. :param is_pong: If this message is a pong type. :type is_pong: bool. :param pong_msg: Name of the pong msg to use. :type pong_msg: str. :param tags: Tags to use to translate. :type tags: [:class:`net.tag.Tag`] :param submessages: Messages to fill the remaining data space. :type submessages: {int : :class:`~net.message.Message`} """ # msg_name mode # T T Fail - bad # T F use msg name # F T used mode name # F F Fail - bad if (len(msg_name + mode) > 0) and\ (len(msg_name) == 0 or len(mode) == 0): self.msg_name = msg_name + mode else: raise ValueError("A msg_name or mode must be provided") self.is_pongable = is_pongable self.is_pong = is_pong self._pong_msg = pong_msg self.tags = [] if tags is None else tags self.submessages = {} if submessages is None else submessages # Init params for submessages self.set_child_attrs(mode) # Set all events self.on_dht = Event('Message.on_dht') if dht_func is not None: self.on_dht += dht_func self.on_data = Event('Message.on_data')
def __init__(self, address): self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._sock.connect(address.tuple) self._thread = threading.Thread(target=self.handler) self._thread.daemon = True self._thread.start() self.on_data = Event()
def __init__(self, port, conn_limit, blocking=False): self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, conn_limit) self._sock.bind(('', port)) self._sock.listen(conn_limit) self._clients = {} self.on_data = Event('tcp.server.on_data') self.on_cleanup = Event('tcp.server.on_cleanup') if blocking: self.listen() else: self._thread = threading.Thread(target=self.listen) self._thread.daemon = True self._thread.start()
def test_data_transformation(): binary = "../src/python-data-processor" emitted_datapoints, emitted_events = invoke_data_processor( binary, {}, [ DatapointValue("temp", "2014-01-01T10:23:00+0100", "1", "Float"), DatapointValue("pressure", "2014-01-01T10:23:05+0100", "5.0", "Float"), Event("pressure-high", "2014-01-01T10:23:05+0100", True, "Pressure is high") ]) assert len(emitted_datapoints) == 2 assert emitted_datapoints[0].datapoint_key == "temp" assert emitted_datapoints[0].timestamp == "2014-01-01T10:23:00+0100" assert emitted_datapoints[0].value == "42.0" assert emitted_datapoints[0].data_type == "Float" assert emitted_datapoints[1].datapoint_key == "pressure" assert emitted_datapoints[1].timestamp == "2014-01-01T10:23:05+0100" assert emitted_datapoints[1].value == "42.0" assert emitted_datapoints[1].data_type == "Float" assert len(emitted_events) == 1 assert emitted_events[0].datapoint_key == "pressure-high" assert emitted_events[0].timestamp == "2014-01-01T10:23:05+0100" assert emitted_events[0].come is True assert emitted_events[0].text == "Pressure is high" assert emitted_events[0].priority == 100
def __init__(self, port): self.on_data = Event('udp.server.on_data') self._bind_address = ('', port) self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._sock.bind(self._bind_address) self._listener_thread = Thread(target=self.listen) self._listener_thread.daemon = True self._listener_thread.start()
def on_lock_change(self, msg): assert isinstance(msg, CrossLock) if msg.type == CrossLock().REQUEST_LOCK: data = { "current_id": "lane_" + str(msg.lane_id), "next_id": "cross_" + str(msg.cross_id) } # print("[switch.py] now request lock from cloud", data) self._event_bus.put(Event(EventType.Request_CrossLockEvent, data), block=True) elif msg.type == CrossLock().RELEASE_LOCK: data = { "current_id": "cross_" + str(msg.cross_id), "next_id": "lane_" + str(msg.lane_id) } # print("[switch.py] now release lock to cloud", data) self._event_bus.put(Event(EventType.Release_CrossLockEvent, data), block=True)
def __init__(self, own_hash, K, B): """ :param own_hash: Our own hash :type own_hash: :class:`~common.Hash` :param K: Bucket size :type K: int. :param B: Key size :type B: int. """ self.K = K self.B = B self.own_hash = own_hash self._last_check = datetime.now() self.on_added = Event('Buckets.on_added') self.on_removed = Event('Buckets.on_removed') # B+1 buckets because 0 means perfect match # 1-320 represent the bit level difference (index + 1) self._buckets = [Bucket(K) for i in range(self.B + 1)] for bucket in self._buckets: bucket.on_added += self.on_added bucket.on_removed += self.on_removed self._conns = {}
def scrape_event_info(event_url: str) -> Event: page = requests.get(event_url) soup = BeautifulSoup(page.text, "html5lib") soup.prettify() content = soup.find(id="region-content") title_region = content.find(id="page-title") title = title_region.get_text().strip() # TODO: Capture start and end times. time_region = content.find(class_="field-name-field-event-time") time_element = time_region.find(class_="date-display-start") if not time_element: # Fallback to date-display-single if start is not available. time_element = time_region.find(class_="date-display-single") time_raw = time_element.get("content") time_aware = datetime.datetime.strptime(time_raw, "%Y-%m-%dT%H:%M:%S%z") time_real = time_aware.astimezone(tz=pytz.utc).replace(tzinfo=None) try: location_region = content.find(class_="field-name-field-location") location_region = location_region.find(class_="location") location_region.find("span", class_="map-icon").extract() location_name = location_region.find(class_="fn").get_text().strip() except: location_name = "TBA" description_region = content.find(class_="field-name-body") if description_region: description_texts = description_region.findAll(text=True) description = "\n".join(text.strip() for text in description_texts) # description = ''.join(description_texts) else: description = "No description provided" description += "\n\n" + event_url return Event( title=title, time=time_real, location=location_name, description=description, url=event_url, )
def __init__(self): self.EVENT_HEARTBEAT = "Heartbeat" self.event_heartbeat = Event(type_=self.EVENT_HEARTBEAT) self.EVENT_WVS_STATE_RECV = "WVSStateRecv" self.event_wvs_state_recv = Event(type_=self.EVENT_WVS_STATE_RECV) self.EVENT_WVS_RESULT_RECV = "ScanResultRecv" self.event_scan_result_recv = Event(type_=self.EVENT_WVS_RESULT_RECV) self.EVENT_WVS_COMMAND = "WVSCommand" self.event_wvs_command = Event(type_=self.EVENT_WVS_COMMAND) self.EVENT_SERVER_COMMAND = "ServerCommand" self.event_server_command = Event(type_=self.EVENT_SERVER_COMMAND) self.EVENT_AGENT_EXIT = "AgentExit" self.event_agent_exit = Event(type_=self.EVENT_AGENT_EXIT) self.EVENT_SCAN_RESULT_SEND = "SendResultSend" self.event_scan_result_send = Event(type_=self.EVENT_SCAN_RESULT_SEND)
def __init__(self, own_hash, target_hash, initial_contacts, K): """ :param target_hash: The :hash that this shortlist is seaching for. :type target_hash: :class:`common.Hash` :param initial_contacts: Contacts to start the shorlist with. :type initial_contacts: [:class:`common.Contact`] """ self.K = K self.search_space = list( SearchContact(contacted=False, contact=x) for x in initial_contacts) self.own_hash = own_hash self.target_hash = target_hash self.on_full_or_found = Event('Shortlist.on_full_or_found') self.in_progress = [] # Ensure we start off increasing. self.sort() self._closest = {} # Add the closest contact (our vote) # This only matters if there is 2 nodes c = self.find_min() if c is not None: self._add_closest(c.contact)
if __name__ == "__main__": event = Event( description="Event description:\n" "Poynter Fellowship in Journalism\n" "Ashlyn Still, Graphics Reporter\n" "Washington Post\n" "\n" "Holly Rushmeier\n" "is hosting Ashlyn Still\n" "\n" "News Graphics and Data Visualization\n" "\n" "The media landscape is changing rapidly and the tools used " "for reporting and storytelling are changing with it. New " "technologies have made data analysis and visualization more " "accessible for reporters to tell stories in new and different " "ways. The graphics team at The Washington Post is no " "exception – they produce award-winning visual storytelling " "using data, design, code, cartography, illustration, " "animation, augmented reality and more. We’ll take a look at " "how graphics reporters at The Post are using all of these " "methods to enhance their storytelling and better reach " "audiences in both the print and digital space.\n" "\n", location="Franke Family Digital Humanities Laboratory in the Sterling " "Memorial Library", time=datetime.datetime(2019, 11, 18, 21, 0), title="Poynter Fellowship in Journalism - Ashlyn Still, Graphics " "Reporter/Washington Post", url="https://cpsc.yale.edu/event/poynter-fellowship-journalism-ashlyn-still-graphics-reporterwashington-post", )
def lineReceived(self, line): self.__event_bus.put(Event(EventType.DataReceivedEvent, line))
def report_finished(self): """""" self._event_bus.put(Event(EventType.TaskFinishedEvent, self._current_task.get_task_state()), block=True)
def connectionMade(self): self.__state = _ConnectorState.CONNECTED self.resetDelay() self.transport.setTcpNoDelay(True) self.__event_bus.put(Event(EventType.ConnectionMadeEvent))
def __init__(self, id): self.__id = id self.loaded_event = Event()
def shutdown(self): self._event_bus.put(Event(EventType.InterruptedEvent, None))
def display_results(results, name): print("%s: 5000 Loops, best of 3: %.02f sec" % (name, min(results))) def profile(): import cProfile import pstats stmt = """ for x in xrange(0, 5000): find_events() """ cProfile.run(stmt, "b33f.prof") p = pstats.Stats("b33f.prof") p.strip_dirs().sort_stats('cumulative').print_stats(20) db = get_client() db.flushdb() Event(name="Redis Meetup 1", location="London").save() t = timeit.Timer('create_events()', 'from __main__ import create_events') display_results(t.repeat(repeat=1, number=5000), 'create_events') t = timeit.Timer('find_events()', 'from __main__ import find_events') display_results(t.repeat(repeat=1, number=5000), 'find_events') t = timeit.Timer('load_events()', 'from __main__ import load_events') display_results(t.repeat(repeat=1, number=5000), 'load_events')
def __init__(self): self.state = 'created' self.on_finalization = Event('Cryptobase.on_finalization')
def clientConnectionFailed(self, connector, reason): self.__state = _ConnectorState.DISCONNECTED self.__event_bus.put(Event(EventType.ConnectionDisconnectedEvent)) protocol.ReconnectingClientFactory.clientConnectionFailed( self, connector, reason)
def create_events(): Event(name="Redis Meetup 1", location="London").save()
def clientConnectionLost(self, connector, reason): self.__state = _ConnectorState.DISCONNECTED print "clientConnectionLost, reason: {}".format(reason) self.__event_bus.put(Event(EventType.ConnectionDisconnectedEvent)) protocol.ReconnectingClientFactory.clientConnectionLost( self, connector, reason)
def __init__(self, K): self.K = K self.contacts = list() self.waitlist = list() self.on_added = Event('Bucket.on_added') self.on_removed = Event('Bucket.on_removed')
def iget_events(self): for event in self.events: yield Event(*event)