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


Python html.escape方法代码示例

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


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

示例1: question_preview_html

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def question_preview_html(self):
        # override to present options (original order) along with question text
        options = self.version.config.get('options', [])
        permute = self.version.config.get('permute', 'keep')
        q_html = self.question_html()
        choices_html = [
            '<p><span class="mc-letter">%s.</span> %s</p>' % (OPTION_LETTERS[i], escape(o[0]))
            for i, o
            in enumerate(options)
        ]

        if permute == 'keep':
            order_note = ''
        else:
            order_note = ' <span class="helptext">[Choices may have been presented in a different order during the quiz.]</span> '

        return mark_safe(''.join((
            '<div>',
            q_html,
            order_note,
            ''.join(choices_html),
            '</div>'
        ))) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:25,代码来源:mc.py

示例2: init_request

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def init_request(self, object_id, *args, **kwargs):
        "The 'delete' admin view for this model."
        self.obj = self.get_object(unquote(object_id))

        if not self.has_delete_permission(self.obj):
            raise PermissionDenied

        if self.obj is None:
            raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(self.opts.verbose_name), 'key': escape(object_id)})

        using = router.db_for_write(self.model)

        # Populate deleted_objects, a data structure of all related objects that
        # will also be deleted.
        (self.deleted_objects, model_count, self.perms_needed, self.protected) = get_deleted_objects(
            [self.obj], self.opts, self.request.user, self.admin_site, using) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:18,代码来源:delete.py

示例3: test_admin_lti_passport_fields_read_only

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def test_admin_lti_passport_fields_read_only(self):
        """Model fields "oauth_consumer_key" and "shared_secret" should be read only."""
        lti_passport = PlaylistLTIPassportFactory()
        user = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=user.username, password="password")
        response = self.client.get(
            reverse("admin:core_ltipassport_change", args=[lti_passport.id])
        )
        self.assertContains(
            response,
            """<div class="readonly">{oauth_consumer_key}</div>""".format(
                oauth_consumer_key=lti_passport.oauth_consumer_key
            ),
        )
        self.assertContains(
            response,
            """<div class="readonly">{shared_secret}</div>""".format(
                shared_secret=escape(lti_passport.shared_secret)
            ),
        ) 
开发者ID:openfun,项目名称:marsha,代码行数:22,代码来源:test_admin_passport.py

示例4: run

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def run(self, lines):
        new_lines = []

        def audiofy(match):
            url = match.group(0)
            url = html_escape(url)
            html = u'<audio controls><source src="{url}"><a href="{url}">{url}</a></audio>'.format(url=url)
            return self.markdown.htmlStash.store(html, safe=True)

        for line in lines:
            if line.strip():
                line = re.sub(PATTERN_RE, audiofy, line, flags=re.UNICODE)

            new_lines.append(line)

        return new_lines 
开发者ID:SPARLab,项目名称:BikeMaps,代码行数:18,代码来源:audio.py

示例5: run

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def run(self, lines):
        new_lines = []

        def videofy(match):
            url = match.group(0)
            url = html_escape(url)
            html = u'<video controls><source src="{url}"><a href="{url}">{url}</a></video>'.format(url=url)
            return self.markdown.htmlStash.store(html, safe=True)

        for line in lines:
            if line.strip():
                line = re.sub(PATTERN_RE, videofy, line, flags=re.UNICODE)

            new_lines.append(line)

        return new_lines 
开发者ID:SPARLab,项目名称:BikeMaps,代码行数:18,代码来源:video.py

示例6: test_autoescape

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def test_autoescape(self):
        content = "\nPraesent <nonummy   mi> \"in\fodio\".\r\n\t"
        template_string = string.Template("""
            {% load compact from utils %}
            {% autoescape $SWITCH %}
                [{% filter compact %}$CONTENT{% endfilter %}]
                [{% filter compact %}{{ my_var }}{% endfilter %}]/[{{ my_var|compact }}]/
            {% endautoescape %}
        """)
        for switch in ('on', 'off'):
            with self.subTest(autoescape=switch):
                template = Template(template_string.substitute(SWITCH=switch, CONTENT=content))
                page = template.render(Context({'my_var': content}))
                self.assertEqual(
                    page.replace(" "*16, "").strip(),
                    "[Praesent <nonummy mi> \"in odio\".]\n"
                    + (escape if switch == 'on' else lambda x: x)("[Praesent <nonummy mi> \"in odio\".]/") * 2
                ) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:20,代码来源:test_misc_tags.py

