Exemplo 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)
Exemplo 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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo 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
   )
Exemplo n.º 11
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
   )
Exemplo n.º 12
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)
Exemplo n.º 13
0
def base62_encode(raw_bytes):
  """
  Encodes raw bytes into base-62 representation. URL-safe and human safe.

  Encode your Unicode strings to a byte encoding before base-62-encoding
  them.

  Convenience wrapper for consistency.

  :param raw_bytes:
      Bytes to encode.
  :returns:
      Base-62 encoded bytes.
  """
  return b62encode(raw_bytes)
Exemplo n.º 14
0
def base62_encode(raw_bytes):
    """
  Encodes raw bytes into base-62 representation. URL-safe and human safe.

  Encode your Unicode strings to a byte encoding before base-62-encoding
  them.

  Convenience wrapper for consistency.

  :param raw_bytes:
      Bytes to encode.
  :returns:
      Base-62 encoded bytes.
  """
    return base62.b62encode(raw_bytes)