当前位置: 首页>>代码示例>>Python>>正文


Python api.Mimeview类代码示例

本文整理汇总了Python中trac.mimeview.api.Mimeview的典型用法代码示例。如果您正苦于以下问题:Python Mimeview类的具体用法?Python Mimeview怎么用?Python Mimeview使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Mimeview类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: expand_macro

    def expand_macro(self, formatter, name, content):
        from trac.mimeview.api import Mimeview
        mime_map = Mimeview(self.env).mime_map
        mime_type_filter = ''
        args, kw = parse_args(content)
        if args:
            mime_type_filter = args.pop(0).strip().rstrip('*')

        mime_types = {}
        for key, mime_type in mime_map.iteritems():
            if (not mime_type_filter or
                mime_type.startswith(mime_type_filter)) and key != mime_type:
                mime_types.setdefault(mime_type, []).append(key)

        return tag.div(class_='mimetypes')(
            tag.table(class_='wiki')(
                tag.thead(tag.tr(
                    tag.th(_("MIME Types")),  # always use plural
                    tag.th(tag.a("WikiProcessors",
                                 href=formatter.context.href.wiki(
                                     'WikiProcessors'))))),
                tag.tbody(
                    tag.tr(tag.th(tag.tt(mime_type),
                                  style="text-align: left"),
                           tag.td(tag.code(
                               ' '.join(sorted(mime_types[mime_type])))))
                    for mime_type in sorted(mime_types.keys()))))
开发者ID:exocad,项目名称:exotrac,代码行数:27,代码来源:macros.py

示例2: get_search_results

    def get_search_results(self, req, query, filters):
        if 'repo' not in filters:
            return

        for filename, reponame in self.search_backend.find_words(query):
            repo = self.env.get_repository(reponame=reponame, authname=req.authname)
            node = repo.get_node(filename)

            if node.kind == Node.DIRECTORY:
                yield (self.env.href.browser(reponame, filename),
                       "%s (in %s)" % (filename, reponame), change.date, change.author,
                       'Directory')
            else:
                found = 0
                mimeview = Mimeview(self.env)
                content = mimeview.to_unicode(node.get_content().read(), node.get_content_type())
                for n, line in enumerate(content.splitlines()):
                    line = line.lower()
                    for q in query:
                        idx = line.find(q)
                        if idx != -1:
                            found = n + 1
                            break
                    if found:
                        break

                change = repo.get_changeset(node.rev)

                yield (self.env.href.browser(reponame, filename
                                             ) + (found and '#L%i' % found or ''
                                                  ),
                       "%s (in %s)" % (filename, reponame), change.date, change.author,
                       shorten_result(content, query))
开发者ID:pombredanne,项目名称:trac-MultiRepoSearchPlugin,代码行数:33,代码来源:search.py

示例3: _render_file

    def _render_file(self, req, context, repos, node, rev=None):
        """ trac.versioncontrol.web_ui.browser.BrowserModule._render_file()
        copy with just the essentials needed for our purpose. """

        req.perm(context.resource).require('FILE_VIEW')

        mimeview = Mimeview(self.env)
        # MIME type detection
        CHUNK_SIZE = 4096
        content = node.get_content()
        chunk = content.read(CHUNK_SIZE)
        mime_type = node.content_type
        if not mime_type or mime_type == 'application/octet-stream':
            mime_type = mimeview.get_mimetype(node.name, chunk) or \
                        mime_type or 'text/plain'

        self.log.debug("Rendering ReposReadMe of node %[email protected]%s with mime-type %s"
                       % (node.name, str(rev), mime_type))
        del content # the remainder of that content is not needed
        add_stylesheet(req, 'common/css/code.css')

        annotations = []
        force_source = False
        raw_href = ''
        return mimeview.preview_data(context, node.get_content(),
                                             node.get_content_length(),
                                             mime_type, node.created_path,
                                             raw_href,
                                             annotations=annotations,
                                             force_source=force_source)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:30,代码来源:reposreadme.py

示例4: _test_convert_content

 def _test_convert_content(self, expected, content, iterable):
     mimeview = Mimeview(self.env)
     output = mimeview.convert_content(self._make_req(), self.in_mimetype,
                                       content, 'text', iterable=iterable)
     if iterable:
         self.assertNotIn(type(output[0]), (str, unicode))
         self.assertEqual(expected, ''.join(output[0]))
     else:
         self.assertEqual(type(expected), type(output[0]))
         self.assertEqual(expected, output[0])
     self.assertEqual('text/plain', output[1])
     self.assertEqual('txt', output[2])
开发者ID:exocad,项目名称:exotrac,代码行数:12,代码来源:api.py

