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


Python XML.generate方法代码示例

本文整理汇总了Python中genshi.input.XML.generate方法的典型用法代码示例。如果您正苦于以下问题:Python XML.generate方法的具体用法?Python XML.generate怎么用?Python XML.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在genshi.input.XML的用法示例。


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

示例1: expand_macro

# 需要导入模块: from genshi.input import XML [as 别名]
# 或者: from genshi.input.XML import generate [as 别名]
    def expand_macro(self, formatter, name, content):
        self.log.info('Begin expand_macro for req: ' + repr(content))
        largs, kwargs = parse_args(content)
        
        if len(largs) == 0:
            raise TracError("File name to include is required parameter!")

        orig_file_name = file_name = largs[0]

        global multirepos
        if not multirepos:
            repos = self.env.get_repository(formatter.req.authname)
        else:
            if (orig_file_name[0] == '/'): orig_file_name = orig_file_name[1:]
            splitpath = file_name.split('/')
            if (file_name[0] == '/'):
                reponame = splitpath[1]
            else:
                reponame = splitpath[0]
            repos = self.env.get_repository(reponame)
            if (repos):
                l = len(reponame)
                if (file_name[0] == '/'):
                    file_name = file_name[1:]
                file_name = file_name[l:]
            else:
                repos = self.env.get_repository()
                
        rev = kwargs.get('rev', None)
        
        if kwargs.has_key('header'):
            header = kwargs.get('header')   # user specified header
        else:
            href = '../browser/%s%s' % (orig_file_name, make_rev_str(rev))
            header = tag.a(file_name, href=href)
        if not header:
            header = u'\xa0'    # default value from trac.mimeview.api.py
            
        # TODO - 'content' is default from mimeview.api.py, but it picks
        # up text-align: center, which probably isn't the best thing if
        # we are adding a file name in the header. There isn't an obvious
        # replacement in the delivered CSS to pick over this for now though
        header_class = kwargs.get('header_class', 'content')
            
        src = repos.get_node(file_name, rev).get_content().read()

        context = formatter.context
        # put these into context object so annotator sees them
        context.file_name = file_name
        context.rev = rev
        context.startline = 1
        
        # we generally include line numbers in the output, unless it has been
        # explicitly requested otherwise. 0, no, false, none will suppress
        line_numbers = kwargs.get('line_numbers', None)
        if line_numbers is None:
            line_numbers = True
        else:
            try:
                line_numbers = int(line_numbers)
            except:
                negatory = ('no', 'false', 'none')
                line_numbers = str(line_numbers).lower() not in negatory

        # lines added up front to "trick" renderer when rendering partial
        render_prepend = []
        
        start, end = kwargs.get('start', None), kwargs.get('end', None)
        if start or end:
            src, start, end = self._handle_partial(src, start, end)
            context.startline = start
            
            if start > 2 and file_name.endswith('.php'):
                render_prepend = [ '#!/usr/bin/php -f', '<?' ]

            if render_prepend:
                src = '\n'.join(render_prepend) + '\n' + src

                # ensure accurate start number after this gets stripped
                context.startline = start - len(render_prepend) 

        mimetype = kwargs.get('mimetype', None)
        url = None  # render method doesn't seem to use this

        mv = Mimeview(self.env)
        annotations = line_numbers and ['givenlineno'] or None
            
        src = mv.render(formatter.context, mimetype, src, file_name, url, annotations)

        if line_numbers:
            # handle the case where only one line of code was included
            # and we get back an XHTML string
            if not hasattr(src, 'generate'):
                from genshi.input import XML
                src = XML(src)
            
            # the _render_source method will always set the CSS class
            # of the annotator to it's name; there isn't an easy way
            # to override that. We could create our own CSS class for
            # givenlineno that mimics lineno, but it's cleaner to just 
#.........这里部分代码省略.........
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:103,代码来源:IncludeSource.py


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