本文整理匯總了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)