]> git.phdru.name Git - bookmarks_db.git/commitdiff
Fix(Py3): Replace `unicode()` with `.decode()`
authorOleg Broytman <phd@phdru.name>
Mon, 11 Sep 2023 14:06:44 +0000 (17:06 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 12 Nov 2023 10:28:41 +0000 (13:28 +0300)
bkmk_parser.py
parse_html/bkmk_parse_html.py
parse_html/bkmk_ph_beautifulsoup.py
parse_html/bkmk_ph_beautifulsoup4.py

index 420d20f7f2b4c07ed4266a357cc9016ee537dae3..42c0712d79b9bf2f8602d427f7a79b9f8bf0e262 100644 (file)
@@ -48,7 +48,7 @@ class BkmkParser(HTMLParser):
     def handle_data(self, data):
         if data:
             if self.charset and default_encoding:
-                data = unicode(data, self.charset, "replace").\
+                data = data.decode(self.charset, "replace").\
                     encode(default_encoding, "xmlcharrefreplace")
             self.accumulator += data
 
index 6afb7f9df735f6a487b6b7537fc23f2c3daa71c2..997bf6489c9a2e49a44c74d1062a61aa85191cf5 100644 (file)
@@ -167,7 +167,7 @@ def parse_html(html_text, charset=None, log=None):
     converted_title = title = parser.title
     if title and (not parser.charset):
         try:
-            unicode(title, "ascii")
+            title.decode("ascii")
         except UnicodeDecodeError:
             parser.charset = DEFAULT_CHARSET
 
@@ -186,7 +186,7 @@ def parse_html(html_text, charset=None, log=None):
             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:
@@ -194,7 +194,7 @@ def parse_html(html_text, charset=None, log=None):
                             "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):
index f2f042e33b18aae1303f5fdbfa5f365f7aeeca78..e29b4997932d764d29ebc290b9f407ec796a8063 100644 (file)
@@ -96,7 +96,7 @@ def parse_html(html_text, charset=None, log=None):
             parts = []
             for part in title:
                 if not isinstance(part, basestring):
-                    part = unicode(part)
+                    part = part.decode()
                 parts.append(part.strip())
             title = ''.join(parts)
 
index e1662ed9e84b9866fceef5f72c0744b35b870111..1f77eb794be2c849f4eee824bb4ddbd62eb44488 100644 (file)
@@ -55,7 +55,7 @@ def parse_html(html_text, charset=None, log=None):
             parts = []
             for part in title:
                 if not isinstance(part, basestring):
-                    part = unicode(part)
+                    part = part.decode()
                 parts.append(part.strip())
             title = ''.join(parts)