Python html 模块,entities() 实例源码
我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用html.entities()。
def error(self, line, col, message, error_type):
"""Add a reference to an error/warning on the given line and column."""
self.highlight.line(line, error_type)
# Some linters use html entities in error messages,decode them
message = HTML_ENTITY_RE.sub(self.replace_entity, message)
# Strip trailing CR,space and period
message = ((col or 0), str(message).rstrip('\r .'))
if line in self.errors:
self.errors[line].append(message)
else:
self.errors[line] = [message]
def test_html_import(self):
import html
import html.entities
import html.parser
self.assertTrue(True)
def replace_entity(match):
"""Return the character corresponding to an HTML entity."""
number = match.group(2)
if number:
hex = match.group(1) is not None
result = chr(int(number, html.entities.html5)
return result
def error(self, str(message).rstrip('\r .'))
if line in self.errors:
self.errors[line].append(message)
else:
self.errors[line] = [message]
def test_future_moves(self):
"""
Ensure everything is available from the future.moves interface that we
claim and expect. (Issue #104).
"""
from future.moves.collections import Counter, OrderedDict # backported to Py2.6
from future.moves.collections import UserDict, UserList, UserString
from future.moves import configparser
from future.moves import copyreg
from future.moves.itertools import filterfalse, zip_longest
from future.moves import html
import future.moves.html.entities
import future.moves.html.parser
from future.moves import http
import future.moves.http.client
import future.moves.http.cookies
import future.moves.http.cookiejar
import future.moves.http.server
from future.moves import queue
from future.moves import socketserver
from future.moves.subprocess import check_output # even on Py2.6
from future.moves.subprocess import getoutput, getstatusoutput
from future.moves.sys import intern
from future.moves import urllib
import future.moves.urllib.error
import future.moves.urllib.parse
import future.moves.urllib.request
import future.moves.urllib.response
import future.moves.urllib.robotparser
try:
# Is _winreg available on Py2? If so,ensure future.moves._winreg is available too:
import _winreg
except ImportError:
pass
else:
from future.moves import winreg
from future.moves import xmlrpc
import future.moves.xmlrpc.client
import future.moves.xmlrpc.server
from future.moves import _dummy_thread
from future.moves import _markupbase
from future.moves import _thread
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。