X-Git-Url: https://git.phdru.name/?p=bookmarks_db.git;a=blobdiff_plain;f=bkmk_objects.py;h=6897721da802123064222a0ebac2c81b65081b14;hp=7777ba33fc0bb9b35a862690e9d95238d355374e;hb=HEAD;hpb=b2b302b348f0b711557961c70744c818cff664f0 diff --git a/bkmk_objects.py b/bkmk_objects.py index 7777ba3..bf5904b 100644 --- a/bkmk_objects.py +++ b/bkmk_objects.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2000-2023 PhiloSoft Design" +__copyright__ = "Copyright (C) 2000-2024 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['Folder', 'Bookmark', 'Ruler', 'Walker', 'Writer', 'Robot', @@ -14,8 +14,8 @@ __all__ = ['Folder', 'Bookmark', 'Ruler', 'Walker', 'Writer', 'Robot', ] +from urllib.parse import unquote import os -import urllib BKMK_FORMAT = os.environ.get("BKMK_FORMAT", "MOZILLA") @@ -58,32 +58,6 @@ 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) - - if protocol == 'place': - href = protocol + ":" - else: - href = protocol + "://" - if user: - href += urllib.quote(user) - if password: - href += ':' + urllib.quote(password) - href += '@' - if host: - href += host.decode(parser_charset or 'utf-8').encode('idna') - if port: - href += ':%d' % port - if path: - href += path - self.href = href self.add_date = add_date self.last_visit = last_visit @@ -152,7 +126,8 @@ class InverseLinker(Walker): def start_folder(self, f, level): f.parent = self.parent_stack[-1] - self.parent_stack.append(f) # Push the folder onto the stack of parents + # Push the folder onto the stack of parents + self.parent_stack.append(f) def end_folder(self, f, level): del self.parent_stack[-1] # Pop off the stack @@ -183,7 +158,8 @@ class Linear(Walker): self.add_object(r) -# Helper - make linked linear represenatation of the tree, suitable to be stored in sequential storage +# Helper - make linked linear represenatation of the tree, +# suitable to be stored in sequential storage. def make_linear(root_folder): linker = InverseLinker() root_folder.walk_depth(linker) @@ -192,7 +168,8 @@ def make_linear(root_folder): root_folder.walk_depth(linear) -# Helper, opposite of make_linear - make a tree from the linked linear representation +# Helper, opposite of make_linear - +# make a tree from the linked linear representation. def make_tree(linear): root_folder = linear[0] del linear[0] @@ -218,9 +195,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 @@ -230,7 +213,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