本文整理汇总了Python中htmlentitydefs.entitydefs方法的典型用法代码示例。如果您正苦于以下问题:Python htmlentitydefs.entitydefs方法的具体用法?Python htmlentitydefs.entitydefs怎么用?Python htmlentitydefs.entitydefs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htmlentitydefs
的用法示例。
在下文中一共展示了htmlentitydefs.entitydefs方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_entityref
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def handle_entityref(self, ref):
# called for each entity reference, e.g. for '©', ref will be 'copy'
if not self.elementstack: return
if _debug: sys.stderr.write('entering handle_entityref with %s\n' % ref)
if ref in ('lt', 'gt', 'quot', 'amp', 'apos'):
text = '&%s;' % ref
else:
# entity resolution graciously donated by Aaron Swartz
def name2cp(k):
import htmlentitydefs
if hasattr(htmlentitydefs, 'name2codepoint'): # requires Python 2.3
return htmlentitydefs.name2codepoint[k]
k = htmlentitydefs.entitydefs[k]
if k.startswith('&#') and k.endswith(';'):
return int(k[2:-1]) # not in latin-1
return ord(k)
try: name2cp(ref)
except KeyError: text = '&%s;' % ref
else: text = unichr(name2cp(ref)).encode('utf-8')
self.elementstack[-1][2].append(text)
示例2: descape_entity
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def descape_entity(m, defs=htmlentitydefs.entitydefs):
"""
Translate one entity to its ISO Latin value.
Inspired by example from effbot.org
"""
#s = 'mcglashan_&_sarrail'
#l = ['mcglashan', '&', 'sarrail']
#pattern = re.compile("&(\w+?);")
#new = list2sym(l)
#s = pattern.sub(descape_entity, s)
#print s, new
try:
return defs[m.group(1)]
except KeyError:
return m.group(0) # use as is
示例3: __init__
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def __init__(self, html=0):
try:
import sgmlop
except ImportError:
raise RuntimeError("sgmlop parser not available")
self.__builder = ElementTree.TreeBuilder()
if html:
import htmlentitydefs
self.entitydefs.update(htmlentitydefs.entitydefs)
self.__parser = sgmlop.XMLParser()
self.__parser.register(self)
##
# Feeds data to the parser.
#
# @param data Encoded data.
示例4: __init__
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def __init__(self, html=0, target=None, encoding=None):
self.__builder = ElementTree.TreeBuilder()
if html:
import htmlentitydefs
self.entitydefs.update(htmlentitydefs.entitydefs)
xmllib.XMLParser.__init__(self)
##
# Feeds data to the parser.
#
# @param data Encoded data.
示例5: name2cp
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def name2cp(k):
if k == 'apos': return ord("'")
if hasattr(htmlentitydefs, "name2codepoint"): # requires Python 2.3
return htmlentitydefs.name2codepoint[k]
else:
k = htmlentitydefs.entitydefs[k]
if k.startswith("&#") and k.endswith(";"): return int(k[2:-1]) # not in latin-1
return ord(codecs.latin_1_decode(k)[0])
示例6: html_entity_decode_char
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def html_entity_decode_char(m, defs=htmlentitydefs.entitydefs):
try:
return defs[m.group(1)]
except KeyError:
return m.group(0)
示例7: handle_entityref
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def handle_entityref(self, ref):
if self.in_disallowed[-1]:
return
elif ref in entitydefs:
self.result += '&%s;' % ref
else:
self.result += xmlescape('&%s' % ref)
示例8: handle_entityref
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def handle_entityref(self, ref):
if ref in entitydefs:
self.result += '&%s;' % ref
else:
self.result += xssescape('&%s' % ref)
示例9: __init__
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def __init__(self, html=0):
self.__builder = ElementTree.TreeBuilder()
if html:
import htmlentitydefs
self.entitydefs.update(htmlentitydefs.entitydefs)
xmllib.XMLParser.__init__(self)
##
# Feeds data to the parser.
#
# @param data Encoded data.
示例10: handle_entityref
# 需要导入模块: import htmlentitydefs [as 别名]
# 或者: from htmlentitydefs import entitydefs [as 别名]
def handle_entityref(self, ref):
if self.in_disallowed:
return
elif ref in entitydefs:
self.result += '&%s;' % ref
else:
self.result += xssescape('&%s' % ref)