示例5: test_extra_mimetypes

 def test_extra_mimetypes(self):
     """
     The text/x-ini mimetype is normally not known by Trac, but
     Pygments supports it.
     """
     mimeview = Mimeview(self.env)
     self.assertEqual('text/x-ini; charset=utf-8',
                      mimeview.get_mimetype('file.ini'))
     self.assertEqual('text/x-ini; charset=utf-8',
                      mimeview.get_mimetype('file.cfg'))
     self.assertEqual('text/x-ini; charset=utf-8',
                      mimeview.get_mimetype('file.text/x-ini'))
开发者ID:exocad,项目名称:exotrac,代码行数:12,代码来源:pygments.py

示例6: __init__

    def __init__(self, env, node, root, base):
        super(FilePage, self).__init__(env, node, root, base)
        self.mimeview = Mimeview(self.env)
        self.exists = (node is not None)

        self.mime_type = None
        self.chunk = None
开发者ID:rcarmo,项目名称:tracdocs,代码行数:7,代码来源:web_ui.py

示例7: setUp

 def setUp(self):
     self.env = EnvironmentStub()
     self.ticket_module = TicketModule(self.env)
     self.mimeview = Mimeview(self.env)
     self.req = Mock(hdf=HDFWrapper(['./templates']),
                     base_path='/trac.cgi', path_info='',
                     href=Href('/trac.cgi'))
开发者ID:cyphactor,项目名称:lifecyclemanager,代码行数:7,代码来源:conversion.py

示例8: ProductTicketConversionTestCase

class ProductTicketConversionTestCase(TicketConversionTestCase, \
        MultiproductTestCase):

    def setUp(self):
        self._mp_setup()
        self.global_env = self.env
        self.env = ProductEnvironment(self.global_env, self.default_product)

        # Product name inserted in RSS feed
        self.env.product._data['name'] = 'My Project'

        self.env.config.set('trac', 'templates_dir',
                            os.path.join(os.path.dirname(self.env.path),
                                         'templates'))
        self.ticket_module = ProductTicketModule(self.env)
        self.mimeview = Mimeview(self.env)
        self.req = Mock(base_path='/trac.cgi', path_info='',
                        href=Href('/trac.cgi'), chrome={'logo': {}},
                        abs_href=Href('http://example.org/trac.cgi'),
                        environ={}, perm=[], authname='-', args={}, tz=None,
                        locale='', session=None, form_token=None)

    def test_csv_conversion(self):
        ticket = self._create_a_ticket()
        csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
                                            ticket, 'csv')
        self.assertEqual(('\xef\xbb\xbf'
                          'id,summary,reporter,owner,description,status,'
                          'product,keywords,cc\r'
                          '\n1,Foo,santa,,Bar,,,,\r\n',
                          'text/csv;charset=utf-8', 'csv'), csv)

    def test_tab_conversion(self):
        ticket = self._create_a_ticket()
        csv = self.mimeview.convert_content(self.req, 'trac.ticket.Ticket',
                                            ticket, 'tab')
        self.assertEqual(('\xef\xbb\xbf'
                          'id\tsummary\treporter\towner\tdescription\tstatus\t'
                          'product\tkeywords\tcc\r\n'
                          '1\tFoo\tsanta\t\tBar\t\t\t\t\r\n',
                          'text/tab-separated-values;charset=utf-8', 'tsv'),
                         csv)

    def tearDown(self):
        self.global_env.reset_db()
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:45,代码来源:conversion.py

示例9: setUp

 def setUp(self):
     env = EnvironmentStub(enable=[Chrome, PatchRenderer])
     req = Mock(base_path='', chrome={}, args={}, session={},
                abs_href=Href('/'), href=Href('/'),
                perm=MockPerm(), authname=None, tz=None)
     self.context = Context.from_request(req)
     self.patch = Mimeview(env).renderers[0]
     patch_html = open(os.path.join(os.path.split(__file__)[0],
                                    'patch.html'))
     self.patch_html = Stream(list(HTMLParser(patch_html)))
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:10,代码来源:patch.py

示例10: setUp

 def setUp(self):
     env = EnvironmentStub(enable=[Chrome, PatchRenderer])
     req = Mock(base_path='', chrome={'static_hash': None}, args={},
                session={}, abs_href=Href('/'), href=Href('/'), locale='',
                perm=MockPerm(), authname=None, tz=None)
     self.context = web_context(req)
     self.patch = Mimeview(env).renderers[0]
     patch_html = open(os.path.join(os.path.split(__file__)[0],
                                    'patch.html'))
     self.patch_html = Stream(list(HTMLParser(patch_html, encoding='utf-8')))
开发者ID:moreati,项目名称:trac-gitsvn,代码行数:10,代码来源:patch.py

示例11: setUp

 def setUp(self):
     self.env = EnvironmentStub(enable=[Chrome, PygmentsRenderer])
     self.pygments = Mimeview(self.env).renderers[0]
     self.req = Mock(base_path='', chrome={}, args={},
                     abs_href=Href('/'), href=Href('/'),
                     session={}, perm=None, authname=None, tz=None)
     self.context = web_context(self.req)
     pygments_html = open(os.path.join(os.path.split(__file__)[0],
                                    'pygments.html'))
     self.pygments_html = Stream(list(HTMLParser(pygments_html, encoding='utf-8')))