示例7: test_var_input

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def test_var_input(self, autoescape=True, test_data=None):
        # Values of type 'str' are expected to be split into a list of strings,
        # and HTML-encoded on output if autoescape is "on" (output as-is otherwise).
        # Values of other types are expected to be wrapped in a list as-is.
        template_string = string.Template("""
            {% load split from utils %}
            {% autoescape $SWITCH %}
                {% for x in my_var|split$SEP %}#{{ x }}#{% endfor %}
            {% endautoescape %}
        """)
        for content, expected_values in (test_data or self.test_data):
            for sep in expected_values:
                with self.subTest(value=content, separator=sep):
                    template = Template(template_string.substitute(
                        SWITCH='on' if autoescape else 'off',
                        SEP=':"{}"'.format(sep) if sep else ''))
                    page = template.render(Context({'my_var': content}))
                    self.assertEqual(
                        page.strip(),
                        "".join("#{}#".format(escape(part) if autoescape else part) for part in expected_values[sep])
                    ) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:23,代码来源:test_misc_tags.py

示例8: check_repo_status

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def check_repo_status(self, repo):
        self.check_in_html("repo_%s" % repo.pk, repo.name)
        branches = repo.branches.exclude(status=models.JobStatus.NOT_STARTED)
        for branch in branches.all():
            self.check_class("branch_%s" % branch.pk, "boxed_job_status_%s" % branch.status_slug())

        prs = repo.pull_requests.filter(closed=False)
        for pr in prs.all():
            self.check_class("pr_status_%s" % pr.pk, "boxed_job_status_%s" % pr.status_slug())
            pr_elem_id = "pr_%s" % pr.pk
            pr_elem = self.check_in_html(pr_elem_id, escape(pr.title))
            self.check_in_html(pr_elem_id, str(pr.number))
            self.check_in_html(pr_elem_id, pr.username)
            self.assertEqual(pr_elem.get_attribute("data-sort"), str(pr.number))

        pr_elems = self.selenium.find_elements_by_xpath("//ul[@id='pr_list_%s']/li" % repo.pk)
        # make sure PRs are sorted properly
        for i, elem in enumerate(pr_elems):
            pr_num = int(elem.get_attribute("data-sort"))
            if i == 0:
                prev_num = int(pr_num)
            else:
                self.assertLess(prev_num, pr_num)
                prev_num = int(pr_num) 
开发者ID:idaholab,项目名称:civet,代码行数:26,代码来源:SeleniumTester.py

示例9: format_match

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def format_match(self, obj):
        return escape(obj.username) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:4,代码来源:lookups.py

示例10: format_item_display

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def format_item_display(self, obj):
        result = '<a href="{0}">{1}</a>'.format(
            reverse(
                'admin:tracker_{0}_change'.format(obj._meta.model_name), args=[obj.pk]
            ),
            escape(str(obj)),
        )
        return mark_safe(result) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:10,代码来源:lookups.py

示例11: student_submissions

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def student_submissions(member, activity):
    url = reverse('offering:quiz:submission_history', kwargs={
        'course_slug': activity.offering.slug,
        'activity_slug': activity.slug,
        'userid': member.person.userid_or_emplid()
    })
    context = {
        'url': url,
        'fname': escape(member.person.first_name),
        'lname': escape(member.person.last_name),
    }
    return mark_safe(STUDENT_TEMPLATE.format(**context)) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:14,代码来源:quiz_display.py

示例12: to_html

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def to_html(self, questionanswer):
        ans = questionanswer.answer.get('data', '')
        if ans:
            return mark_safe('<p>' + escape(ans) + '</p>')
        else:
            return MISSING_ANSWER_HTML 
开发者ID:sfu-fas,项目名称:coursys,代码行数:8,代码来源:text.py

示例13: escape_break

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def escape_break(text: str) -> SafeText:
    """
    Helper to display student-entered text reasonably (and safely).
    """
    return mark_safe(linebreaks(escape(text))) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:7,代码来源:base.py

示例14: format_field

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def format_field(case, field):
    """
    Format long-form text as required by the discipline module, making substitutions as appropriate.
    """
    text = eval("case."+field)
    if text is None or text.strip() == "":
        return mark_safe('<p class="empty">None</p>')
    
    if field == 'contact_email_text':
        # special case: contact email is plain text
        return mark_safe("<pre>" + escape(wrap(case.substitite_values(str(text)), 78)) + "</pre>")
    else:
        return mark_safe('<div class="disc-details">' + textile_restricted(case.substitite_values(str(text)), lite=False) + '</div>') 
开发者ID:sfu-fas,项目名称:coursys,代码行数:15,代码来源:discipline_filters.py

示例15: download_response

# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import escape [as 别名]
def download_response(self, **kwargs):
        response = HttpResponse(content_type="text/html;charset=utf-8")
        content = """<title>%s</title><a href="%s">%s</a>""" % (escape(self.component.title), escape(self.url), escape(self.url))
        response.write(content.encode('utf-8'))
        return response 
开发者ID:sfu-fas,项目名称:coursys,代码行数:7,代码来源:url.py


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