##// END OF EJS Templates
fix png/jpeg b64-encoding check
MinRK -
Show More
@@ -97,9 +97,11 b' def date_default(obj):'
97 97
98 98 # constants for identifying png/jpeg data
99 99 PNG = b'\x89PNG\r\n\x1a\n'
100 PNG64 = encodebytes(PNG)
100 # front of PNG base64-encoded
101 PNG64 = b'iVBORw0KG'
101 102 JPEG = b'\xff\xd8'
102 JPEG64 = encodebytes(JPEG)
103 # front of JPEG base64-encoded
104 JPEG64 = b'/9'
103 105
104 106 def encode_images(format_dict):
105 107 """b64-encodes images in a displaypub format dict
@@ -126,14 +128,14 b' def encode_images(format_dict):'
126 128 pngdata = format_dict.get('image/png')
127 129 if isinstance(pngdata, bytes):
128 130 # make sure we don't double-encode
129 if pngdata[:13] != PNG64:
131 if not pngdata.startswith(PNG64):
130 132 pngdata = encodebytes(pngdata)
131 133 encoded['image/png'] = pngdata.decode('ascii')
132 134
133 135 jpegdata = format_dict.get('image/jpeg')
134 136 if isinstance(jpegdata, bytes):
135 137 # make sure we don't double-encode
136 if jpegdata[:5] != JPEG64:
138 if not jpegdata.startswith(JPEG64):
137 139 jpegdata = encodebytes(jpegdata)
138 140 encoded['image/jpeg'] = jpegdata.decode('ascii')
139 141
General Comments 0
You need to be logged in to leave comments. Login now