Ejemplo n.º 1
0
  def test_encodes_zero_prefixed_padding(self):
    self.assertEqual(b62decode(b62encode(padding_raw)), padding_raw)
    self.assertEqual(b62decode_naive(b62encode(padding_raw)), padding_raw)

    self.assertEqual(b62decode(b62encode_naive(padding_raw)), padding_raw)
    self.assertEqual(b62decode_naive(b62encode_naive(padding_raw)), padding_raw)

    self.assertEqual(base62_decode(base62_encode(padding_raw)), padding_raw)
Ejemplo n.º 2
0
  def test_encodes_zero_prefixed_padding(self):
    self.assertEqual(base62.b62decode(base62.b62encode(PADDING_RAW)), PADDING_RAW)
    self.assertEqual(_alt_base.b62decode_naive(base62.b62encode(PADDING_RAW)), PADDING_RAW)

    self.assertEqual(base62.b62decode(_alt_base.b62encode_naive(PADDING_RAW)), PADDING_RAW)
    self.assertEqual(_alt_base.b62decode_naive(_alt_base.b62encode_naive(PADDING_RAW)), PADDING_RAW)

    self.assertEqual(codec.base62_decode(codec.base62_encode(PADDING_RAW)), PADDING_RAW)
Ejemplo n.º 3
0
  def test_encoding_and_decoding(self):
    self.assertEqual(base62.b62encode(RAW_DATA), ENCODED)
    self.assertEqual(_alt_base.b62encode_naive(RAW_DATA), ENCODED)
    self.assertEqual(base62.b62decode(ENCODED), RAW_DATA)
    self.assertEqual(base62.b62decode(ENCODED_WITH_WHITESPACE), RAW_DATA)
    self.assertEqual(_alt_base.b62decode_naive(ENCODED), RAW_DATA)
    self.assertEqual(_alt_base.b62decode_naive(ENCODED_WITH_WHITESPACE), RAW_DATA)

    self.assertEqual(codec.base62_encode(RAW_DATA), ENCODED)
    self.assertEqual(codec.base62_decode(ENCODED), RAW_DATA)
    self.assertEqual(codec.base62_decode(ENCODED_WITH_WHITESPACE), RAW_DATA)
Ejemplo n.º 4
0
  def test_encoding_and_decoding(self):
    self.assertEqual(b62encode(raw_data), encoded)
    self.assertEqual(b62encode_naive(raw_data), encoded)
    self.assertEqual(b62decode(encoded), raw_data)
    self.assertEqual(b62decode(encoded_with_whitespace), raw_data)
    self.assertEqual(b62decode_naive(encoded), raw_data)
    self.assertEqual(b62decode_naive(encoded_with_whitespace), raw_data)

    self.assertEqual(base62_encode(raw_data), encoded)
    self.assertEqual(base62_decode(encoded), raw_data)
    self.assertEqual(base62_decode(encoded_with_whitespace), raw_data)
Ejemplo n.º 5
0
    def test_encoding_and_decoding(self):
        self.assertEqual(base62.b62encode(RAW_DATA), ENCODED)
        self.assertEqual(_alt_base.b62encode_naive(RAW_DATA), ENCODED)
        self.assertEqual(base62.b62decode(ENCODED), RAW_DATA)
        self.assertEqual(base62.b62decode(ENCODED_WITH_WHITESPACE), RAW_DATA)
        self.assertEqual(_alt_base.b62decode_naive(ENCODED), RAW_DATA)
        self.assertEqual(_alt_base.b62decode_naive(ENCODED_WITH_WHITESPACE),
                         RAW_DATA)

        self.assertEqual(codec.base62_encode(RAW_DATA), ENCODED)
        self.assertEqual(codec.base62_decode(ENCODED), RAW_DATA)
        self.assertEqual(codec.base62_decode(ENCODED_WITH_WHITESPACE),
                         RAW_DATA)
Ejemplo n.º 6
0
  def test_zero_bytes(self):
    self.assertEqual(base62.b62encode(ZERO_BYTES), b("0000"))
    self.assertEqual(_alt_base.b62encode_naive(ZERO_BYTES), b("0000"))
    self.assertEqual(base62.b62decode(b("0000")), ZERO_BYTES)
    self.assertEqual(_alt_base.b62decode_naive(b("0000")), ZERO_BYTES)
    self.assertEqual(base62.b62encode(ONE_ZERO_BYTE), b("0"))
    self.assertEqual(_alt_base.b62encode_naive(ONE_ZERO_BYTE), b("0"))
    self.assertEqual(base62.b62decode(b("0")), ONE_ZERO_BYTE)
    self.assertEqual(_alt_base.b62decode_naive(b("0")), ONE_ZERO_BYTE)

    self.assertEqual(codec.base62_encode(ZERO_BYTES), b("0000"))
    self.assertEqual(codec.base62_decode(b("0000")), ZERO_BYTES)
    self.assertEqual(codec.base62_encode(ONE_ZERO_BYTE), b("0"))
    self.assertEqual(codec.base62_decode(b("0")), ONE_ZERO_BYTE)
Ejemplo n.º 7
0
  def test_zero_bytes(self):
    self.assertEqual(b62encode(zero_bytes), b('0000'))
    self.assertEqual(b62encode_naive(zero_bytes), b('0000'))
    self.assertEqual(b62decode(b('0000')), zero_bytes)
    self.assertEqual(b62decode_naive(b('0000')), zero_bytes)
    self.assertEqual(b62encode(one_zero_byte), b('0'))
    self.assertEqual(b62encode_naive(one_zero_byte), b('0'))
    self.assertEqual(b62decode(b('0')), one_zero_byte)
    self.assertEqual(b62decode_naive(b('0')), one_zero_byte)

    self.assertEqual(base62_encode(zero_bytes), b('0000'))
    self.assertEqual(base62_decode(b('0000')), zero_bytes)
    self.assertEqual(base62_encode(one_zero_byte), b('0'))
    self.assertEqual(base62_decode(b('0')), one_zero_byte)
