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)
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')
def test_base64_stdlib_compat(self): if not hasattr(py_b64, 'b64encode'): raise SkipTest( 'Python-2.3 doesn\'t have b64encode to compare against') tools.ok_( base64.b64encode(self.b_byte_chars) == py_b64.b64encode( self.b_byte_chars)) tools.ok_( base64.b64decode(self.b_byte_chars) == py_b64.b64decode( self.b_byte_chars))
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)
def test_base64_stdlib_compat(self): if not hasattr(py_b64, 'b64encode'): raise SkipTest('Python-2.3 doesn\'t have b64encode to compare against') tools.ok_(base64.b64encode(self.b_byte_chars) == py_b64.b64encode(self.b_byte_chars)) tools.ok_(base64.b64decode(self.b_byte_chars) == py_b64.b64decode(self.b_byte_chars))