def install(server, chan_list, timeout=480): fd = open(join(dirname(__file__), 'quote_database'), 'r') data = fd.read() fd.close() list_quote = split('\n+', data) sched.after(timeout, send_quote, False, server, chan_list, list_quote)
def run_test(n, m): # There will be no transmission # of data. size = 0 for ind in xrange(n, m): # We will not be ending data # so it is empty. fd = StringIO() DccServer(fd, ind) def connect(): for ind in xrange(n, m): fd = StringIO() # It will attempt to connect. client = DccClient('localhost', ind, fd, size) # If it fails then the DccServer spawned # TIMEOUT correctly and there is no listening socket. xmap(client, CONNECT_ERR, lambda x, ident=ind: logvar.write('Connection fail %s\n' % ident)) # If it connects then we have done something wrong. xmap(client, CONNECT, lambda x, ident=ind: logvar.write('Connected %s\n' % ident)) # It calls connect after 25 the timeout should run in 20. sched.after(25, connect, True)
def __init__(self, spin): self.request = '' self.header = '' self.data = '' self.spin = spin self.fd = None sched.after(self.TIMEOUT, self.spawn_idle_timeout, True) xmap(spin, LOAD, self.get_header)
def send_lines(server, target, msg, delay=0.7): def lazy(): for ind in msg.splitlines(): send_msg(server, target, ind) yield iter = lazy() def consume(): try: iter.next() except StopIteration: sched.unmark(delay, consume) sched.after(delay, consume, False)
def __init__(self, file_obj, port, timeout=20): """ Class constructor. file_obj -> The file that is being sent. port -> The port which will be used. timeout -> How long the server must be up. """ sock = socket(AF_INET, SOCK_STREAM) sock.bind(('', port)) sock.listen(1) Spin.__init__(self, sock) self.file_obj = file_obj self.timeout = timeout self.port = port Server(self) self.is_on = False xmap(self, ACCEPT, self.start_transfer) sched.after(self.timeout, self.run_timeout, True)
# When the connection is over we close # the socket and call destroy on it. # lose does this job and if something went # wrong when calling spin.close it spawns # CLOSE_ERR event. xmap(con, CLOSE, lambda con, err: lose(con)) print 'sending nick', nick send_cmd(spin, 'NICK %s' % nick) send_cmd(spin, 'USER %s' % user) # When CONNECT is issued we have send_auth called. xmap(con, CONNECT, send_auth) return con if __name__ == '__main__': USER = '******' NICK = 'alpha' CMD = ('JOIN #~math', 'PRIVMSG #~math :Uriel', 'quit') INTERVAL = 10 # This call back will be called periodically. cbck = lambda: main('irc.freenode.com', 6667, NICK, USER, CMD) sched.after(INTERVAL, cbck, False) # it runs the reactor. core.gear.mainloop()
xmap(con, CLOSE, lambda con, err: lose(con)) print 'sending nick', nick send_cmd(spin, 'NICK %s' % nick) send_cmd(spin, 'USER %s' % user) # When CONNECT is issued we have send_auth called. xmap(con, CONNECT, send_auth) return con if __name__ == '__main__': USER = '******' NICK = 'alpha' CMD = ('JOIN #~math', 'PRIVMSG #~math :Uriel', 'quit') INTERVAL = 10 # This call back will be called periodically. cbck = lambda :main('irc.freenode.com', 6667, NICK, USER, CMD) sched.after(INTERVAL, cbck, False) # it runs the reactor. core.gear.mainloop()