def test_zero_bytes(self): self.assertEqual(base36.b36encode(ZERO_BYTES_4), b("0000")) self.assertEqual(base36.b36decode(b("0000")), ZERO_BYTES_4) self.assertEqual(base36.b36encode(ZERO_BYTE), b("0")) self.assertEqual(base36.b36decode(b("0")), ZERO_BYTE) self.assertEqual(codec.base36_encode(ZERO_BYTES_4), b("0000")) self.assertEqual(codec.base36_decode(b("0000")), ZERO_BYTES_4) self.assertEqual(codec.base36_encode(ZERO_BYTE), b("0")) self.assertEqual(codec.base36_decode(b("0")), ZERO_BYTE)
def base36_decode(encoded): """ Decodes base-36-encoded bytes into raw bytes. Convenience wrapper for consistency. :param encoded: Base-36 encoded bytes. :returns: Raw bytes. """ return b36decode(encoded)
def base36_decode(encoded): """ Decodes base-36-encoded bytes into raw bytes. Convenience wrapper for consistency. :param encoded: Base-36 encoded bytes. :returns: Raw bytes. """ return base36.b36decode(encoded)
def test_wikipedia_decoding(self): decoding_table = [ (b("1"), 1), (b("10"), 36), (b("100"), 1296), (b("1000"), 46656), (b("10000"), 1679616), (b("100000"), 60466176), (b("1000000"), 2176782336), (b("10000000"), 78364164096), (b("100000000"), 2821109907456), ] for encoded, number in decoding_table: raw_bytes = integer.uint_to_bytes(number) self.assertEqual(base36.b36encode(raw_bytes), encoded) self.assertEqual(base36.b36decode(encoded), raw_bytes)
def test_wikipedia_encoding(self): encoding_table = [ (1, b("1")), (10, b("A")), (100, b("2S")), (1000, b("RS")), (10000, b("7PS")), (100000, b("255S")), (1000000, b("LFLS")), (1000000000, b("GJDGXS")), (1000000000000, b("CRE66I9S")), ] for number, encoded in encoding_table: raw_bytes = integer.uint_to_bytes(number) self.assertEqual(base36.b36encode(raw_bytes), encoded) self.assertEqual(base36.b36decode(encoded), raw_bytes)
def test_decoder_ignores_whitespace(self): hello_world_encoded = b(" \nFUV RSIVVNF\nRBJW\tAJO\x0b") self.assertEqual(base36.b36decode(hello_world_encoded), b("hello world"))
def test_hello_world(self): hello_world = b("\x48\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64") encoded_hello_world = base36.b36encode(hello_world) self.assertEqual(base36.b36decode(encoded_hello_world), hello_world)
def test_encodes_zero_prefixed_padding(self): self.assertEqual(base36.b36decode(base36.b36encode(RAW_DATA)), RAW_DATA) self.assertEqual(codec.base36_decode(codec.base36_encode(RAW_DATA)), RAW_DATA)
def test_codec_identity(self): self.assertEqual(base36.b36decode(base36.b36encode(RANDOM_BYTES)), RANDOM_BYTES) self.assertEqual(codec.base36_decode(codec.base36_encode(RANDOM_BYTES)), RANDOM_BYTES)
def test_codec_identity(self): self.assertEqual(base36.b36decode(base36.b36encode(RANDOM_BYTES)), RANDOM_BYTES) self.assertEqual( codec.base36_decode(codec.base36_encode(RANDOM_BYTES)), RANDOM_BYTES)