class CnczPushRHWrapper(object): """ Acts as glue between our derivation of BaseHTTPRequestHandler and the SocketServer """ def __init__(self, request, addr, server, l): self.request = IntSocketFile(request) self.addr = addr self.server = server self.l = l def handle(self): self.h = CnczPushRH(self.request, self.addr, self.server, self.l) def interrupt(self): self.request.interrupt() def cleanup(self): pass
def __init__(self, sock, locals): code.InteractiveConsole.__init__(self, locals) self.f = IntSocketFile(sock) if not isinstance(sys.stdout, FileMux): sys.stdout = FileMux(sys.stdout) if not isinstance(sys.stderr, FileMux): sys.stderr = FileMux(sys.stderr) sys.stdout.register(self.on_std_write) sys.stderr.register(self.on_std_write) self.log_handler = logging.StreamHandler(HushFile(self.f)) formatter = logging.Formatter( "%(levelname)s:%(name)s:%(message)s") self.log_handler.setFormatter(formatter) logging.getLogger('').addHandler(self.log_handler)
def __init__(self, server, _socket, l): self.l = l self.server = server self.f = ExceptionCatchingWrapper(IntSocketFile(_socket), self._on_exception) self.handler = LogServer.SocketHandler(self.f) self.socket = _socket self.running = True
def __init__(self, request, addr, server, l): self.addr = addr self.server = server self.l = l if self.server.useIntSocketFile: self.request = IntSocketFile(request) else: self.request = request
class SockConsole(code.InteractiveConsole): """ The InteractiveConsole addapted for usage with ShellServer """ def __init__(self, sock, locals): code.InteractiveConsole.__init__(self, locals) self.f = IntSocketFile(sock) if not isinstance(sys.stdout, FileMux): sys.stdout = FileMux(sys.stdout) if not isinstance(sys.stderr, FileMux): sys.stderr = FileMux(sys.stderr) sys.stdout.register(self.on_std_write) sys.stderr.register(self.on_std_write) self.log_handler = logging.StreamHandler(HushFile(self.f)) formatter = logging.Formatter( "%(levelname)s:%(name)s:%(message)s") self.log_handler.setFormatter(formatter) logging.getLogger('').addHandler(self.log_handler) def raw_input(self, prompt): self.f.write(prompt) ret = self.f.readline() if ret == '': raise IOError return ret[:-1] def on_std_write(self, v): try: self.f.write(v) except Exception: pass def cleanup(self): sys.stdout.deregister(self.on_std_write) sys.stderr.deregister(self.on_std_write) logging.getLogger('').removeHandler(self.log_handler) def interrupt(self): self.f.interrupt() def handle(self): self.interact()
class CometRHWrapper(object): """ Exposes SocketServer handler semantics for our BaseHTTPRequestHandler based CometRH """ def __init__(self, request, addr, server, l): self.addr = addr self.server = server self.l = l if self.server.useIntSocketFile: self.request = IntSocketFile(request) else: self.request = request def handle(self): self.h = CometRH(self.request, self.addr, self.server, self.l) def interrupt(self): if hasattr(self.request, 'interrupt'): self.request.interrupt() def cleanup(self): pass
def __init__(self, sock, locals): code.InteractiveConsole.__init__(self, locals) self.f = IntSocketFile(sock) if not isinstance(sys.stdout, FileMux): sys.stdout = FileMux(sys.stdout) if not isinstance(sys.stderr, FileMux): sys.stderr = FileMux(sys.stderr) sys.stdout.register(self.on_std_write) sys.stderr.register(self.on_std_write) self.log_handler = logging.StreamHandler(HushFile(self.f)) formatter = logging.Formatter("%(levelname)s:%(name)s:%(message)s") self.log_handler.setFormatter(formatter) logging.getLogger("").addHandler(self.log_handler)
def do_handshake(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.host, self.port)) f = IntSocketFile(s) prots = json.loads(f.readline()[:-1]) if not self.protocol in prots: raise UnsupportedProtocol f.write(json.dumps(self.protocol)) f.write("\n") l = logging.getLogger("%s.relay" % self.l.name) self.relay = LightJoyceRelay(self, l, f, self.protocol) self.connected.set()
def handle(self): f = IntSocketFile(self.conn) self.relay = LightJoyceRelay(self.hub, self.l, f, None) f.write(json.dumps(self.relay.prot_map.keys())) f.write("\n") protocol = self.protocol = json.loads( f.readline()[:-1]) if not isinstance(protocol, basestring) or \ not protocol in self.relay.prot_map: self.f.write("Invalid response\n") return self.relay.protocol = protocol self.hub.threadPool.execute(self.relay._run_sender) self.relay._run_receiver()
def __init__(self, request, addr, server, l): self.request = IntSocketFile(request) self.addr = addr self.server = server self.l = l