當前位置: 首頁>>代碼示例>>Python>>正文


Python TagEngine.walk_tagged_names方法代碼示例

本文整理匯總了Python中tractags.api.TagEngine.walk_tagged_names方法的典型用法代碼示例。如果您正苦於以下問題:Python TagEngine.walk_tagged_names方法的具體用法?Python TagEngine.walk_tagged_names怎麽用?Python TagEngine.walk_tagged_names使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tractags.api.TagEngine的用法示例。


在下文中一共展示了TagEngine.walk_tagged_names方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: render_listtagged

# 需要導入模塊: from tractags.api import TagEngine [as 別名]
# 或者: from tractags.api.TagEngine import walk_tagged_names [as 別名]
    def render_listtagged(self, req, *tags, **kwargs):
        """ List tagged objects. Optionally accepts a list of tags to match
            against.  The special tag '''. (dot)''' inserts the current Wiki page name.

            `[[ListTagged(<tag>, ...)]]`

            ||'''Argument'''||'''Description'''||
            ||`tagspace=<tagspace>`||Specify the tagspace the macro should operate on.||
            ||`tagspaces=(<tagspace>,...)`||Specify a set of tagspaces the macro should operate on.||
            ||`operation=intersection|union`||The set operation to perform on the discovered objects.||
            ||`showheadings=true|false`||List objects under the tagspace they occur in.||
            ||`expression=<expr>`||Match object tags against the given expression.||

            The supported expression operators are: unary - (not); binary +, -
            and | (and, and not, or). All values in the expression are treated
            as tags. Any tag not in the same form as a Python variable must be
            quoted.
            
            eg. Match all objects tagged with ticket and workflow, and not
            tagged with wiki or closed.
            
                (ticket+workflow)-(wiki|closed)

            If an expression is provided operation is ignored.
        """

        if 'tagspace' in kwargs:
            tagspaces = [kwargs.get('tagspace', None)]
        else:
            tagspaces = kwargs.get('tagspaces', '') or \
                        list(TagEngine(self.env).tagspaces)
        expression = kwargs.get('expression', None)
        showheadings = kwargs.get('showheadings', 'false')
        operation = kwargs.get('operation', 'intersection')
        if operation not in ('union', 'intersection'):
            raise TracError("Invalid tag set operation '%s'" % operation)

        engine = TagEngine(self.env)
        page_name = req.hdf.get('wiki.page_name')
        if page_name:
            tags = [tag == '.' and page_name or tag for tag in tags]

        tags = set(tags)
        taginfo = {}
        out = StringIO()
        out.write('<ul class="listtagged">\n')
        # If expression was passed as an argument, do a full walk, using the
        # expression as the predicate. Silently assumes that failed expressions
        # are normal tags.
        if expression:
            from tractags.expr import Expression
            try:
                expr = Expression(expression)
            except Exception, e:
                self.env.log.error("Invalid expression '%s'" % expression, exc_info=True)
                tags.update([x.strip() for x in re.split('[+,]', expression) if x.strip()])
                expression = None
            else:
                self.env.log.debug(expr.ast)
                tagged_names = {}
                tags.update(expr.get_tags())
                for tagspace, name, name_tags in engine.walk_tagged_names(tags=tags,
                        tagspaces=tagspaces, predicate=lambda ts, n, t: expr(t)):
                    tagged_names.setdefault(tagspace, {})[name] = name_tags
                tagged_names = [(tagspace, names) for tagspace, names in tagged_names.iteritems()]
開發者ID:nyuhuhuu,項目名稱:trachacks,代碼行數:67,代碼來源:macros.py


注:本文中的tractags.api.TagEngine.walk_tagged_names方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。