我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用html.entities()。
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, 16 if hex else 10)) else: entity = match.group(3) result = unescape(entity, html.entities.html5) return result
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 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