import codecs
import os
+import re
+from htmlentitydefs import name2codepoint
+
+from compat import unicode, unichr
+
+DEFAULT_CHARSET = "cp1251" # Stupid default for Russian Cyrillic
+parsers = []
try:
from . import bkmk_ph_beautifulsoup4
# else:
# parsers.append(bkmk_ph_etreetidy.parse_html)
-import re
-from htmlentitydefs import name2codepoint
-
universal_charset = "utf-8"
-DEFAULT_CHARSET = "cp1251" # Stupid default for Russian Cyrillic
-
-parsers = []
-
-entity_re = re.compile("(&\w+;)")
+entity_re = re.compile("(&\\w+;)")
num_entity_re = re.compile("(&#[0-9]+;)")
converted_title = title = parser.title
if title and (not parser.charset):
try:
- unicode(title, "ascii")
+ title.decode("ascii")
except UnicodeDecodeError:
parser.charset = DEFAULT_CHARSET
if log: log(" title : %s" % title)
if parser.charset != universal_charset:
try:
- converted_title = unicode(title, parser.charset).\
+ converted_title = title.decode(parser.charset).\
encode(universal_charset)
except UnicodeError:
if log:
"converting from %s"
% (parser.charset, DEFAULT_CHARSET))
converted_title = \
- unicode(title, DEFAULT_CHARSET, "replace").\
+ title.decode(DEFAULT_CHARSET, "replace").\
encode(universal_charset, "replace")
parser.charset = DEFAULT_CHARSET
if log and (converted_title != title):