def test_base64valid(): # Test base64 with valid data MAX_BASE64 = 57 lines = [] for i in range(0, len(data), MAX_BASE64): b = data[i:i + MAX_BASE64] a = binascii.b2a_base64(b) lines.append(a) res = "" for line in lines: b = binascii.a2b_base64(line) res = res + b assert res == data
def test_base64valid(): # Test base64 with valid data MAX_BASE64 = 57 lines = [] for i in range(0, len(data), MAX_BASE64): b = data[i:i+MAX_BASE64] a = binascii.b2a_base64(b) lines.append(a) res = "" for line in lines: b = binascii.a2b_base64(line) res = res + b assert res == data
def test_base64invalid(): # Test base64 with random invalid characters sprinkled throughout # (This requires a new version of binascii.) MAX_BASE64 = 57 lines = [] for i in range(0, len(data), MAX_BASE64): b = data[i:i + MAX_BASE64] a = binascii.b2a_base64(b) lines.append(a) fillers = "" valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/" for i in xrange(256): c = chr(i) if c not in valid: fillers += c def addnoise(line): noise = fillers ratio = len(line) // len(noise) res = "" while line and noise: if len(line) // len(noise) > ratio: c, line = line[0], line[1:] else: c, noise = noise[0], noise[1:] res += c return res + noise + line res = "" for line in map(addnoise, lines): b = binascii.a2b_base64(line) res += b assert res == data # Test base64 with just invalid characters, which should return # empty strings. TBD: shouldn't it raise an exception instead ? assert binascii.a2b_base64(fillers) == ''
def test_base64invalid(): # Test base64 with random invalid characters sprinkled throughout # (This requires a new version of binascii.) MAX_BASE64 = 57 lines = [] for i in range(0, len(data), MAX_BASE64): b = data[i:i+MAX_BASE64] a = binascii.b2a_base64(b) lines.append(a) fillers = "" valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/" for i in xrange(256): c = chr(i) if c not in valid: fillers += c def addnoise(line): noise = fillers ratio = len(line) // len(noise) res = "" while line and noise: if len(line) // len(noise) > ratio: c, line = line[0], line[1:] else: c, noise = noise[0], noise[1:] res += c return res + noise + line res = "" for line in map(addnoise, lines): b = binascii.a2b_base64(line) res += b assert res == data # Test base64 with just invalid characters, which should return # empty strings. TBD: shouldn't it raise an exception instead ? assert binascii.a2b_base64(fillers) == ''
def test_base64(): assert binascii.b2a_base64('xxxx') == 'eHh4eA==\n'