]> git.phdru.name Git - bookmarks_db.git/blobdiff - bkmk_objects.py
Style(Robots/bkmk_rurllib_py3): Remove unused variable
[bookmarks_db.git] / bkmk_objects.py
index 89647aa52eb57ecced2d4681834bba4b79f4ffaf..bd5c71377bda4e71d3ee7322567a4a68516ff2b5 100644 (file)
@@ -14,8 +14,8 @@ __all__ = ['Folder', 'Bookmark', 'Ruler', 'Walker', 'Writer', 'Robot',
            ]
 
 
+from urllib.parse import urlsplit, quote, unquote
 import os
-import urllib
 
 BKMK_FORMAT = os.environ.get("BKMK_FORMAT", "MOZILLA")
 
@@ -58,27 +58,24 @@ class Bookmark(object):
     def __init__(self, href, add_date, last_visit=None, last_modified=None,
                  keyword=None, comment='', icon_href=None, icon=None,
                  charset=None, parser_charset=None):
-        protocol, request = urllib.splittype(href)
-        user, password, port = None, None, None
-        host, path = urllib.splithost(request)
-        if host:
-            user, host = urllib.splituser(host)
-            if user:
-                user, password = urllib.splitpasswd(user)
-            host, port = urllib.splitport(host)
-            if port: port = int(port)
+        split_results = urlsplit(href)
+        protocol, netloc, path, query, tag = split_results
+        user = split_results.username
+        password = split_results.password
+        host = split_results.hostname
+        port = split_results.port
 
         if protocol == 'place':
             href = protocol + ":"
         else:
             href = protocol + "://"
         if user:
-            href += urllib.quote(user)
+            href += quote(user)
             if password:
-                href += ':' + urllib.quote(password)
+                href += ':' + quote(password)
             href += '@'
         if host:
-            href += host.decode(parser_charset or 'utf-8').encode('idna')
+            href += host.encode('idna').decode('ascii')
             if port:
                 href += ':%d' % port
         if path:
@@ -221,10 +218,15 @@ def quote_title(title):
 
 def unquote_title(title):
     if BKMK_FORMAT == "MOZILLA":
-        from HTMLParser import HTMLParser
-        title = HTMLParser().unescape(
-            title.replace("&", '&').decode('utf-8'))
-        title = title.encode('utf-8').replace("'", "'")
+        try:
+            from HTMLParser import HTMLParser
+        except ImportError:
+            from html import unescape
+        else:
+            unescape = HTMLParser().unescape
+        title = unescape(
+            title.replace("&", '&'))
+        title = title.replace("'", "'")
     return title
 
 
@@ -234,7 +236,7 @@ def parse_params(param_str):
     param_list = {}
     for param in params:
         key, value = param.split('=', 1)
-        param_list[key] = value
+        param_list[key] = unquote(value)
     return main_param, param_list