Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def description(item):
global name_to_oid, oid_to_desc, oid_to_name, oid_to_pid
oid = name_to_oid.get(item,0)
desc = oid_to_desc.get(oid, None)
if desc:
for a,b in entitydefs.items(): desc = desc.replace("&%s;"%a,b)
desc = desc.replace("\r","")
for r,s in regices: desc = r.sub(s,desc)
desc = desc.strip()
return desc.split("\n")
else: return []
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])
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])
string = re.sub(r'&[^;]+;', lambda m: entitydefs[m.group(0)[1:-1]], string)
return string
def entity_replacer(m):
entity = m.group(1)
if entity in entitydefs:
return entitydefs[entity]
else:
return m.group(0)
def html_entity_decode_char(self, m, defs=htmlentities.entitydefs):
"""
decode html entity into one of the html char
"""
try:
char = defs[m.group(1)]
return "&{char};".format(char=char)
except ValueError:
return m.group(0)
except KeyError:
return m.group(0)
def __init__(self, filename, encoding):
if isinstance( filename, StringIO.StringIO ):
self._file = filename
else:
self._file = open(filename, "wb") if filename else sys.stdout
self._encoding = encoding
# See which of the HTML entities of interest are supported by this encoding.
self._char_replacements = {}
for code_point,html_enity_name in entitydefs.codepoint2name.iteritems():
char = unichr(code_point)
try:
char.encode(encoding)
except UnicodeEncodeError:
self._char_replacements[char] = "&" + html_enity_name + ";"
self._char_replacements.update((unichr(i),".") for i in xrange(32) if unichr(i) not in u"\t\n\r")
self._dbg_saw_html = False
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])
def entity_replacer(m):
entity = m.group(1)
if entity in entitydefs:
return entitydefs[entity]
else:
return m.group(0)
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])