Beispiel #1
0
class Reader(object):

    def __init__(self, protocolError, responseError):
        self.protocolError = protocolError
        self.responseError = responseError
        self._stack = []
        self._inbuffer = BytesIO()
        #self.decode = connection.decode
    
    def read(self, length = None):
        """
        Read a line from the buffer is no length is specified,
        otherwise read ``length`` bytes. Always strip away the newlines.
        """
        if length is not None:
            chunk = self._inbuffer.read(length+2)
        else:
            chunk = self._inbuffer.readline()
        if chunk:
            if chunk[-2:] == b'\r\n':
                return chunk[:-2]
            else:
                self._inbuffer = BytesIO(chunk)
        return False
    
    def feed(self, buffer):
        buffer = self._inbuffer.read(-1) + buffer
        self._inbuffer = BytesIO(buffer)
        
    def gets(self, recursive = False):
        '''Called by the Parser'''
        if self._stack and not recursive:
            task = self._stack.pop()
        else:
            response = self.read()
            if not response:
                return False
            task = redisReadTask(response[:1], response[1:], self)
        return task.gets(recursive=recursive)
Beispiel #2
0
 def read(self, length = None):
     """
     Read a line from the buffer is no length is specified,
     otherwise read ``length`` bytes. Always strip away the newlines.
     """
     if length is not None:
         chunk = self._inbuffer.read(length+2)
     else:
         chunk = self._inbuffer.readline()
     if chunk:
         if chunk[-2:] == b'\r\n':
             return chunk[:-2]
         else:
             self._inbuffer = BytesIO(chunk)
     return False
Beispiel #3
0
 def feed(self, buffer):
     buffer = self._inbuffer.read(-1) + buffer
     self._inbuffer = BytesIO(buffer)
Beispiel #4
0
 def __init__(self, protocolError, responseError):
     self.protocolError = protocolError
     self.responseError = responseError
     self._stack = []
     self._inbuffer = BytesIO()