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


Python Markup.escape方法代码示例

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


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

示例1: test_payin_pages_when_currencies_dont_match

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
    def test_payin_pages_when_currencies_dont_match(self):
        self.add_payment_account(self.creator_1, 'stripe')
        self.add_payment_account(self.creator_2, 'paypal')
        self.add_payment_account(self.creator_3, 'stripe')
        self.add_payment_account(self.creator_3, 'paypal')
        self.donor.set_tip_to(self.creator_1, EUR('11.00'))
        self.donor.set_tip_to(self.creator_2, JPY('1100'))
        self.donor.set_tip_to(self.creator_3, USD('11.00'))

        paypal_path = '/donor/giving/pay/paypal/?beneficiary=%i,%i' % (
            self.creator_2.id, self.creator_3.id
        )
        stripe_path = '/donor/giving/pay/stripe/?beneficiary=%i,%i&method=card' % (
            self.creator_1.id, self.creator_3.id
        )
        r = self.client.GET('/donor/giving/pay/', auth_as=self.donor)
        assert r.code == 200, r.text
        assert str(Markup.escape(paypal_path)) not in r.text
        assert str(Markup.escape(stripe_path)) not in r.text

        r = self.client.GxT(paypal_path, auth_as=self.donor)
        assert r.code == 400, r.text

        r = self.client.GxT(stripe_path, auth_as=self.donor)
        assert r.code == 400, r.text
开发者ID:liberapay,项目名称:liberapay.com,代码行数:27,代码来源:test_payins.py

示例2: render_and_scrub

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
def render_and_scrub(markdown):
    """Given markdown, return a Markup with tags stripped and everything else
    escaped.
    """
    u_right_to_left_override = "\u202E"
    right_to_left_override = "‮"
    replacements = (right_to_left_override, ''), (u_right_to_left_override, '')
    rtlo_gone = reduce(lambda a, kv: a.replace(*kv), replacements, markdown)
    return Markup.escape(render(rtlo_gone).striptags())
开发者ID:cyberjacob,项目名称:www.gittip.com,代码行数:11,代码来源:markdown.py

示例3: test_02_payin_stripe_card_one_to_many

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
    def test_02_payin_stripe_card_one_to_many(self):
        self.db.run("ALTER SEQUENCE payins_id_seq RESTART WITH 102")
        self.db.run("ALTER SEQUENCE payin_transfers_id_seq RESTART WITH 102")
        self.add_payment_account(self.creator_1, 'stripe', id=self.acct_switzerland.id)
        self.add_payment_account(self.creator_3, 'stripe')
        self.add_payment_account(self.creator_3, 'paypal')
        tip1 = self.donor.set_tip_to(self.creator_1, JPY('1250'))
        tip3 = self.donor.set_tip_to(self.creator_3, JPY('1250'))

        # 1st request: test getting the payment pages
        expected_uri = '/donor/giving/pay/stripe/?beneficiary=%i,%i&method=card' % (
            self.creator_1.id, self.creator_3.id
        )
        r = self.client.GET('/donor/giving/pay/', auth_as=self.donor)
        assert r.code == 200, r.text
        assert str(Markup.escape(expected_uri)) in r.text
        r = self.client.GET(expected_uri, auth_as=self.donor)
        assert r.code == 200, r.text

        # 2nd request: prepare the payment
        form_data = {
            'amount': '10000',
            'currency': 'JPY',
            'tips': '%i,%i' % (tip1['id'], tip3['id']),
            'token': 'tok_jp',
        }
        r = self.client.PxST('/donor/giving/pay/stripe', form_data, auth_as=self.donor)
        assert r.code == 200, r.text
        assert r.headers[b'Refresh'] == b'0;url=/donor/giving/pay/stripe/102'
        payin = self.db.one("SELECT * FROM payins")
        assert payin.status == 'pre'
        assert payin.amount == JPY('10000')
        payin_transfers = self.db.all("SELECT * FROM payin_transfers ORDER BY id")
        assert len(payin_transfers) == 2
        pt1, pt2 = payin_transfers
        assert pt1.status == 'pre'
        assert pt1.amount == JPY('5000')
        assert pt2.status == 'pre'
        assert pt2.amount == JPY('5000')

        # 3rd request: execute the payment
        r = self.client.GET('/donor/giving/pay/stripe/102', auth_as=self.donor)
        assert r.code == 200, r.text
        payin = self.db.one("SELECT * FROM payins")
        assert payin.status == 'succeeded'
        assert payin.amount_settled == EUR('78.66')
        assert payin.fee == EUR('2.53')
        payin_transfers = self.db.all("SELECT * FROM payin_transfers ORDER BY id")
        assert len(payin_transfers) == 2
        pt1, pt2 = payin_transfers
        assert pt1.status == 'succeeded'
        assert pt1.amount == EUR('38.07')
        assert pt1.remote_id
        assert pt2.status == 'succeeded'
        assert pt2.amount == EUR('38.06')