开发者ID:exocad,项目名称:exotrac,代码行数:10,代码来源:pygments.py

示例12: setUp

 def setUp(self):
     self.env = EnvironmentStub()
     self.env.config.set('trac', 'templates_dir',
                         os.path.join(os.path.dirname(self.env.path),
                                      'templates'))
     self.ticket_module = TicketModule(self.env)
     self.mimeview = Mimeview(self.env)
     self.req = Mock(base_path='/trac.cgi', path_info='',
                     href=Href('/trac.cgi'), chrome={'logo': {}},
                     abs_href=Href('http://example.org/trac.cgi'),
                     environ={}, perm=[], authname='-', args={}, tz=None,
                     session=None, form_token=None)
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:12,代码来源:conversion.py

示例13: test_get_supported_conversions

    def test_get_supported_conversions(self):
        class Converter0(Component):
            implements(IContentConverter)
            def get_supported_conversions(self):
                yield 'key0', 'Format 0', 'c0', 'text/x-sample', 'text/html', 8

        class Converter2(Component):
            implements(IContentConverter)
            def get_supported_conversions(self):
                yield 'key2', 'Format 2', 'c2', 'text/x-sample', 'text/html', 2

        class Converter1(Component):
            implements(IContentConverter)
            def get_supported_conversions(self):
                yield 'key1', 'Format 1', 'c1', 'text/x-sample', 'text/html', 4

        mimeview = Mimeview(self.env)
        conversions = mimeview.get_supported_conversions('text/x-sample')
        self.assertEqual(Converter0(self.env), conversions[0][-1])
        self.assertEqual(Converter1(self.env), conversions[1][-1])
        self.assertEqual(Converter2(self.env), conversions[2][-1])
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:21,代码来源:api.py

示例14: process_combinewiki

 def process_combinewiki(self, req, format, title, pages):
     # Dump all pages to HTML files
     files = [self._page_to_file(req, p) for p in pages]
     titlefile = self._page_to_file(req, title, self.TITLE_HTML%title)
         
     # File to write PDF to
     pfile, pfilename = mkstemp('tracpdf')
     os.close(pfile)       
      
     # Render
     os.environ["HTMLDOC_NOCGI"] = 'yes'
     codepage = Mimeview(self.env).default_charset
     htmldoc_format = {'pdf': 'pdf14', 'ps':'ps3'}[format]
     htmldoc_args = { 'book': None, 'format': htmldoc_format, 'left': '1.5cm',
                      'right': '1.5cm', 'top': '1.5cm', 'bottom': '1.5cm',
                      'charset': codepage.replace('iso-', ''), 'title': None,
                      'titlefile': titlefile}
     htmldoc_args.update(dict(self.env.config.options('pagetopdf')))
     htmldoc_args.update(dict(self.env.config.options('combinewiki')))
     args_string = ' '.join(['--%s %s' % (arg, value or '') for arg, value
                             in htmldoc_args.iteritems()])
     cmd_string = 'htmldoc %s %s -f %s'%(args_string, ' '.join(files), pfilename)
     self.log.info('CombineWikiModule: Running %r', cmd_string)
     os.system(cmd_string)
         
     out = open(pfilename, 'rb').read()
         
     # Clean up
     os.unlink(pfilename)
     for f in files:
         os.unlink(f)
     os.unlink(titlefile)
           
     # Send the output
     req.send_response(200)
     req.send_header('Content-Type', {'pdf':'application/pdf', 'ps':'application/postscript'}[format])
     req.send_header('Content-Length', len(out))
     req.end_headers()
     req.write(out)
     raise RequestDone
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:40,代码来源:formats.py

示例15: expand_macro

    def expand_macro(self, formatter, name, content):
        add_stylesheet(formatter.req, 'lineno/css/lineno.css')

        i = 1
        self._anchor = 'a1'
        while self._anchor in formatter._anchors:
            self._anchor = 'a' + str(i)
            i += 1
        formatter._anchors[self._anchor] = True

        mt = 'txt'
        match = WikiParser._processor_re.match(content)
        if match:
            try: #Trac 0.12+
                mt = match.group(2)
                content = content[match.end(2)+1:]
            except IndexError: #Trac 0.11
                mt = match.group(1)
                content = content[match.end(1)+1:]
        
        mimeview = Mimeview(formatter.env)
        mimetype = mimeview.get_mimetype(mt) or mimeview.get_mimetype('txt')        
        return mimeview.render(formatter.context, mimetype,
                               content, annotations=['codeblock-lineno'])
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:24,代码来源:LinenoMacro.py


注:本文中的trac.mimeview.api.Mimeview类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。