mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add simple svg tester for imghdr
This commit is contained in:
parent
ea87cfba4f
commit
372e8f2c64
@ -120,3 +120,17 @@ def parse_data_uri(uri):
|
||||
|
||||
image_data = base64.b64decode(data)
|
||||
return DataURI(mimetype, charset, image_data)
|
||||
|
||||
|
||||
def test_svg(h, f):
|
||||
"""An additional imghdr library helper; test the header is SVG's or not."""
|
||||
try:
|
||||
if '<svg' in h.decode('utf-8').lower():
|
||||
return 'svg+xml'
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
|
||||
# install test_svg() to imghdr
|
||||
# refs: https://docs.python.org/3.6/library/imghdr.html#imghdr.tests
|
||||
imghdr.tests.append(test_svg)
|
||||
|
Loading…
Reference in New Issue
Block a user