Cleanup extension overrides in get_css.py.
authorW. Trevor King <wking@drexel.edu>
Sun, 9 Jan 2011 12:42:37 +0000 (07:42 -0500)
committerW. Trevor King <wking@drexel.edu>
Sun, 9 Jan 2011 12:42:37 +0000 (07:42 -0500)
posts/get_css/get_css.py

index 7b5baa1b268262f9ea739e6dbf11669808e14823..d4d3b36be2634ac967924f3ab6dc53701a896c48 100755 (executable)
@@ -147,6 +147,10 @@ class CSSReplacer (object):
     Downloads the files, adjusting the extension if necessary, and
     update reference to point to the local copies.
     """
+    _mime_overrides = {
+        'image/jpeg': '.jpg',
+        }
+
     def __init__(self, href=None, data_dir=None, data_url=None):
         self._href = href
         if data_dir == None:
@@ -163,12 +167,12 @@ class CSSReplacer (object):
         _url = os.path.basename(url)
         root,ext = os.path.splitext(_url)
         info,data = get_page(full_url)
-        expected_ext = guess_extension(info.gettype())
-        for _from,_to in [('.jpe', '.jpg')]:
-            if expected_ext == _from:
-                LOG.debug('wierd exception %s from type %s'
-                          % (_from, info.gettype()))
-                expected_ext = _to
+        _type = info.gettype()
+        if _type in self._mime_overrides:
+            expected_ext = self._mime_overrides[_type]
+        else:
+            expected_ext = guess_extension(_type)
+        LOG.critical('XX %s\t%s' % (_type, expected_ext))
         if expected_ext != ext:
             LOG.info('changing extension for %s from %s to %s'
                      % (full_url, ext, expected_ext))