Example #1
0
 def test_as_bytes(self):
     ords = [0, 1, 0x7F, 0x80, 0xC3, 0x20, 0xC3, 0xB6, 0xFF]
     s = ''.join([chr(i) for i in ords])
     self.failUnlessEqual(len(s), len(ords))
     b = compat.as_bytes(s)
     self.failUnless(isinstance(b, compat.bytes_))
     self.failUnlessEqual([compat.ord_(i) for i in b], ords)
Example #2
0
def test_magic(f, magic_hex):
    """ tests a given file to see if the magic hex matches.
    """
    data = f.read(len(magic_hex))

    if len(data) != len(magic_hex):
        return 0

    for i in range(len(magic_hex)):
        if magic_hex[i] != ord_(data[i]):
            return 0
    
    return 1
Example #3
0
def utf_8_needs_UCS_4(text):
    first = ord(b'\xF0')
    for ch in text:
        if ord_(ch) >= first:
            return True
    return False
 def test_ord_(self):
     self.failUnless(isinstance(compat.ord_(compat.bytes_(1)[0]), int))
Example #5
0
 def test_ord_(self):
     self.assertIsInstance(compat.ord_(compat.bytes_(1)[0]), int)
Example #6
0
def utf_8_needs_UCS_4(text):
    first = ord(b'\xF0')
    for ch in text:
        if ord_(ch) >= first:
            return True
    return False
Example #7
0
 def test_ord_(self):
     self.assertTrue(isinstance(compat.ord_(compat.bytes_(1)[0]), int))