def requestReceived(self, command, path, version, data): parsed = urlparse.urlparse(path) protocol = parsed[0] host = parsed[1] port = self.ports[protocol] if ':' in host: host, port = string.split(host, ':') rest = urlparse.urlunparse(('', '') + parsed[2:]) if not rest: rest = rest + '/' class_ = self.protocols[protocol] if not self.received.has_key('host'): self.received['host'] = host clientProtocol = class_(command, rest, version, self.received, data, self) client = tcp.Client(host, port, clientProtocol)
def login(self): host = self.hostname.get() port = self.port.get() service = self.service.get() # Maybe we're connecting to a unix socket, so don't make any # assumptions try: port = int(port) except: pass user = self.username.get() pswd = self.password.get() b = pb.Broker() self.broker = b b.requestIdentity(user, pswd, callback=self.gotIdentity, errback=self.couldNotConnect) b.notifyOnDisconnect(self.disconnected) tcp.Client(host, port, b)
def checkState(self): '''call me periodically to check I am still up to date synchronize with the state of the world, and maybe launch a new relay ''' self.readDirectory() if not self.messages: return if len(self.managed) >= self.maxConnections: return nextMessages = self.messages.keys()[:self.maxMessagesPerConnection] toRelay = [] for message in nextMessages: self.relayingMessages[message] = 1 del self.messages[message] toRelay.append(os.path.join(self.directory, message)) protocol = SMTPManagedRelayer(toRelay, self) self.managed[protocol] = nextMessages transport = tcp.Client(self.smartHostAddr[0], self.smartHostAddr[1], protocol)
def connect(self): self.needAuthorization = 1 self.transport = tcp.Client(self.host, self.port, self)
def requestReceived(self, command, path, version, data): self.received['host'] = self.factory.host clientProtocol = ProxyClient(command, path, version, self.received, data, self) client = tcp.Client(self.factory.host, self.factory.port, clientProtocol)
def queryTCP(self, addr, name, callback, type=1, cls=1, recursive=1): self.createTCPFactory() protocol = self.factories[1].buildProtocol(addr) protocol.setQuery(name, callback, type, cls) transport = tcp.Client(addr[0], addr[1], protocol, recursive)
def main(): tcp.Client("localhost", 389, SearchALot()) twisted.internet.main.run()
def connectionMade(self): clientProtocol = StupidProtocol() clientProtocol.setPeer(self.transport) client = tcp.Client(self.factory.host, self.factory.port, clientProtocol) self.setPeer(client)
class IRCBot(irc.IRCClient): def signedOn(self): self.setNick("SeanP-AIM") self.join("#sbp") def ctcpQuery_ACTION(self, user, channel, data): b1.say("aaronswartz", "* " + user.split("!")[0] + " " + data) def privmsg(self, user, channel, message): if not user: print message return b1.say("aaronswartz", "<" + user.split("!")[0] + "> " + message) def callWhois(self): print "calling whos" self.sendLine("WHOIS sbp") reactor.callLater(60, self.callWhois) def irc_RPL_WHOISIDLE(self, prefix, params): b1.idle(params[2]) b1 = AIMBot('screenname', 'password') t1 = tcp.Client("toc.oscar.aol.com", 9898, b1) b2 = IRCBot() t2 = tcp.Client("irc.openprojects.net", 6667, b2) main.run()
def ctcpQuery_DCC(self, user, channel, data): """Initiate a Direct Client Connection Supported connection types: SEND, CHAT """ data = string.split(data) if len(data) < 4: raise IRCBadMessage, "malformed DCC request: %s" % (data, ) (dcctype, arg, address, port) = data[:4] port = int(port) if '.' in address: pass else: try: address = long(address) except ValueError: raise IRCBadMessage,\ "Indecipherable address '%s'" % (address,) else: address = ( (address >> 24) & 0xFF, (address >> 16) & 0xFF, (address >> 8) & 0xFF, address & 0xFF, ) # The mapping to 'int' is to get rid of those accursed # "L"s which python 1.5.2 puts on the end of longs. address = string.join(map(str, map(int, address)), ".") if self.dcc_sessions is None: self.dcc_sessions = [] if dcctype == 'SEND': size = -1 if len(data) >= 5: try: size = int(data[4]) except ValueError: pass filename = path.basename(arg) protocol = DccFileReceive(filename, size, queryData=(user, channel, data)) tcp.Client(address, port, protocol) self.dcc_sessions.append(protocol) elif dcctype == 'CHAT': protocol = DccChat(self, queryData=(user, channel, data)) tcp.Client(address, port, protocol) self.dcc_sessions.append(protocol) #elif dcctype == 'PERSPECTIVE': # b = self.classDccPbRequest(user, channel, arg) # pb.connect(b.callback, b.errback, address, port, # string.split(arg, ':')[0], # string.split(arg, ':')[1], # string.split(arg, ':')[2]) else: nick = string.split(user, "!")[0] self.ctcpMakeReply(nick, [('ERRMSG', "DCC %s :Unknown DCC type '%s'" % (data, dcctype))]) self.quirkyMessage("%s offered unknown DCC type %s" % (user, dcctype))