Example #1
0
    def test_base64_encode(self):
        tools.ok_(base64.b64encode(self.b_byte_chars) == self.b_byte_encoded)
        tools.ok_(base64.b64encode(self.b_byte_chars, altchars='-_') == self.b_byte_encoded_urlsafe)
        tools.ok_(base64.standard_b64encode(self.b_byte_chars) == self.b_byte_encoded)
        tools.ok_(base64.urlsafe_b64encode(self.b_byte_chars) == self.b_byte_encoded_urlsafe)

        tools.ok_(base64.b64encode(self.b_byte_chars) == self.b_byte_encoded)
        tools.ok_(base64.b64encode(self.b_byte_chars, altchars='-_') == self.b_byte_encoded_urlsafe)
        tools.ok_(base64.standard_b64encode(self.b_byte_chars) == self.b_byte_encoded)
        tools.ok_(base64.urlsafe_b64encode(self.b_byte_chars) == self.b_byte_encoded_urlsafe)
Example #2
0
 def test_b64encode(self):
     eq = self.assertEqual
     # Test default alphabet
     eq(base64.b64encode("www.python.org"), "d3d3LnB5dGhvbi5vcmc=")
     eq(base64.b64encode('\x00'), 'AA==')
     eq(base64.b64encode("a"), "YQ==")
     eq(base64.b64encode("ab"), "YWI=")
     eq(base64.b64encode("abc"), "YWJj")
     eq(base64.b64encode(""), "")
     eq(base64.b64encode("abcdefghijklmnopqrstuvwxyz"
                         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                         "0123456789!@#0^&*();:<>,. []{}"),
        "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
        "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
        "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
     # Test with arbitrary alternative characters
     eq(base64.b64encode('\xd3V\xbeo\xf7\x1d', altchars='*$'), '01a*b$cd')
     # Test standard alphabet
     eq(base64.standard_b64encode("www.python.org"), "d3d3LnB5dGhvbi5vcmc=")
     eq(base64.standard_b64encode("a"), "YQ==")
     eq(base64.standard_b64encode("ab"), "YWI=")
     eq(base64.standard_b64encode("abc"), "YWJj")
     eq(base64.standard_b64encode(""), "")
     eq(base64.standard_b64encode("abcdefghijklmnopqrstuvwxyz"
                                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                  "0123456789!@#0^&*();:<>,. []{}"),
        "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
        "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
        "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
     # Test with 'URL safe' alternative characters
     eq(base64.urlsafe_b64encode('\xd3V\xbeo\xf7\x1d'), '01a-b_cd')
Example #3
0
 def test_b64encode(self):
     eq = self.assertEqual
     # Test default alphabet
     eq(base64.b64encode("www.python.org"), "d3d3LnB5dGhvbi5vcmc=")
     eq(base64.b64encode('\x00'), 'AA==')
     eq(base64.b64encode("a"), "YQ==")
     eq(base64.b64encode("ab"), "YWI=")
     eq(base64.b64encode("abc"), "YWJj")
     eq(base64.b64encode(""), "")
     eq(base64.b64encode("abcdefghijklmnopqrstuvwxyz"
                         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                         "0123456789!@#0^&*();:<>,. []{}"),
        "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
        "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
        "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
     # Test with arbitrary alternative characters
     eq(base64.b64encode('\xd3V\xbeo\xf7\x1d', altchars='*$'), '01a*b$cd')
     # Test standard alphabet
     eq(base64.standard_b64encode("www.python.org"), "d3d3LnB5dGhvbi5vcmc=")
     eq(base64.standard_b64encode("a"), "YQ==")
     eq(base64.standard_b64encode("ab"), "YWI=")
     eq(base64.standard_b64encode("abc"), "YWJj")
     eq(base64.standard_b64encode(""), "")
     eq(base64.standard_b64encode("abcdefghijklmnopqrstuvwxyz"
                                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                  "0123456789!@#0^&*();:<>,. []{}"),
        "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE"
        "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT"
        "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==")
     # Test with 'URL safe' alternative characters
     eq(base64.urlsafe_b64encode('\xd3V\xbeo\xf7\x1d'), '01a-b_cd')
Example #4
0
    def test_base64_encode(self):
        tools.ok_(base64.b64encode(self.b_byte_chars) == self.b_byte_encoded)
        tools.ok_(
            base64.b64encode(self.b_byte_chars, altchars='-_') ==
            self.b_byte_encoded_urlsafe)
        tools.ok_(
            base64.standard_b64encode(self.b_byte_chars) ==
            self.b_byte_encoded)
        tools.ok_(
            base64.urlsafe_b64encode(self.b_byte_chars) ==
            self.b_byte_encoded_urlsafe)

        tools.ok_(base64.b64encode(self.b_byte_chars) == self.b_byte_encoded)
        tools.ok_(
            base64.b64encode(self.b_byte_chars, altchars='-_') ==
            self.b_byte_encoded_urlsafe)
        tools.ok_(
            base64.standard_b64encode(self.b_byte_chars) ==
            self.b_byte_encoded)
        tools.ok_(
            base64.urlsafe_b64encode(self.b_byte_chars) ==
            self.b_byte_encoded_urlsafe)