Ejemplo n.º 1
0
    def testResultCode(self):

        self.assertTrue(MemcacheResult.get('STORED') == MemcacheResult.get('STORED'))

        self.assertEquals('blaataap', MemcacheResult.get('CLIENT_ERROR blaataap').msg)
        self.assertEquals('blaataap', MemcacheResult.get('SERVER_ERROR blaataap').msg)

        self.assertTrue(MemcacheResult.get('CLIENT_ERROR blaataap') == MemcacheResult.get('CLIENT_ERROR blaataap'))

        self.assertEquals("MemcacheResult.STORED", repr(MemcacheResult.STORED))

        try:
            MemcacheResult.get('XXX')
            self.fail()
        except MemcacheError:
            pass
Ejemplo n.º 2
0
    def testResultCode(self):

        self.assertTrue(
            MemcacheResult.get('STORED') == MemcacheResult.get('STORED'))

        self.assertEquals('blaataap',
                          MemcacheResult.get('CLIENT_ERROR blaataap').msg)
        self.assertEquals('blaataap',
                          MemcacheResult.get('SERVER_ERROR blaataap').msg)

        self.assertTrue(
            MemcacheResult.get('CLIENT_ERROR blaataap') == MemcacheResult.get(
                'CLIENT_ERROR blaataap'))

        self.assertEquals("MemcacheResult.STORED", repr(MemcacheResult.STORED))

        try:
            MemcacheResult.get('XXX')
            self.fail()
        except MemcacheError:
            pass
Ejemplo n.º 3
0
 def read_get(self, reader, with_cas_unique = False):
     result = {}
     while True:
         response_line = reader.read_line()
         if response_line.startswith('VALUE'):
             response_fields = response_line.split(' ')
             key = response_fields[1]
             flags = int(response_fields[2])
             n = int(response_fields[3])
             if with_cas_unique:
                 cas_unique = int(response_fields[4])
             encoded_value = reader.read_bytes(n)
             reader.read_line() #\r\n
             if with_cas_unique:
                 result[key] = (self._codec.decode(flags, encoded_value), cas_unique)
             else:
                 result[key] = self._codec.decode(flags, encoded_value)
         elif response_line == 'END':
             return MemcacheResult.OK, result
         else:
             return MemcacheResult.get(response_line), {}
Ejemplo n.º 4
0
 def read_get(self, reader, with_cas_unique=False):
     result = {}
     while True:
         response_line = reader.read_line()
         if response_line.startswith('VALUE'):
             response_fields = response_line.split(' ')
             key = response_fields[1]
             flags = int(response_fields[2])
             n = int(response_fields[3])
             if with_cas_unique:
                 cas_unique = int(response_fields[4])
             encoded_value = reader.read_bytes(n)
             reader.read_line()  #\r\n
             if with_cas_unique:
                 result[key] = (self._codec.decode(flags, encoded_value),
                                cas_unique)
             else:
                 result[key] = self._codec.decode(flags, encoded_value)
         elif response_line == 'END':
             return MemcacheResult.OK, result
         else:
             return MemcacheResult.get(response_line), {}
Ejemplo n.º 5
0
 def _read_incdec(self, reader):
     response_line = reader.read_line()
     try:
         return MemcacheResult.OK, int(response_line)
     except ValueError:
         return MemcacheResult.get(response_line), None
Ejemplo n.º 6
0
 def read_version(self, reader):
     response_line = reader.read_line()
     if response_line.startswith('VERSION'):
         return MemcacheResult.OK, response_line[8:].strip()
     else:
         return MemcacheResult.get(response_line), None
Ejemplo n.º 7
0
 def _read_result(self, reader, value = None):
     response_line = reader.read_line()
     return MemcacheResult.get(response_line), value
Ejemplo n.º 8
0
 def _read_incdec(self, reader):
     response_line = reader.read_line()
     try:
         return MemcacheResult.OK, int(response_line)
     except ValueError:
         return MemcacheResult.get(response_line), None
Ejemplo n.º 9
0
 def read_version(self, reader):
     response_line = reader.read_line()
     if response_line.startswith('VERSION'):
         return MemcacheResult.OK, response_line[8:].strip()
     else:
         return MemcacheResult.get(response_line), None
Ejemplo n.º 10
0
 def _read_result(self, reader, value=None):
     response_line = reader.read_line()
     return MemcacheResult.get(response_line), value