aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornewt@chromium.org <newt@chromium.org@7262f16d-afe8-6277-6482-052fa10e57b1>2014-06-12 18:36:17 +0000
committernewt@chromium.org <newt@chromium.org@7262f16d-afe8-6277-6482-052fa10e57b1>2014-06-12 18:36:17 +0000
commit6a4072ebd9b251b4c0f17057e94746c63f076ffb (patch)
tree432f726fd7664ac94e4eb96b06a5040e590a8591
parent7acb6009d958f09470d7216d28d79ddf488af272 (diff)
downloadgrit-6a4072ebd9b251b4c0f17057e94746c63f076ffb.tar.gz
Teach grit that file.svg is an SVG.
When dropping the reliance of platform mime databases we also lost support for the svg mime type. Readding it specifically. Also added an explicit failure if something similar happens in the future. BUG=383189 R=newt@chromium.org Review URL: https://codereview.chromium.org/324383003 git-svn-id: http://grit-i18n.googlecode.com/svn/trunk@169 7262f16d-afe8-6277-6482-052fa10e57b1
-rwxr-xr-xgrit/format/html_inline.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/grit/format/html_inline.py b/grit/format/html_inline.py
index c2b898e..66a957a 100755
--- a/grit/format/html_inline.py
+++ b/grit/format/html_inline.py
@@ -22,8 +22,10 @@ from grit import util
# There is a python bug that makes mimetypes crash if the Windows
# registry contains non-Latin keys ( http://bugs.python.org/issue9291
# ). Initing manually and blocking external mime-type databases will
-# prevent that bug and still give us the data we need.
+# prevent that bug and if we add svg manually, it will still give us
+# the data we need.
mimetypes.init([])
+mimetypes.add_type('image/svg+xml', '.svg')
DIST_DEFAULT = 'chromium'
DIST_ENV_VAR = 'CHROMIUM_BUILD'
@@ -52,17 +54,6 @@ _ICON_RE = lazy_re.compile(
re.MULTILINE)
-
-def FixupMimeType(mime_type):
- """Helper function that normalizes platform differences in the mime type
- returned by the Python's mimetypes.guess_type API.
- """
- mappings = {
- 'image/x-png': 'image/png'
- }
- return mappings[mime_type] if mime_type in mappings else mime_type
-
-
def GetDistribution():
"""Helper function that gets the distribution we are building.
@@ -115,7 +106,10 @@ def SrcInlineAsDataURL(
if names_only:
return ""
- mimetype = FixupMimeType(mimetypes.guess_type(filename)[0]) or 'text/plain'
+ mimetype = mimetypes.guess_type(filename)[0]
+ if mimetype is None:
+ raise Exception('%s is of an an unknown type and '
+ 'cannot be stored in a data url.' % filename)
inline_data = base64.standard_b64encode(util.ReadFile(filepath, util.BINARY))
prefix = src_match.string[src_match.start():src_match.start('filename')]