def receiver(self):
        buf = bytearray()

        sock = self._sock
        wait_read = gethub().do_read
        add_chunk = buf.extend
        pos = [0]

        def readmore():
            while True:
                wait_read(sock)
                try:
                    if pos[0]*2 > len(buf):
                        del buf[:pos[0]]
                        pos[0] = 0
                    bytes = sock.recv(self.BUFSIZE)
                    if not bytes:
                        raise EOFError()
                    add_chunk(bytes)
                except socket.error as e:
                    if e.errno in (errno.EAGAIN, errno.EINTR):
                        continue
                    else:
                        raise
                else:
                    break

        def readchar():
            if len(buf) <= pos[0]:
                readmore()
            c = buf[pos[0]]
            pos[0] += 1
            return c

        def readline():
            if len(buf) < 2 or pos[0] >= len(buf):
                readmore()
            while True:
                try:
                    idx = buf.index(b'\r\n', pos[0])
                except __HOLE__:
                    pass
                else:
                    break
                readmore()
            res = buf[pos[0]:idx]
            pos[0] = idx + 2
            return res

        def readslice(ln):
            while len(buf) - pos[0] < ln:
                readmore()
            res = buf[pos[0]:pos[0]+ln]
            pos[0] += ln
            return res

        def readone():
            ch = readchar()
            if ch == 42: # b'*'
                cnt = int(readline())
                return [readone() for i in range(cnt)]
            elif ch == 43: # b'+'
                return readline().decode('ascii')
            elif ch == 45: # b'-'
                return RedisError(readline().decode('ascii'))
            elif ch == 58: # b':'
                return int(readline())
            elif ch == 36: # b'$'
                ln = int(readline())
                if ln < 0:
                    return None
                res = readslice(ln)
                assert readline() == b''
                return res
            else:
                raise NotImplementedError(ch)

        while True:
            self.produce(readone())
dataset/ETHPy150Open tailhook/zorro/zorro/redis.py/RedisChannel.receiver