Esempio n. 1
0
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
Esempio n. 2
0
 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)
Esempio n. 3
0
File: log.py Progetto: sjl421/sarah
 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
Esempio n. 4
0
 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
Esempio n. 5
0
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()
Esempio n. 6
0
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
Esempio n. 7
0
 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)
Esempio n. 8
0
 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()
Esempio n. 9
0
 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()
Esempio n. 10
0
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()
Esempio n. 11
0
 def __init__(self, request, addr, server, l):
     self.request = IntSocketFile(request)
     self.addr = addr
     self.server = server
     self.l = l