1. Amit Aronovitch
  2. hatta-amit-dev

Commits

Amit Aronovitch  committed bad12e3

default_mimetype : refactor and fix

  • Participants
  • Parent commits 40781df
  • Branches default

Comments (0)

Files changed (3)

File hatta/config.py

View file
 _add('-U', '--unix-eol', dest='unix_eol',
     action="store_true",
     help='Convert all text pages to UNIX-style CR newlines')
+MIMETYPE_OPTIONS = ['plain','x-wiki','x-rst']
 _add('-M', '--default-mimetype', dest='default_mimetype',
-    help='Use text/MIMETYPE ([plain|x-rst|x-wiki]) for unsuffixed pages',
+    help='Use text/MIMETYPE ([%s]) for unsuffixed pages' %\
+         ('|'.join(MIMETYPE_OPTIONS)),
     metavar='MIMETYPE')
 
 class WikiConfig(object):
         
         value = self.get(option)
         if value not in allowed_vals:
-            value = defualt_value
+            value = default_value
         return value
     
     def get_bool(self, option, default_value=False):

File hatta/page.py

View file
 import error
 
 
-def page_mime(title, config=None):
+def page_mime(title, default='text/x-wiki'):
     """
     Guess page's mime type ased on corresponding file name.
-    Default ot text/x-wiki for files without an extension.
+    `default` specifies the value returned for files without an extension.
 
     >>> page_mime(u'something.txt')
     'text/plain'
     if encoding:
         mime = 'archive/%s' % encoding
     if mime is None:
-        if config:
-            mime = "text/"+config.get_enum('default_mimetype',
-                                           mime_allowed_default,
-                                           'x-wiki')
-        else:
-            mime = 'text/x-wiki'
-    
+        mime = default
     return mime
 
 

File hatta/wiki.py

View file
 import parser
 import error
 import data
+from config import MIMETYPE_OPTIONS
 
 import mercurial  # import it after storage!
 
         self.subdirectories = self.config.get_bool('subdirectories', False)
         self.extension = self.config.get('extension', None)
         self.unix_eol = self.config.get_bool('unix_eol', False)
+        self.default_mime = "text/" + \
+            self.config.get_enum('default_mimetype',MIMETYPE_OPTIONS, 'x-wiki')
         if self.subdirectories:
             self.storage = storage.WikiSubdirectoryStorage(self.path,
                                                            self.page_charset,
             try:
                 page_class, mime = self.filename_map[title]
             except KeyError:
-                mime = page.page_mime(title, self.config)
+                mime = page.page_mime(title, self.default_mime)
                 major, minor = mime.split('/', 1)
                 try:
                     page_class = self.mime_map[mime]
     def download(self, request, title):
         """Serve the raw content of a page directly from disk."""
 
-        mime = page.page_mime(title)
+        mime = page.page_mime(title, self.default_mime)
         if mime == 'text/x-wiki':
             mime = 'text/plain'
         try: