def test_producer (now, p, next_test): def test_produce (when): if p.producer_stalled (): async_loop.schedule ( when + async_loop.precision, test_produce ) else: data = p.more () if data: loginfo.log (data, 'p.more ()') async_loop.schedule ( when + async_loop.precision, test_produce ) else: async_loop.schedule ( when + async_loop.precision, next_test ) async_loop.schedule ( now + async_loop.precision, test_produce )
def connect (dispatcher, addr, timeout=3.0, family=socket.AF_INET): "create a socket, try to connect it and schedule a timeout" assert ( not dispatcher.connected and timeout > 0 and family in SOCKET_FAMILIES ) dispatcher.client_when = time.time () dispatcher.client_timeout = timeout try: dispatcher.create_socket (family, socket.SOCK_STREAM) dispatcher.connect (addr) except: dispatcher.loginfo_traceback () dispatcher.handle_error () return False assert None == dispatcher.log ('connect', 'debug') def connect_timeout (when): "if not connected and not closing yet, handle close" if not dispatcher.connected and not dispatcher.closing: assert None == dispatcher.log ( 'connect-timeout %f seconds' % ( when - dispatcher.client_when ), 'debug' ) dispatcher.handle_close () async_loop.schedule ( dispatcher.client_when + timeout, connect_timeout ) return True
def server_start (self, when): "handle the client management startup" self.server_when = when async_loop.schedule ( when + self.server_precision, self.server_manage ) assert None == self.log ('start', 'debug')
def connect(dispatcher, addr, timeout=3.0, family=socket.AF_INET): "create a socket, try to connect it and schedule a timeout" assert (not dispatcher.connected and timeout > 0 and family in SOCKET_FAMILIES) dispatcher.client_when = time.time() dispatcher.client_timeout = timeout try: dispatcher.create_socket(family, socket.SOCK_STREAM) dispatcher.connect(addr) except: dispatcher.loginfo_traceback() dispatcher.handle_error() return False assert None == dispatcher.log('connect', 'debug') def connect_timeout(when): "if not connected and not closing yet, handle close" if not dispatcher.connected and not dispatcher.closing: assert None == dispatcher.log( 'connect-timeout %f seconds' % (when - dispatcher.client_when), 'debug') dispatcher.handle_close() async_loop.schedule(dispatcher.client_when + timeout, connect_timeout) return True
def test_file_collector(when): loginfo.log('test File_collector') c = synchronized.File_collector('test.txt') c.collect_incoming_data('this is a test\n') c.collect_incoming_data('this is a test\n') c.collect_incoming_data('this is a test\n') c.found_terminator() async_loop.schedule(when + async_loop.precision, test_file_producer)
def test_popen_collector (when): loginfo.log ('test Popen_collector') c = synchronized.popen_collector ( '/python24/python test/subcollect.py' ) c.collect_incoming_data ('this is a test\n\n') c.found_terminator () async_loop.schedule ( when + async_loop.precision, test_popen_reactor )
def test_file_collector (when): loginfo.log ('test File_collector') c = synchronized.File_collector ('test.txt') c.collect_incoming_data ('this is a test\n') c.collect_incoming_data ('this is a test\n') c.collect_incoming_data ('this is a test\n') c.found_terminator () async_loop.schedule ( when + async_loop.precision, test_file_producer )
def http_clock (Class): now = time () Class.http_time = format_time (now) def scheduled (when): if Class.http_time == None: return Class.http_time = format_time (when) return (when + 1.0, scheduled) async_loop.schedule (now + 1.0, scheduled)
def http_clock(Class): now = time() Class.http_time = format_time(now) def scheduled(when): if Class.http_time == None: return Class.http_time = format_time(when) return (when + 1.0, scheduled) async_loop.schedule(now + 1.0, scheduled)
def test_producer(now, p, next_test): def test_produce(when): if p.producer_stalled(): async_loop.schedule(when + async_loop.precision, test_produce) else: data = p.more() if data: loginfo.log(data, 'p.more ()') async_loop.schedule(when + async_loop.precision, test_produce) else: async_loop.schedule(when + async_loop.precision, next_test) async_loop.schedule(now + async_loop.precision, test_produce)
def limit_schedule (dispatcher, when, interval, limit, unlimit): "instanciate and schedule a limit recurrence" # set the limit flag down dispatcher.limit_stop = False def scheduled (when): if dispatcher.closing or dispatcher.limit_stop: # closing or limit flag raised, remove unlimit (dispatcher) return if limit (dispatcher, when): # limit overflowed, remove and handle close unlimit (dispatcher) dispatcher.handle_close () return # recur at interval return (when + interval, scheduled) async_loop.schedule (when + interval, scheduled)
) test_producer (when, p, test_popen_collector) def test_popen_collector (when): loginfo.log ('test Popen_collector') c = synchronized.popen_collector ( '/python24/python test/subcollect.py' ) c.collect_incoming_data ('this is a test\n\n') c.found_terminator () async_loop.schedule ( when + async_loop.precision, test_popen_reactor ) def test_popen_reactor (when): loginfo.log ('test Popen_reactor') apipe = synchronized.Popen_reactor ( '/python24/python test/subcollect.py' ) def finalize (apipe): loginfo.log ('%r' % apipe, 'finalized') apipe.finalization = finalize test_producer (when, apipe.producer, (lambda when: None)) apipe.collector.collect_incoming_data ('this is a test\n\n') apipe.collector.found_terminator () async_loop.schedule ( time.time () + async_loop.precision, test_file_collector ) async_loop.dispatch () finalization.collect ()
def test_popen_collector(when): loginfo.log('test Popen_collector') c = synchronized.popen_collector('/python24/python test/subcollect.py') c.collect_incoming_data('this is a test\n\n') c.found_terminator() async_loop.schedule(when + async_loop.precision, test_popen_reactor)
loginfo, async_loop, dns_client ) def test_lookup (info): def resolved (request): loginfo.log ('%r' % (request.__dict__, ), info) # lookup A, MX, NS and PTR resource records dns_client.lookup (('www.google.be', 'A'), resolved) dns_client.lookup (('google.be', 'MX'), resolved) dns_client.lookup (('google.be', 'NS'), resolved) dns_client.lookup (( '215.247.47.195.in-addr.arpa', 'PTR' ), resolved) # lookup the same question twice dns_client.lookup (('www.google.be', 'A'), resolved) # try an error dns_client.lookup (('www.google', 'A'), resolved) # and failing server/IP addresses dns_client.lookup (('www.google.com', 'A'), resolved, ( '192.168.1.3', 'not-a-valid-IP-address', '192.168.1.1', )) # test asap test_lookup ('resolved') # schedule cache hits def delayed_lookup (when): test_lookup ('delayed') async_loop.schedule (time.time () + 6, delayed_lookup) async_loop.dispatch ()
def test_popen_producer(when): loginfo.log('test Popen_producer') p = synchronized.popen_producer('/python24/python test/subproduce.py') test_producer(when, p, test_popen_collector) def test_popen_collector(when): loginfo.log('test Popen_collector') c = synchronized.popen_collector('/python24/python test/subcollect.py') c.collect_incoming_data('this is a test\n\n') c.found_terminator() async_loop.schedule(when + async_loop.precision, test_popen_reactor) def test_popen_reactor(when): loginfo.log('test Popen_reactor') apipe = synchronized.Popen_reactor('/python24/python test/subcollect.py') def finalize(apipe): loginfo.log('%r' % apipe, 'finalized') apipe.finalization = finalize test_producer(when, apipe.producer, (lambda when: None)) apipe.collector.collect_incoming_data('this is a test\n\n') apipe.collector.found_terminator() async_loop.schedule(time.time() + async_loop.precision, test_file_collector) async_loop.dispatch() finalization.collect()
def timeouts_start (self, when): async_loop.schedule ( when + self.timeouts_precision, self.timeouts_poll )
loginfo.log('%r' % (request.__dict__, ), info) # lookup A, MX, NS and PTR resource records dns_client.lookup(('www.google.be', 'A'), resolved) dns_client.lookup(('google.be', 'MX'), resolved) dns_client.lookup(('google.be', 'NS'), resolved) dns_client.lookup(('215.247.47.195.in-addr.arpa', 'PTR'), resolved) # lookup the same question twice dns_client.lookup(('www.google.be', 'A'), resolved) # try an error dns_client.lookup(('www.google', 'A'), resolved) # and failing server/IP addresses dns_client.lookup(('www.google.com', 'A'), resolved, ( '192.168.1.3', 'not-a-valid-IP-address', '192.168.1.1', )) # test asap test_lookup('resolved') # schedule cache hits def delayed_lookup(when): test_lookup('delayed') async_loop.schedule(time.time() + 6, delayed_lookup) async_loop.dispatch()
def timeouts_start(self, when): async_loop.schedule(when + self.timeouts_precision, self.timeouts_poll)
def server_start(self, when): "handle the client management startup" self.server_when = when async_loop.schedule(when + self.server_precision, self.server_manage) assert None == self.log('start', 'debug')