Exemplo n.º 1
0
    def handle_netstr(self, data):
        try:
            import netstring
            decoder = netstring.Decoder()

            keys = [
                "elevel",
                "sqlerrcode",
                "username",
                "database",
                "remotehost",
                "funcname",
                "message",
                "detail",
                "hint",
                "context ",
                "debug_query_string",
            ]
            pos = 0
            for field in decoder.feed(data):
                if pos < len(keys):
                    k = keys[pos]
                print(" %s: %s" % (k, field))
                pos += 1
        except Exception, e:
            print("netstr parsing error: %s" % e)
Exemplo n.º 2
0
    def worker_next_message(cls):
        """
        Get the next message from stdin.
        Called by a worker.
        Return (key, payload)
        Return (None, None) on EOF
        """

        dc = netstring.Decoder()

        # force stdin to be non-blocking
        fl = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL)
        fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, fl | os.O_NONBLOCK)

        while True:

            # wait for data
            ready_fds, _, _ = select.select([sys.stdin], [], [], 0.1)

            if len(ready_fds) == 0:
                continue

            # get data
            try:
                buf = sys.stdin.read(4096)
            except (IOError, OSError), e:
                if e.errno == errno.EWOULDBLOCK:
                    continue
                else:
                    raise

            if len(buf) == 0:
                # EOF
                return

            for msg in dc.feed(buf):
                key, payload = cls.parse_message(msg)
                yield (key, payload)
Exemplo n.º 3
0
    def __init__(self, proc):

        self.proc = proc
        self.stdout_decoder = netstring.Decoder()
        self.write_carryover = ""