[Zope-Checkins] CVS: Zope/lib/python/OFS - mime.types:1.1.12.1
content_types.py:1.18.68.2
Chris McDonough
chrism at zopemafia.com
Sun Dec 21 21:34:12 EST 2003
Update of /cvs-repository/Zope/lib/python/OFS
In directory cvs.zope.org:/tmp/cvs-serv15277/lib/python/OFS
Modified Files:
Tag: Zope-2_7-branch
content_types.py
Added Files:
Tag: Zope-2_7-branch
mime.types
Log Message:
Backport the warnfilter and mime-types features from the HEAD into the 2.7 branch.
=== Added File Zope/lib/python/OFS/mime.types ===
application-x-cdf cdf
application/msword doc dot wiz
application/pdf pdf
application/pkcs7-mime p7c
application/vnd.mozilla.xul+xml xul
application/vnd.ms-excel xlb xls
application/vnd.ms-powerpoint pot ppa pps ppt pwz
application/x-javascript js
application/x-pkcs12 p12 pfx
application/x-pn-realaudio ram
audio/mpeg mp3
audio/x-pn-realaudio ra
image/pict pct pic pict
message/rfc822 eml nws mht mhtml
text/css css
text/plain bat c h pl ksh
text/x-vcard vcf
text/xml xml xsl
video/mpeg m1v mpa
=== Zope/lib/python/OFS/content_types.py 1.18.68.1 => 1.18.68.2 ===
--- Zope/lib/python/OFS/content_types.py:1.18.68.1 Sun Sep 14 08:39:59 2003
+++ Zope/lib/python/OFS/content_types.py Sun Dec 21 21:33:41 2003
@@ -13,10 +13,12 @@
"""A utility module for content-type handling."""
__version__='$Revision$'[11:-2]
-import re, mimetypes
+import mimetypes
+import os.path
+import re
-find_binary=re.compile('[\0-\7]').search
+find_binary = re.compile('[\0-\7]').search
def text_type(s):
# Yuk. See if we can figure out the type by content.
@@ -30,70 +32,43 @@
return 'text/plain'
-
-# This gives us a hook to add content types that
-# aren't currently listed in the mimetypes module.
-_addtypes=(
- ('.mp3', 'audio/mpeg'),
- ('.ra', 'audio/x-pn-realaudio'),
- ('.pdf', 'application/pdf'),
- ('.c', 'text/plain'),
- ('.bat', 'text/plain'),
- ('.h', 'text/plain'),
- ('.pl', 'text/plain'),
- ('.ksh', 'text/plain'),
- ('.ram', 'application/x-pn-realaudio'),
- ('.cdf', 'application-x-cdf'),
- ('.doc', 'application/msword'),
- ('.dot', 'application/msword'),
- ('.wiz', 'application/msword'),
- ('.xlb', 'application/vnd.ms-excel'),
- ('.xls', 'application/vnd.ms-excel'),
- ('.ppa', 'application/vnd.ms-powerpoint'),
- ('.ppt', 'application/vnd.ms-powerpoint'),
- ('.pps', 'application/vnd.ms-powerpoint'),
- ('.pot', 'application/vnd.ms-powerpoint'),
- ('.pwz', 'application/vnd.ms-powerpoint'),
- ('.eml', 'message/rfc822'),
- ('.nws', 'message/rfc822'),
- ('.mht', 'message/rfc822'),
- ('.mhtml', 'message/rfc822'),
- ('.css', 'text/css'),
- ('.p7c', 'application/pkcs7-mime'),
- ('.p12', 'application/x-pkcs12'),
- ('.pfx', 'application/x-pkcs12'),
- ('.js', 'application/x-javascript'),
- ('.pct', 'image/pict'),
- ('.pic', 'image/pict'),
- ('.pict', 'image/pict'),
- ('.m1v', 'video/mpeg'),
- ('.mpa', 'video/mpeg'),
- ('.vcf', 'text/x-vcard'),
- ('.xml', 'text/xml'),
- ('.xsl', 'text/xml'),
- ('.xul', 'application/vnd.mozilla.xul+xml'),
- )
-for name, val in _addtypes:
- mimetypes.types_map[name]=val
-
def guess_content_type(name='', body='', default=None):
# Attempt to determine the content type (and possibly
# content-encoding) based on an an object's name and
# entity body.
- type, enc=mimetypes.guess_type(name)
+ type, enc = mimetypes.guess_type(name)
if type is None:
if body:
if find_binary(body) is not None:
- type=default or 'application/octet-stream'
+ type = default or 'application/octet-stream'
else:
- type=(default or text_type(body)
- or 'text/x-unknown-content-type')
+ type = (default or text_type(body)
+ or 'text/x-unknown-content-type')
else:
- type=default or 'text/x-unknown-content-type'
+ type = default or 'text/x-unknown-content-type'
return type.lower(), enc and enc.lower() or None
-if __name__=='__main__':
- items=mimetypes.types_map.items()
+
+def add_files(filenames):
+ # Make sure the additional files are either loaded or scheduled to
+ # be loaded:
+ if mimetypes.inited:
+ # Re-initialize the mimetypes module, loading additional files
+ mimetypes.init(filenames)
+ else:
+ # Tell the mimetypes module about the additional files so
+ # when it is initialized, it will pick up all of them, in
+ # the right order.
+ mimetypes.knownfiles.extend(filenames)
+
+
+# Provide definitions shipped as part of Zope:
+here = os.path.dirname(os.path.abspath(__file__))
+add_files([os.path.join(here, "mime.types")])
+
+
+if __name__ == '__main__':
+ items = mimetypes.types_map.items()
items.sort()
for item in items: print "%s:\t%s" % item
More information about the Zope-Checkins
mailing list