]> git.phdru.name Git - bookmarks_db.git/blobdiff - bkmk_parser.py
Fix(Py3): Stop using module `string`
[bookmarks_db.git] / bkmk_parser.py
index 00cfcd4c4ce298efc4d4da643b188b391230f325..0cd8f1fe711a7fd00abe8feaecffb89d79a8d303 100644 (file)
@@ -16,18 +16,18 @@ from m_lib.net.www.html import HTMLParser
 from bkmk_objects import Folder, Bookmark, Ruler
 
 
-DEBUG = os.environ.has_key("BKMK_DEBUG")
+DEBUG = "BKMK_DEBUG" in os.environ
 
 if DEBUG:
     def debug(note):
         print(note)
 
     def dump_names(folder_stack):
-        l = []
+        _l = []
         for object in folder_stack:
             if object.isFolder:
-                l.append(object.name)
-        return "'%s'" % "' '".join(l)
+                _l.append(object.name)
+        return "'%s'" % "' '".join(_l)
 
 else:
     def debug(note):
@@ -48,7 +48,8 @@ class BkmkParser(HTMLParser):
     def handle_data(self, data):
         if data:
             if self.charset and default_encoding:
-                data = unicode(data, self.charset, "replace").encode(default_encoding, "xmlcharrefreplace")
+                data = data.decode(self.charset, "replace").\
+                    encode(default_encoding, "xmlcharrefreplace")
             self.accumulator += data
 
     # Mozilla - get charset
@@ -72,7 +73,8 @@ class BkmkParser(HTMLParser):
 
     def start_title(self, attrs):
         if default_encoding:
-            self.accumulator += '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=%s">\n' % default_encoding
+            self.accumulator += '<META HTTP-EQUIV="Content-Type" '
+            'CONTENT="text/html; charset=%s">\n' % default_encoding
         self.accumulator += "<TITLE>"
 
     def end_title(self):