Esempio n. 1
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]
Esempio n. 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]
Esempio n. 3
0
 def test_bytes(self):
     expected = b'0815'
     result = to_bytes(b'0815')
     self.assertEqual(result, expected)
Esempio n. 4
0
 def test_float(self):
     expected = b'0.815'
     result = to_bytes(0.815)
     self.assertEqual(result, expected)
Esempio n. 5
0
 def test_str(self):
     expected = b'\xc3\xbc\xc3\x9f_blarg'
     result = to_bytes('üß_blarg')
     self.assertEqual(result, expected)
Esempio n. 6
0
 def test_int(self):
     expected = b'512'
     result = to_bytes(512)
     self.assertEqual(result, expected)
Esempio n. 7
0
 def test_bytes(self):
     expected = b'0815'
     result = to_bytes(b'0815')
     self.assertEqual(result, expected)
Esempio n. 8
0
 def test_str(self):
     expected = b'\xc3\xbc\xc3\x9f_blarg'
     result = to_bytes('üß_blarg')
     self.assertEqual(result, expected)
Esempio n. 9
0
 def test_float(self):
     expected = b'0.815'
     result = to_bytes(0.815)
     self.assertEqual(result, expected)
Esempio n. 10
0
 def test_int(self):
     expected = b'512'
     result = to_bytes(512)
     self.assertEqual(result, expected)