Back to index

plone3  3.1.7
mtr_mimetypes.py
Go to the documentation of this file.
00001 from Products.MimetypesRegistry.interfaces import IClassifier
00002 from Products.MimetypesRegistry.MimeTypeItem import MimeTypeItem
00003 from Products.MimetypesRegistry.common import MimeTypeException
00004 
00005 from types import InstanceType
00006 import re
00007 
00008 class text_plain(MimeTypeItem):
00009 
00010     __implements__ = MimeTypeItem.__implements__
00011     __name__   = "Plain Text"
00012     mimetypes  = ('text/plain',)
00013     extensions = ('txt',)
00014     binary     = 0
00015 
00016 class text_pre_plain(MimeTypeItem):
00017 
00018     __implements__ = MimeTypeItem.__implements__
00019     __name__   = "Pre-formatted Text (<pre>)"
00020     mimetypes  = ('text/plain-pre',)
00021     extensions = ()
00022     binary     = 0
00023 
00024 class text_structured(MimeTypeItem):
00025 
00026     __implements__ = MimeTypeItem.__implements__
00027     __name__   = "Structured Text"
00028     mimetypes  = ('text/structured',)
00029     extensions = ('stx',)
00030     binary     = 0
00031 
00032 class text_rest(MimeTypeItem):
00033 
00034     __implements__ = MimeTypeItem.__implements__
00035     __name__   = "reStructured Text"
00036     mimetypes  = ("text/x-rst", "text/restructured",)
00037     extensions = ("rst", "rest", "restx") #txt?
00038     binary     = 0
00039 
00040 class text_python(MimeTypeItem):
00041 
00042     __implements__ = MimeTypeItem.__implements__
00043     __name__   = "Python Source"
00044     mimetypes  = ("text/python-source", "text/x-python",)
00045     extensions = ("py",)
00046     binary     = 0
00047 
00048 class text_wiki(MimeTypeItem):
00049 
00050     __implements__ = MimeTypeItem.__implements__
00051     __name__   = "Wiki text"
00052     mimetypes  = ("text/wiki",)
00053     extensions = ()
00054     binary     = 0
00055 
00056 class application_rtf(MimeTypeItem):
00057 
00058     __implements__ = MimeTypeItem.__implements__
00059     __name__   = 'Rich Text Format (RTF)'
00060     mimetypes  = ('application/rtf',)
00061     extensions = ('rtf',)
00062     binary     = 1
00063 
00064 class application_msword(MimeTypeItem):
00065 
00066     __implements__ = MimeTypeItem.__implements__
00067     __name__   = "Microsoft Word Document"
00068     mimetypes  = ('application/msword',)
00069     extensions = ('doc',)
00070     binary     = 1
00071 
00072 class text_xml(MimeTypeItem):
00073 
00074     __implements__ = MimeTypeItem.__implements__ + (IClassifier,)
00075 
00076     __name__   = "Extensible Markup Language (XML)"
00077     mimetypes  = ('text/xml',)
00078     extensions = ('xml',)
00079     binary     = 0
00080 
00081     def classify(self, data):
00082         m = re.search('^\s*<\\?xml.*\\?>', data)
00083         if m:
00084             return 1 # True
00085         return None  # False
00086 
00087 class application_octet_stream(MimeTypeItem):
00088     """we need to be sure this one exists"""
00089     __name__   = "Octet Stream"
00090     mimetypes = ('application/octet-stream',)
00091     binary     = 1
00092     extensions = ()
00093 
00094 class text_html(MimeTypeItem):
00095 
00096     __implements__ = MimeTypeItem.__implements__
00097     __name__   = "HTML"
00098     mimetypes  = ('text/html',)
00099     extensions = ('html', 'htm')
00100     binary     = 0
00101 
00102 class text_html_safe(MimeTypeItem):
00103 
00104     __implements__ = MimeTypeItem.__implements__
00105     __name__   = "Safe HTML"
00106     mimetypes  = ('text/x-html-safe',)
00107     extensions = ()
00108     binary     = 0
00109 
00110 class text_web_intelligent(MimeTypeItem):
00111 
00112     __implements__ = MimeTypeItem.__implements__
00113     __name__   = "Web Intelligent Plain Text"
00114     mimetypes  = ('text/x-web-intelligent',)
00115     extensions = ()
00116     binary     = 0
00117 
00118 class text_web_markdown(MimeTypeItem):
00119 
00120     __implements__ = MimeTypeItem.__implements__
00121     __name__   = "Markdown"
00122     mimetypes  = ('text/x-web-markdown',)
00123     extensions = ('markdown',)
00124     binary     = 0
00125 
00126 class text_web_textile(MimeTypeItem):
00127 
00128     __implements__ = MimeTypeItem.__implements__
00129     __name__   = "Textile"
00130     mimetypes  = ('text/x-web-textile',)
00131     extensions = ('textile',)
00132     binary     = 0
00133 
00134 reg_types = [
00135     text_plain,
00136     text_pre_plain,
00137     application_msword,
00138     text_xml,
00139     text_structured,
00140     text_rest,
00141     text_python,
00142     text_wiki,
00143     application_octet_stream,
00144     application_rtf,
00145     text_html,
00146     text_html_safe,
00147     text_web_intelligent,
00148     text_web_markdown,
00149     text_web_textile,
00150     ]
00151 
00152 def initialize(registry):
00153     for mt in reg_types:
00154         if type(mt) != InstanceType:
00155             mt = mt()
00156         registry.register(mt)
00157 
00158 __all__ = tuple([cls.__name__ for cls in reg_types])