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