[Zope-CVS] CVS: Products/AdaptableStorage/serial_ofs - MetaTypeClassifier.py:1.15

Shane Hathaway shane@zope.com
Thu, 6 Feb 2003 13:14:44 -0500


Update of /cvs-repository/Products/AdaptableStorage/serial_ofs
In directory cvs.zope.org:/tmp/cvs-serv18094/serial_ofs

Modified Files:
	MetaTypeClassifier.py 
Log Message:
Corrected the automatic extension for certain kinds of files.

=== Products/AdaptableStorage/serial_ofs/MetaTypeClassifier.py 1.14 => 1.15 ===
--- Products/AdaptableStorage/serial_ofs/MetaTypeClassifier.py:1.14	Thu Feb  6 12:55:25 2003
+++ Products/AdaptableStorage/serial_ofs/MetaTypeClassifier.py	Thu Feb  6 13:14:12 2003
@@ -24,6 +24,20 @@
 from mapper_public import IClassifier, DeserializationError
 
 
+# guess_extension() is useful but it's unoptimized and sometimes
+# chooses strange extensions.  fixed_extensions is faster and contains
+# some better defaults.
+fixed_extensions = {
+    'text/plain': '.txt',
+    'text/html':  '.html',
+    'image/png':  '.png',
+    'image/jpg':  '.jpg',
+    'image/jpeg': '.jpg',
+    'image/gif':  '.gif',
+    'application/octet-stream': '',  # No extension--too overloaded.
+    }
+
+
 class MetaTypeClassifier:
     """A classifier based on meta_type attributes.
     """
@@ -123,7 +137,9 @@
         if flags and (flags & MetaTypeClassifier.CONTENT_TYPE_ATTR):
             ct = str(getattr(aq_base(value), 'content_type', None))
             if ct:
-                ext = guess_extension(ct, strict=0)
+                ext = fixed_extensions.get(ct)
+                if ext is None:
+                    ext = guess_extension(ct, strict=0)
         else:
             ext = self.mt_to_ext.get(mt)
         if ext: