X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fparse_html.py;h=80d4a9243bbbec31b96d98a4881182afefd05361;hb=5f637b5a5fe27098985975928632b9fea5ea3c62;hp=ec93ea5acb0903e9557bc370559a0a0ebee4dd6e;hpb=3cb1b83ad134cc67669ff52cfed5662c80bbade4;p=bookmarks_db.git diff --git a/Robots/parse_html.py b/Robots/parse_html.py index ec93ea5..80d4a92 100755 --- a/Robots/parse_html.py +++ b/Robots/parse_html.py @@ -67,7 +67,7 @@ def parse_html(filename, charset=None, log=None): parser = None for c in charsets: try: - parser = p(filename, c) + parser = p(filename, c, log) break except UnicodeEncodeError: pass @@ -86,23 +86,26 @@ def parse_html(filename, charset=None, log=None): if parser.charset: parser.charset = parser.charset.lower().replace("windows-", "cp") - if parser.charset and (parser.charset <> universal_charset): + if parser.charset and ( + (parser.charset <> universal_charset) or + ((not charset) or (charset <> parser.charset))): try: if parser.meta_charset: if log: log(" META charset : %s" % parser.charset) - elif (not charset) or charset <> parser.charset: + elif (not charset) or (charset <> parser.charset): if log: log(" guessed charset: %s" % parser.charset) if log: log(" current charset: %s" % universal_charset) if log: log(" title : %s" % title) - try: - converted_title = unicode(title, parser.charset).encode(universal_charset) - except UnicodeError: - if log: log(" incorrect conversion from %s, converting from %s" % (parser.charset, DEFAULT_CHARSET)) - converted_title = unicode(title, DEFAULT_CHARSET, "replace").encode(universal_charset, "replace") - parser.charset = DEFAULT_CHARSET + if parser.charset <> universal_charset: + try: + converted_title = unicode(title, parser.charset).encode(universal_charset) + except UnicodeError: + if log: log(" incorrect conversion from %s, converting from %s" % (parser.charset, DEFAULT_CHARSET)) + converted_title = unicode(title, DEFAULT_CHARSET, "replace").encode(universal_charset, "replace") + parser.charset = DEFAULT_CHARSET if log and (converted_title <> title): log(" converted title: %s" % converted_title) except LookupError: - if log: log(" unknown charset: `%s' or `%s'" % (parser.charset, universal_charset)) + if log: log(" unknown charset: '%s'" % parser.charset) else: if log: log(" title : %s" % title)