當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。