def test_encode_and_decode(self): for length in xrange(0, 1000): content = 'x' * length encoded = util.urlsafe_b64encode(content) self.assertFalse('/' in encoded) self.assertFalse('_' in encoded) self.assertFalse('=' in encoded) self.assertEqual( content, util.urlsafe_b64decode(encoded))
def _base64_decode_json(base64_string): """ Decode the given base64 string, and return the parsed JSON as a dictionary. :raise ValidationError if either the base64 or JSON is malformed """ try: json_string = util.urlsafe_b64decode(base64_string) return json.loads(json_string) except (TypeError, ValueError) as e: raise ValidationError('Unable to decode %s as JSON: %s' % (base64_string, e))
def _base64_decode_json(base64_string): """ Decode the given base64 string, and return the parsed JSON as a dictionary. :raise ValidationError if either the base64 or JSON is malformed """ try: json_string = util.urlsafe_b64decode(base64_string) return json.loads(json_string) except (TypeError, ValueError) as e: raise ValidationError( 'Unable to decode %s as JSON: %s' % (base64_string, e) )