开发者ID:liberapay,项目名称:liberapay.com,代码行数:57,代码来源:test_payins.py

示例4: __repr__

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
 def __repr__(self):
     if self.object_table == 'microblog':
         obj = Microblog.query.get(self.object_id)
         pattern = u'<a href="%s">%s</a> 在微博 <a href="%s">%s</a> 中回复了你'
         return pattern % (
             url_for('frontend.people', id=self.from_id), Markup.escape(self.from_people.nickname),
             url_for('mblog.comment', mid=self.object_id) if obj else '', Markup.escape(obj.content[:20]) if obj else u'抱歉,该微博已删除'
         )
     elif self.object_table == 'comment':
         obj = Comment.query.get(self.object_id)
         pattern = u'<a href="%s">%s</a> 在评论 <a href="%s">%s</a> 中回复了你'
         return pattern % (
             url_for('frontend.people', id=self.from_id), Markup.escape(self.from_people.nickname),
             url_for('mblog.comment', mid=obj.microblog_id, cid=self.object_id) if obj else '', Markup.escape(obj.parent_comment.content[:20]) if obj else u'抱歉,该评论已删除'
         )
     elif self.object_table == 'photo':
         obj = Photo.query.get(self.object_id)
         pattern = u'<a href="%s">%s</a> 在照片 <a href="%s">%s</a> 中回复了你'
         return pattern % (
             url_for('frontend.people', id=self.from_id), Markup.escape(self.from_people.nickname),
             url_for('photo.show_photo', pid=obj.id, aid=self.album_id) if obj else '', Markup.escape(obj.title[:20]) if obj else u'抱歉,该照片已删除'
         )
     elif self.object_table == 'album':
         obj = PhotoAlbum.query.get(self.object_id)
         pattern = u'<a href="%s">%s</a> 在相册 <a href="%s">%s</a> 中回复了你'
         return pattern % (
             url_for('frontend.people', id=self.from_id), Markup.escape(self.from_people.nickname),
             url_for('photo.show_album', id=obj.id) if obj else '', Markup.escape(obj.title[:20]) if obj else u'抱歉,该相册已删除'
         )
     elif self.object_table == 'chatting':
         pattern = u'<a href="%s">%s</a> 给你发来了一条 <a href="%s">私信</a>'
         return pattern % (
             url_for('frontend.people', id=self.from_id), Markup.escape(self.from_people.nickname),
             url_for('friendship.show_chatting_detail', box='inbox', id=self.object_id)
         )
     elif self.object_table == 'friendship':
         pattern = u'<a href="%s">%s</a> 关注了你'
         return pattern % (
             url_for('frontend.people', id=self.from_id), Markup.escape(self.from_people.nickname),
         )
开发者ID:whypro,项目名称:vieboo,代码行数:42,代码来源:notification.py

示例5: whitelist

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
def whitelist(value):
    """Whitelist specific HTML tags and strings.

    Positional arguments:
    value -- the string to perform the operation on.

    Returns:
    Markup() instance, indicating the string is safe.
    """
    translations = {
        '&amp;quot;': '&quot;',
        '&amp;#39;': '&#39;',
        '&amp;lsquo;': '&lsquo;',
        '&amp;nbsp;': '&nbsp;',
        '&lt;br&gt;': '<br>',
    }
    escaped = str(Markup.escape(value))  # Escapes everything.
    for k, v in translations.items():
        escaped = escaped.replace(k, v)  # Un-escape specific elements using str.replace.
    return Markup(escaped)  # Return as 'safe'.
开发者ID:crypex,项目名称:poppet,代码行数:22,代码来源:middleware.py