Ejemplo n.º 8
0
    def test_zero_bytes(self):
        self.assertEqual(base62.b62encode(ZERO_BYTES), b("0000"))
        self.assertEqual(_alt_base.b62encode_naive(ZERO_BYTES), b("0000"))
        self.assertEqual(base62.b62decode(b("0000")), ZERO_BYTES)
        self.assertEqual(_alt_base.b62decode_naive(b("0000")), ZERO_BYTES)
        self.assertEqual(base62.b62encode(ONE_ZERO_BYTE), b("0"))
        self.assertEqual(_alt_base.b62encode_naive(ONE_ZERO_BYTE), b("0"))
        self.assertEqual(base62.b62decode(b("0")), ONE_ZERO_BYTE)
        self.assertEqual(_alt_base.b62decode_naive(b("0")), ONE_ZERO_BYTE)

        self.assertEqual(codec.base62_encode(ZERO_BYTES), b("0000"))
        self.assertEqual(codec.base62_decode(b("0000")), ZERO_BYTES)
        self.assertEqual(codec.base62_encode(ONE_ZERO_BYTE), b("0"))
        self.assertEqual(codec.base62_decode(b("0")), ONE_ZERO_BYTE)
Ejemplo n.º 9
0
    def test_encodes_zero_prefixed_padding(self):
        self.assertEqual(base62.b62decode(base62.b62encode(PADDING_RAW)),
                         PADDING_RAW)
        self.assertEqual(
            _alt_base.b62decode_naive(base62.b62encode(PADDING_RAW)),
            PADDING_RAW)

        self.assertEqual(
            base62.b62decode(_alt_base.b62encode_naive(PADDING_RAW)),
            PADDING_RAW)
        self.assertEqual(
            _alt_base.b62decode_naive(_alt_base.b62encode_naive(PADDING_RAW)),
            PADDING_RAW)

        self.assertEqual(codec.base62_decode(codec.base62_encode(PADDING_RAW)),
                         PADDING_RAW)
Ejemplo n.º 10
0
 def test_codec_identity(self):
     self.assertEqual(
         base62.b62decode(base62.b62encode(RANDOM_BYTES_LEN_512)),
         RANDOM_BYTES_LEN_512)
     self.assertEqual(
         _alt_base.b62decode_naive(base62.b62encode(RANDOM_BYTES_LEN_512)),
         RANDOM_BYTES_LEN_512)
     self.assertEqual(
         base62.b62decode(_alt_base.b62encode_naive(RANDOM_BYTES_LEN_512)),
         RANDOM_BYTES_LEN_512)
     self.assertEqual(
         _alt_base.b62decode_naive(
             _alt_base.b62encode_naive(RANDOM_BYTES_LEN_512)),
         RANDOM_BYTES_LEN_512)
     self.assertEqual(
         codec.base62_decode(codec.base62_encode(RANDOM_BYTES_LEN_512)),
         RANDOM_BYTES_LEN_512)
Ejemplo n.º 11
0
def base62_decode(encoded):
  """
  Decodes base-62-encoded bytes into raw bytes.

  Convenience wrapper for consistency.

  :param encoded:
      Base-62 encoded bytes.
  :returns:
      Raw bytes.
  """
  return b62decode(encoded)
Ejemplo n.º 12
0
def base62_decode(encoded):
    """
  Decodes base-62-encoded bytes into raw bytes.

  Convenience wrapper for consistency.

  :param encoded:
      Base-62 encoded bytes.
  :returns:
      Raw bytes.
  """
    return base62.b62decode(encoded)
Ejemplo n.º 13
0
 def test_codec_identity(self):
   self.assertEqual(
     base62.b62decode(base62.b62encode(RANDOM_BYTES_LEN_512)),
     RANDOM_BYTES_LEN_512
   )
   self.assertEqual(
     _alt_base.b62decode_naive(base62.b62encode(RANDOM_BYTES_LEN_512)),
     RANDOM_BYTES_LEN_512
   )
   self.assertEqual(
     base62.b62decode(_alt_base.b62encode_naive(RANDOM_BYTES_LEN_512)),
     RANDOM_BYTES_LEN_512
   )
   self.assertEqual(
     _alt_base.b62decode_naive(_alt_base.b62encode_naive(RANDOM_BYTES_LEN_512)),
     RANDOM_BYTES_LEN_512
   )
   self.assertEqual(
     codec.base62_decode(codec.base62_encode(RANDOM_BYTES_LEN_512)),
     RANDOM_BYTES_LEN_512
   )
Ejemplo n.º 14
0
 def test_codec_identity(self):
   self.assertEqual(
     b62decode(b62encode(random_bytes_len_512)),
     random_bytes_len_512
   )
   self.assertEqual(
     b62decode_naive(b62encode(random_bytes_len_512)),
     random_bytes_len_512
   )
   self.assertEqual(
     b62decode(b62encode_naive(random_bytes_len_512)),
     random_bytes_len_512
   )
   self.assertEqual(
     b62decode_naive(b62encode_naive(random_bytes_len_512)),
     random_bytes_len_512
   )
   self.assertEqual(
     base62_decode(base62_encode(random_bytes_len_512)),
     random_bytes_len_512
   )