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


Python Transformer.wrap方法代码示例

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


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

示例1: filter_stream

# 需要导入模块: from genshi.filters import Transformer [as 别名]
# 或者: from genshi.filters.Transformer import wrap [as 别名]
    def filter_stream(self, req, method, filename, stream, data):
        """
        Reformat the ``branch`` field of a ticket to show the history of the
        linked branch.
        """
        if filename == 'ticket.html':
            ticket = data.get('ticket')
            if ticket and ticket.exists:
                branch = ticket['branch']
                if branch:
                    error = None
                    if not self._is_valid_branch_name(branch):
                        error = "not a valid branch name"
                    elif not self._is_existing_branch(branch):
                        error = "branch does not exist"
                    else:
                        try:
                            master = self._dereference_head(MASTER_BRANCH)
                            branch = self._dereference_head(branch)
                            common_ancestor = self._common_ancestor(master,branch)
                            if branch == common_ancestor:
                                # the trac log page does not work if the revisions are equal
                                error = "no commits on branch yet"
                            else:
                                filter = Transformer('//td[@headers="h_branch"]/text()')
                                stream |= filter.wrap(tag.a(href=req.href.log(revs="%s-%s"%(common_ancestor,branch))))
                        except GitError:
                            error = "failed to determine common ancestor with %s branch"%MASTER_BRANCH

                    if error:
                        filter = Transformer('//td[@headers="h_branch"]')
                        stream |= filter.attr("title",error)

        return stream
开发者ID:saraedum,项目名称:sage_trac,代码行数:36,代码来源:ticket_branch.py

示例2: filter_stream

# 需要导入模块: from genshi.filters import Transformer [as 别名]
# 或者: from genshi.filters.Transformer import wrap [as 别名]
    def filter_stream(self, req, method, filename, stream, data):
        """
        Wrap the banner and mainnav in a single banner_wrapper div
        """
        buffer = StreamBuffer()
        filter = Transformer("//div[@id='banner']")
        stream |= filter.wrap(tag.div(id="banner_wrapper")).end(
            ).select("//div[@id='mainnav']").cut(buffer, accumulate=True).end().buffer(
            ).select("//div[@id='banner_wrapper']").append(tag.hr()).append(buffer).end()

        return stream
开发者ID:pombredanne,项目名称:trac-LighterTheme,代码行数:13,代码来源:__init__.py

示例3: _customize_View

# 需要导入模块: from genshi.filters import Transformer [as 别名]
# 或者: from genshi.filters.Transformer import wrap [as 别名]
    def _customize_View(self, stream):

        filter = Transformer('.//div [@id="banner"]')
        stream = stream | filter.wrap(self.css_banner_top2)

        buffer = StreamBuffer()
        stream = stream | Transformer('.//div [@id="banner"]').copy(buffer).end().select('.//div [@id="top2"]').after(
            tag.div(id_="top1")(buffer)
        )

        filter = Transformer('.//div [@id="mainnav"]')
        stream = stream | filter.wrap(self.css_banner_top4)

        buffer = StreamBuffer()
        stream = stream | Transformer('.//div [@id="mainnav"]').copy(buffer).end().select('.//div [@id="top4"]').after(
            tag.div(id_="top3")(buffer)
        )

        filter = Transformer('.//div [@id="top3"]')
        stream = stream | filter.after(tag.div(id_="right")(tag.p()))

        filter = Transformer('.//div [@id="right"]')
        stream = stream | filter.append(tag.div(class_="wiki-toc")(tag.h4(_("Table of Contents"))))

        # just for the menu / TOC
        filter = Transformer('.//div [@class="wiki-toc"]')

        if self.anchors and self.keylist:
            for key in self.keylist:
                stream = stream | filter.append(
                    tag.a(key, href="#" + self.anchors.get(key), onclick="scrollup();") + tag.br()
                )
        filter = Transformer('.//div [@id="main"]')
        stream = stream | filter.wrap(self.css_left)

        return stream
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:38,代码来源:ticketnav.py

示例4: filter_stream

# 需要导入模块: from genshi.filters import Transformer [as 别名]
# 或者: from genshi.filters.Transformer import wrap [as 别名]
    def filter_stream(self, req, method, filename, stream, data):
        """
        Wrap the banner and mainnav in a single banner_wrapper div
        """

        for href in self.extra_stylesheets:
            add_stylesheet(req, href)
        add_stylesheet(req, '/lightertheme/theme.css')

        stream |= Transformer("//div[@id='banner']").wrap(tag.div(class_="banner_wrapper banner_wrapper_first"))
        stream |= Transformer("//div[@id='mainnav']").wrap(tag.div(class_="banner_wrapper banner_wrapper_second"))
        stream |= Transformer("//div[@class='banner_wrapper banner_wrapper_first']").append(tag.hr())
        return stream


        filter = Transformer("//div[@id='banner']")
        stream |= filter.wrap(tag.div(id="banner_wrapper")).end(
            ).select("//div[@id='mainnav']").cut(buffer, accumulate=True).end().buffer(
            ).select("//div[@id='banner_wrapper']").append(tag.hr()).append(buffer).end()

        return stream
开发者ID:ejucovy,项目名称:trac-LighterTheme,代码行数:23,代码来源:__init__.py

示例5: filter_stream

