예제 #1
0
파일: helper.py 프로젝트: d0znpp/pyredis
def tag_from_key(key):
    """ return tag from key

    Tries to convert key to bytes, and return the string
    enclosed by '{' and '}', if any.
    If there is no pair of curly braces enclosing a string,
    the key, converted to bytes, is returned.

    :param key: str, bytes
    :return: bytes
    """
    key = to_bytes(key)
    lcb = key.find(b'{')
    rcb = key.find(b'}')
    if not (lcb >= 0 and rcb >= 0):
        return key
    else:
        return key[lcb+1:rcb]
예제 #2
0
def tag_from_key(key):
    """ return tag from key

    Tries to convert key to bytes, and return the string
    enclosed by '{' and '}', if any.
    If there is no pair of curly braces enclosing a string,
    the key, converted to bytes, is returned.

    :param key: str, bytes
    :return: bytes
    """
    key = to_bytes(key)
    lcb = key.find(b'{')
    rcb = key.find(b'}')
    if not (lcb >= 0 and rcb >= 0):
        return key
    else:
        return key[lcb+1:rcb]
예제 #3
0
 def test_bytes(self):
     expected = b'0815'
     result = to_bytes(b'0815')
     self.assertEqual(result, expected)
예제 #4
0
 def test_float(self):
     expected = b'0.815'
     result = to_bytes(0.815)
     self.assertEqual(result, expected)
예제 #5
0
 def test_str(self):
     expected = b'\xc3\xbc\xc3\x9f_blarg'
     result = to_bytes('üß_blarg')
     self.assertEqual(result, expected)
예제 #6
0
 def test_int(self):
     expected = b'512'
     result = to_bytes(512)
     self.assertEqual(result, expected)
예제 #7
0
 def test_bytes(self):
     expected = b'0815'
     result = to_bytes(b'0815')
     self.assertEqual(result, expected)
예제 #8
0
 def test_str(self):
     expected = b'\xc3\xbc\xc3\x9f_blarg'
     result = to_bytes('üß_blarg')
     self.assertEqual(result, expected)
예제 #9
0
 def test_float(self):
     expected = b'0.815'
     result = to_bytes(0.815)
     self.assertEqual(result, expected)
예제 #10
0
 def test_int(self):
     expected = b'512'
     result = to_bytes(512)
     self.assertEqual(result, expected)