示例6: install

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
def install(request):
    addon_id = request.GET.get('addon_id', None)
    if addon_id:
        try:
            addon_id = int(addon_id)
        except ValueError:
            addon_id = Markup.escape(addon_id)
    addon_key = request.GET.get('addon_key', None)
    addon_name = request.GET.get('addon_name', None)
    if addon_id in addons:
        addon = addons[addon_id]
    elif addon_key in addons:
        addon = addons[addon_key]
    elif addon_name and addon_id:
        xpi = 'https://addons.mozilla.org/en-US/firefox/downloads/latest/%s' % addon_id
        icon = 'https://addons.mozilla.org/en-US/firefox/images/addon_icon/%s' % addon_id
        addon = {
            'name': addon_name,
            'xpi': xpi,
            'icon': icon
            }
    else:
        return HttpResponseNotFound()
    addon_link = addon.get('link', None)
    if addon_link:
        return HttpResponsePermanentRedirect(addon_link)
    if not 'xpi' in addon:
        return HttpResponseNotFound()
    src = request.GET.get('src', 'installservice')
    addon['xpi'] = urlparams(addon['xpi'], src=src)
    addon_params = {'URL': addon['xpi']}
    if 'icon' in addon:
        addon_params['IconURL'] = addon['icon']
    if 'hash' in addon:
        addon_params['Hash'] = addon['hash']
    referrers = ' || '.join(addon.get('referrers', default_referrers))
    return jingo.render(request, 'services/install.html',
                        {'referrers': referrers,
                         'params': json.dumps({'name': addon_params}),
                         'addon': addon})
开发者ID:gedex,项目名称:zamboni,代码行数:42,代码来源:install.py

示例7: __html__

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
    def __html__(self):
        ctx = get_ctx()

        # If we're in a nested render, we disable the rendering here or we
        # risk a recursion error.
        if ctx is None or self in ctx.flow_block_render_stack:
            return Markup.escape(repr(self))

        ctx.flow_block_render_stack.append(self)
        try:
            try:
                return self.pad.db.env.render_template(
                    ['blocks/%s.html' % self._data['_flowblock'],
                     'blocks/default.html'],
                    pad=self.pad,
                    this=self,
                    alt=self.record.alt,
                    values={'record': self.record}
                )
            except TemplateNotFound:
                return Markup('[could not find snippet template]')
        finally:
            ctx.flow_block_render_stack.pop()
开发者ID:ChillarAnand,项目名称:lektor,代码行数:25,代码来源:flow.py

示例8: __html__

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
    def __html__(self):
        ctx = get_ctx()

        # If we're in a nested render, we disable the rendering here or we
        # risk a recursion error.
        if ctx is None or self in ctx.flow_block_render_stack:
            return Markup.escape(repr(self))

        ctx.flow_block_render_stack.append(self)
        try:
            try:
                record = find_record_for_flowblock(ctx, self)
                return self.pad.db.env.render_template(
                    ["blocks/%s.html" % self._data["_flowblock"], "blocks/default.html"],
                    pad=self.pad,
                    this=self,
                    alt=record and record.alt or None,
                    values={"record": record},
                )
            except TemplateNotFound:
                return Markup("[could not find snippet template]")
        finally:
            ctx.flow_block_render_stack.pop()
开发者ID:RonnyPfannschmidt,项目名称:lektor,代码行数:25,代码来源:flow.py

示例9: __call__

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
    def __call__(self, field, **kwargs):
        html = super(CustomFileSelectWidget, self).__call__(field, **kwargs)

        file_format = self.file_format
        file_format_regex = ''
        if file_format and file_format == 'image':
            file_format_regex = '^image\/(gif|jpe?g|png|tif?f|tga)$'

        button = [u'<div class="form-upload-file">']

        if field.data:
            api = system_util.pillar_api()
            try:
                # Load the existing file attached to the field
                file_item = File.find(field.data, api=api)
            except ResourceNotFound:
                pass
            else:
                filename = Markup.escape(file_item.filename)
                if file_item.content_type.split('/')[0] == 'image':
                    # If a file of type image is available, display the preview
                    button.append(u'<img class="preview-thumbnail" src="{0}" />'.format(
                        file_item.thumbnail('s', api=api)))
                else:
                    button.append(u'<p>{}</p>'.format(filename))

                button.append(u'<ul class="form-upload-file-meta">')
                # File name
                button.append(u'<li class="name">{0}</li>'.format(filename))
                # File size
                button.append(u'<li class="size">({0} MB)</li>'.format(
                    round((file_item.length / 1024) * 0.001, 2)))
                # Image resolution (if image)
                button.append(u'<li class="dimensions">{0}x{1}</li>'.format(
                    file_item.width, file_item.height))
                # Delete button
                button.append(u'<li class="delete">'
                              u'<a href="#" class="file_delete" '
                              u'data-field-name="{field_name}" '
                              u'data-file_id="{file_id}"> '
                              u'<i class="pi-trash"></i> Delete</a></li>'.format(
                    field_name=field.name, file_id=field.data))
                # Download button for original file
                button.append(u'<li class="original">'
                              u'<a href="{}" class="file_original"> '
                              u'<i class="pi-download"></i>Original</a></li>'
                              .format(file_item.link))
                button.append(u'</ul>')

        upload_url = u'%s/storage/stream/{project_id}' % current_app.config[
            'PILLAR_SERVER_ENDPOINT']

        button.append(u'<input class="fileupload" type="file" name="file" '
                      u'data-url="{url}" '
                      u'data-field-name="{name}" '
                      u'data-token="{token}" '
                      u'data-file-format="{file_format}">'
                      u'<div class="form-upload-progress"> '
                      u'<div class="form-upload-progress-bar" role="progressbar" '
                      u'aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" '
                      u'style="width: 0%;"> '
                      u'</div> '
                      u'</div>'.format(url=upload_url,
                                       name=field.name,
                                       token=Markup.escape(current_user.id),
                                       file_format=Markup.escape(file_format_regex)))

        button.append(u'</div>')

        return HTMLString(html + u''.join(button))