# 需要导入模块: from genshi.filters import Transformer [as 别名]
# 或者: from genshi.filters.Transformer import wrap [as 别名]
    def filter_stream(self, req, method, filename, stream, data):
        """
        Quick and dirty solution - modify page on the fly to inject special field. It would be
        nicer if we can do it by creating custom field as this depends on page structure.
        """
        #embed(header='Ticket Stream Filter')
        if filename == 'ticket.html':
            # Disable any direct bounty input
            filter = Transformer('.//input[@id="field-bounty"]')
            stream |= filter.attr("disabled", "disabled")
            
            ticket = data.get('ticket')
            if ticket and ticket.exists:
                identifier = ticket.id
                user = req.authname if req.authname != 'anonymous' else None
                request = self.call_api('GET', '/issue/%s' % identifier)
                fragment = tag()
                sponsorships = {}
                status = self.convert_status(ticket.values['status'])
                owner = ticket.values['owner']
                tooltip = None
                if request != None and (request.status_code == 200 or request.status_code == 404):
                    sponsorships = self.get_sponsorships(identifier)
                    
                    pledged_amount = sum_amounts(sponsorships.values())
                    user_sponsorship = sponsorships.get(user, Sponsorship())

                    # Bounty
                    tooltip = u"Pledged: %d\u20ac" % pledged_amount
                    
                    if status == 'STARTED' or status == 'COMPLETED':
                        confirmed_amount = sum_amounts(sponsorships.values(), ('CONFIRMED', 'VALIDATED', 'REJECTED', 'TRANSFERRED', 'REFUNDED'))
                        tooltip += u" \nConfirmed: %d\u20ac" % confirmed_amount
                    if status == 'COMPLETED':
                        validated_amount = sum_amounts(sponsorships.values(), 'VALIDATED')
                        tooltip += u" \nValidated: %d\u20ac" % validated_amount
                    
                    # Action
                    action = None
                    if (((status == 'STARTED' or status == 'COMPLETED') 
                            and user_sponsorship.status == 'PLEDGED') 
                        or (status == 'STARTED' and user != None and user != owner
                            and user_sponsorship.status == None)):
                        response = self.call_api('GET', '/config/payment_gateways')
                        gateways = response.json().get('gateways')
                        gateway_tags = []
                        if 'DUMMY' in gateways:
                            gateway_tags.append(tag.input(type="submit", value="Payment Card", name='DUMMY'))
                        if 'PAYPAL_STANDARD' in gateways:
                            gateway_tags.append(tag.input(type="submit", value="PayPal", name='PAYPAL_STANDARD'))
                        if 'PAYPAL_ADAPTIVE' in gateways:
                            gateway_tags.append(tag.input(type="submit", value="PayPal", name='PAYPAL_ADAPTIVE'))
                        if user_sponsorship.status == 'PLEDGED':
                            action = tag.form(
                                tag.input(type="button", name="confirm", value=u"Confirm %d\u20ac" % user_sponsorship.amount, id="confirm-button"), 
                                tag.span(gateway_tags, id="confirm-options"), 
                                tag.input(type="submit", name="delete", value="Delete"), 
                                method="post", action=req.href.ticket(identifier, "confirm"))
                        else:
                            #TODO: should be separate action
                            action = tag.form(
                                tag.input(name="amount", type="text", size="3", value="0", pattern="[0-9]*", title="money amount"), 
                                tag.input(type="button", value="Pledge & Confirm", id="confirm-button"), 
                                tag.span(gateway_tags, id="confirm-options"), 
                                method="post", action=req.href.ticket(identifier, "confirm"))

                    elif status == 'COMPLETED' and user_sponsorship.status in ('CONFIRMED', 'REJECTED', 'VALIDATED'):
                        action = tag.form(method="post", action=req.href.ticket(identifier, "validate"))
                        if user_sponsorship.status == 'CONFIRMED' or user_sponsorship.status == 'REJECTED':
                            action.append(tag.input(type="submit", name='validate', value=u"Validate %d\u20ac" % user_sponsorship.amount))
                        if user_sponsorship.status == 'CONFIRMED' or user_sponsorship.status == 'VALIDATED':
                            action.append(tag.input(type="submit", name='reject', value="Reject"))
                    elif (status == 'READY' and user != None):
                        if user_sponsorship.status == None:
                            action = tag.form(tag.input(name="amount", type="text", size="3", value=user_sponsorship.amount, pattern="[0-9]*", title="money amount"), tag.input(type="submit", value="Pledge"), method="post", action=req.href.ticket(identifier, "sponsor"))
                        elif user_sponsorship.status == 'PLEDGED':
                            action = tag.form(tag.input(name="amount", type="text", size=3, value=user_sponsorship.amount, pattern="[0-9]*", title="money amount"), tag.input(type="submit", name="update", value="Update"), tag.input(type="submit", name="delete", value="Delete"), method="post", action=req.href.ticket(identifier, "update_sponsorship"))
                    
                    elif (user == None):
                        action = tag.span(u"\u00A0", tag.a("Login", href=req.href.login()), " or ", tag.a("Register", href=req.href.register()), " to sponsor")
                    
                    if action != None:
                        fragment.append(" ")
                        fragment.append(action)
                        
                else:
                    error = "Connection error"
                    if request:
                        error = request.json().get("error", "Unknown error")
                    fragment.append(tag.span("[BountyFunding Error]", title=error))
    
                #chrome = Chrome(self.env)
                #chrome.add_jquery_ui(req)
                
                add_stylesheet(req, 'htdocs/styles/bountyfunding.css')
                add_script(req, 'htdocs/scripts/bountyfunding.js')

                if tooltip != None:
                    filter = Transformer('.//td[@headers="h_bounty"]/text()')
                    stream |= filter.wrap(tag.span(title=tooltip))
#.........这里部分代码省略.........
开发者ID:centaurustech,项目名称:bountyfunding,代码行数:103,代码来源:bountyfunding.py


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