def handle_input(result, error): if result is not None: windows.manager.get_active().entered_text(result) elif isinstance(error, EOFError): windows.manager.exit() return ui.fork(handle_input, raw_input)
def on_connect(self, result, error): if error: self.disconnect(error=error[1]) # we should immediately retry if we failed to open the socket and # there are hosts left if self.status == DISCONNECTED and not self.failedlasthost: windows.get_default( self, self.core.manager).write("* Retrying with next available host") self.connect() else: self.source = source = ui.Source() self.status = INITIALIZING self.failedhosts[:] = () self.events.trigger('SocketConnect', network=self) if source.enabled: self.source = ui.fork(self.on_read, self.socket.recv, 8192) # Auto join channels on connect for channel in self.core.channels: self.core.run_command("/join %s" % channel) for channelother in self.core.channels: self.core.run_command("/join %s" % channelother)
def connect(self): if not self.status: self.status = CONNECTING self.source = ui.fork(self.on_dns, socket.getaddrinfo, self.server, self.port, 0, socket.SOCK_STREAM) events.trigger('Connecting', network=self)
def connect(self): if not self.status: self.status = CONNECTING self.source = ui.fork(self.on_dns, socket.getaddrinfo, self.server, self.port, 0, socket.SOCK_STREAM) self.events.trigger('Connecting', network=self)
def on_dns(self, result, error): if error: self.disconnect(error=error[1]) else: #import os #import random #random.seed() #random.shuffle(result) if socket.has_ipv6: #prefer ipv6 result = [(f, t, p, c, a) for (f, t, p, c, a) in result if f == socket.AF_INET6] + result elif hasattr(socket, "AF_INET6"): #ignore ipv6 result = [(f, t, p, c, a) for (f, t, p, c, a) in result if f != socket.AF_INET6] self.failedlasthost = False for f, t, p, c, a in result: if (f, t, p, c, a) not in self.failedhosts: try: self.socket = socket.socket(f, t, p) except: continue self.source = ui.fork(self.on_connect, self.socket.connect, a) self.failedhosts.append((f, t, p, c, a)) if set(self.failedhosts) >= set(result): self.failedlasthost = True break else: self.failedlasthost = True if len(result): self.failedhosts[:] = (f, t, p, c, a), f, t, p, c, a = result[0] try: self.socket = socket.socket(f, t, p) self.source = ui.fork(self.on_connect, self.socket.connect, a) except: self.disconnect( error="Couldn't find a host we can connect to") else: self.disconnect( error="Couldn't find a host we can connect to")
def on_dns(self, result, error): if error: self.disconnect(error=error[1]) else: #import os #import random #random.seed() #random.shuffle(result) if socket.has_ipv6: #prefer ipv6 result = [(f, t, p, c, a) for (f, t, p, c, a) in result if f == socket.AF_INET6]+result elif hasattr(socket,"AF_INET6"): #ignore ipv6 result = [(f, t, p, c, a) for (f, t, p, c, a) in result if f != socket.AF_INET6] self.failedlasthost = False for f, t, p, c, a in result: if (f, t, p, c, a) not in self.failedhosts: try: self.socket = socket.socket(f, t, p) except: continue self.source = ui.fork(self.on_connect, self.socket.connect, a) self.failedhosts.append((f, t, p, c, a)) if set(self.failedhosts) >= set(result): self.failedlasthost = True break else: self.failedlasthost = True if len(result): self.failedhosts[:] = (f, t, p, c, a), f, t, p, c, a = result[0] try: self.socket = socket.socket(f, t, p) self.source = ui.fork(self.on_connect, self.socket.connect, a) except: self.disconnect(error="Couldn't find a host we can connect to") else: self.disconnect(error="Couldn't find a host we can connect to")
def on_read(self, result, error): if error: self.disconnect(error=error[1]) elif not result: self.disconnect(error="Connection closed by remote host") else: self.source = source = ui.Source() self.buffer = (self.buffer + result).split("\r\n") for line in self.buffer[:-1]: self.got_msg(line) if self.buffer: self.buffer = self.buffer[-1] else: self.buffer = '' if source.enabled: self.source = ui.fork(self.on_read, self.socket.recv, 8192)
def on_read(self, result, error): if error: self.disconnect(error=error[1]) elif not result: self.disconnect(error="Connection closed by remote host") else: self.source = source = ui.Source() self.buffer = (self.buffer + result).split("\r\n") for line in self.buffer[:-1]: self.got_msg(line) if self.buffer: self.buffer = self.buffer[-1] else: self.buffer = '' if source.enabled: self.source = ui.fork(self.on_read, self.socket.recv, 8192)
def on_connect(self, result, error): if error: self.disconnect(error=error[1]) #we should immediately retry if we failed to open the socket and there are hosts left if self.status == DISCONNECTED and not self.failedlasthost: windows.get_default(self, self.core.manager).write( "* Retrying with next available host") self.connect() else: self.source = source = ui.Source() self.status = INITIALIZING self.failedhosts[:] = () self.events.trigger('SocketConnect', network=self) if source.enabled: self.source = ui.fork(self.on_read, self.socket.recv, 8192) # Auto join channels on connect for channel in self.core.channels: self.core.run_command("/join %s" % channel)
import windows active_window = None def handle_input(result, error): if result is not None: windows.manager.get_active().entered_text(result) elif isinstance(error, EOFError): windows.manager.exit() return ui.fork(handle_input, raw_input) def onActive(e): global active_window if active_window != e.window.id: active_window = e.window.id print "Active window is now %s" % e.window.id def onCommandW(e): if len(e.args) >= 1: for window in windows.manager: if window.id == e.args[0]: window.activate() break else: print "Active window is now %s" % windows.get_active().id ui.fork(handle_input, raw_input)