开发者ID:aditiapratama,项目名称:pillar-web,代码行数:72,代码来源:forms.py

示例10: linebreaks

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
def linebreaks(value):
    return re.sub('\r\n|\r|\n', Markup('<br />\n'), Markup.escape(value))
开发者ID:tark-hidden,项目名称:pyramid_igniter,代码行数:4,代码来源:filters.py

示例11: test_03_payin_stripe_sdd_one_to_many

# 需要导入模块: from markupsafe import Markup [as 别名]
# 或者: from markupsafe.Markup import escape [as 别名]
    def test_03_payin_stripe_sdd_one_to_many(self):
        self.db.run("ALTER SEQUENCE payins_id_seq RESTART WITH 203")
        self.db.run("ALTER SEQUENCE payin_transfers_id_seq RESTART WITH 203")
        self.add_payment_account(self.creator_1, 'stripe', id=self.acct_switzerland.id)
        self.add_payment_account(self.creator_3, 'stripe')
        self.add_payment_account(self.creator_3, 'paypal')
        tip1 = self.donor.set_tip_to(self.creator_1, EUR('12.00'))
        tip3 = self.donor.set_tip_to(self.creator_3, EUR('12.00'))

        # 1st request: test getting the payment pages
        expected_uri = '/donor/giving/pay/stripe/?beneficiary=%i,%i&method=card' % (
            self.creator_1.id, self.creator_3.id
        )
        r = self.client.GET('/donor/giving/pay/', auth_as=self.donor)
        assert r.code == 200, r.text
        assert str(Markup.escape(expected_uri)) in r.text
        r = self.client.GET(expected_uri, auth_as=self.donor)
        assert r.code == 200, r.text

        # 2nd request: prepare the payment
        sepa_direct_debit_token = stripe.Token.create(bank_account=dict(
            country='FR',
            currency='EUR',
            account_number='FR1420041010050500013M02606',
            account_holder_name='Jane Doe',
        ))
        form_data = {
            'amount': '100.00',
            'currency': 'EUR',
            'tips': '%i,%i' % (tip1['id'], tip3['id']),
            'token': sepa_direct_debit_token.id,
        }
        r = self.client.PxST('/donor/giving/pay/stripe', form_data, auth_as=self.donor)
        assert r.code == 200, r.text
        assert r.headers[b'Refresh'] == b'0;url=/donor/giving/pay/stripe/203'
        payin = self.db.one("SELECT * FROM payins")
        assert payin.status == 'pre'
        assert payin.amount == EUR('100.00')
        payin_transfers = self.db.all("SELECT * FROM payin_transfers ORDER BY id")
        assert len(payin_transfers) == 2
        pt1, pt2 = payin_transfers
        assert pt1.status == 'pre'
        assert pt1.amount == EUR('50.00')
        assert pt2.status == 'pre'
        assert pt2.amount == EUR('50.00')

        # 3rd request: execute the payment
        r = self.client.GET('/donor/giving/pay/stripe/203', auth_as=self.donor)
        assert r.code == 200, r.text
        payin = self.db.one("SELECT * FROM payins")
        assert payin.status == 'pending'
        assert payin.amount_settled is None
        assert payin.fee is None
        payin_transfers = self.db.all("SELECT * FROM payin_transfers ORDER BY id")
        assert len(payin_transfers) == 2
        pt1, pt2 = payin_transfers
        assert pt1.status == 'pre'
        assert pt1.amount == EUR('50.00')
        assert pt1.remote_id is None
        assert pt2.status == 'pre'
        assert pt2.amount == EUR('50.00')
        assert pt2.remote_id is None
开发者ID:liberapay,项目名称:liberapay.com,代码行数:64,代码来源:test_payins.py


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