]> git.phdru.name Git - bookmarks_db.git/commitdiff
Fix(Py3): Use `urllib.parse.urlsplit()`
authorOleg Broytman <phd@phdru.name>
Tue, 28 Nov 2023 17:04:18 +0000 (20:04 +0300)
committerOleg Broytman <phd@phdru.name>
Tue, 28 Nov 2023 17:04:39 +0000 (20:04 +0300)
Robots/bkmk_robot_base.py
bkmk_objects.py

index c5afd3fdc0aef90c1db8f69551e64c37e7c70882..2024ab85efd74594eb4700078f19f7e012ae2b78 100644 (file)
@@ -12,14 +12,10 @@ __all__ = ['robot_base', 'get_error']
 
 
 from base64 import b64encode
+from urllib.parse import urlsplit, urljoin
 import sys
 import socket
 import time
-try:
-    from urllib.parse import splittype, splithost, splittag, urljoin
-except ImportError:
-    from urllib import splittype, splithost, splittag
-    from urlparse import urljoin
 
 from m_lib.md5wrapper import md5wrapper
 from m_lib.net.www.util import parse_time
@@ -66,10 +62,9 @@ class robot_base(Robot):
             self.start = int(time.time())
             bookmark.icon = None
 
-            url_type, url_rest = splittype(bookmark.href)
-            url_host, url_path = splithost(url_rest)
-            url_path, url_tag  = splittag(url_path)  # noqa: E221
-            #                    multiple spaces before operator
+            split_results = urlsplit(bookmark.href)
+            url_type, netloc, url_path, query, url_tag = split_results
+            url_host = split_results.hostname
 
             url = "%s://%s%s" % (url_type, url_host, url_path)
             error, redirect_code, redirect_to, headers, content = \
index 741567039d7763077e1255ef162e6f09bb498e28..1f27c988ec8b7956942064ddbb1885aebd64dfb3 100644 (file)
@@ -14,15 +14,8 @@ __all__ = ['Folder', 'Bookmark', 'Ruler', 'Walker', 'Writer', 'Robot',
            ]
 
 
+from urllib.parse import urlsplit, quote
 import os
-try:
-    from urllib.parse import quote, \
-        splittype, splithost, splituser, splitpasswd, \
-        splitport
-except ImportError:
-    from urllib import quote, \
-        splittype, splithost, splituser, splitpasswd, \
-        splitport
 
 BKMK_FORMAT = os.environ.get("BKMK_FORMAT", "MOZILLA")
 
@@ -65,15 +58,12 @@ 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 = splittype(href)
-        user, password, port = None, None, None
-        host, path = splithost(request)
-        if host:
-            user, host = splituser(host)
-            if user:
-                user, password = splitpasswd(user)
-            host, port = 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 + ":"