mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-01 11:34:41 +00:00
Python3: fix few htmllib problems
This commit is contained in:
parent
205ceb6805
commit
2daf685633
1 changed files with 11 additions and 4 deletions
|
|
@ -19,6 +19,8 @@ Default HTML parser handler classes.
|
|||
"""
|
||||
|
||||
import sys
|
||||
from builtins import bytes, str as str_text
|
||||
from builtins import chr
|
||||
|
||||
|
||||
class HtmlPrinter (object):
|
||||
|
|
@ -43,7 +45,8 @@ class HtmlPrinter (object):
|
|||
@type attrs: tuple
|
||||
@return: None
|
||||
"""
|
||||
print >> self.fd, self.mem, attrs
|
||||
self.fd.write(self.mem)
|
||||
self.fd.write(str_text(attrs))
|
||||
|
||||
def __getattr__ (self, name):
|
||||
"""
|
||||
|
|
@ -201,14 +204,18 @@ def quote_attrval (s):
|
|||
"""
|
||||
res = []
|
||||
for c in s:
|
||||
if ord(c) <= 127:
|
||||
try: # Python 2
|
||||
ord_c = ord(c)
|
||||
except TypeError:
|
||||
ord_c = c
|
||||
if ord_c <= 127:
|
||||
# ASCII
|
||||
if c == u'&':
|
||||
res.append(u"&")
|
||||
elif c == u'"':
|
||||
res.append(u""")
|
||||
else:
|
||||
res.append(c)
|
||||
res.append(chr(ord_c))
|
||||
else:
|
||||
res.append(u"&#%d;" % ord(c))
|
||||
res.append(u"&#%d;" % ord_c)
|
||||
return u"".join(res)
|
||||
|
|
|
|||
Loading…
Reference in a new issue