def _CompileContent(self, path, text):
     assert text is not None, path
     _, ext = posixpath.splitext(path)
     mimetype = _MIMETYPE_OVERRIDES.get(ext, mimetypes.guess_type(path)[0])
     if ext == '.md':
         # See http://pythonhosted.org/Markdown/extensions
         # for details on "extensions=".
         content = markdown(ToUnicode(text),
                            extensions=('extra', 'headerid', 'sane_lists'))
         if self._supports_templates:
             content = Handlebar(content, name=path)
         mimetype = 'text/html'
     elif mimetype is None:
         content = text
         mimetype = 'text/plain'
     elif mimetype == 'text/html':
         content = ToUnicode(text)
         if self._supports_templates:
             content = Handlebar(content, name=path)
     elif (mimetype.startswith('text/')
           or mimetype in ('application/javascript', 'application/json')):
         content = ToUnicode(text)
     else:
         content = text
     return ContentAndType(content, mimetype,
                           self.file_system.Stat(path).version)
   def ForUnicode(self, file_system):
       '''Creates a CompiledFileSystem for Unicode text processing.
 '''
       return self.Create(file_system,
                          SingleFile(lambda _, text: ToUnicode(text)),
                          CompiledFileSystem,
                          category='text')
 def _CompileContent(self, path, text):
     assert text is not None, path
     mimetype = mimetypes.guess_type(path)[0]
     if mimetype is None:
         content = text
         mimetype = 'text/plain'
     elif mimetype == 'text/html':
         content = ToUnicode(text)
         if self._supports_templates:
             content = Handlebar(content, name=path)
     elif (mimetype.startswith('text/')
           or mimetype in ('application/javascript', 'application/json')):
         content = ToUnicode(text)
     else:
         content = text
     return ContentAndType(content, mimetype)
Exemple #4
0
 def ForTemplates(self, file_system):
   '''Creates a CompiledFileSystem for parsing templates.
   '''
   return self.Create(
       file_system,
       SingleFile(lambda path, text: Handlebar(ToUnicode(text), name=path)),
       CompiledFileSystem)
   def ForJson(self, file_system):
       '''A CompiledFileSystem specifically for parsing JSON configuration data.
 These are memoized over file systems tied to different branches.
 '''
       return self.Create(
           file_system,
           SingleFile(lambda _, data: json_parse.Parse(ToUnicode(data))),
           CompiledFileSystem,
           category='json')
 def convert_args(args):
     args = list(args)
     args[-1] = ToUnicode(args[-1])
     return args