]
-import os, urllib
+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")
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)
+ protocol, request = splittype(href)
user, password, port = None, None, None
- host, path = urllib.splithost(request)
+ host, path = splithost(request)
if host:
- user, host = urllib.splituser(host)
+ user, host = splituser(host)
if user:
- user, password = urllib.splitpasswd(user)
- host, port = urllib.splitport(host)
+ user, password = splitpasswd(user)
+ host, port = splitport(host)
if port: port = int(port)
if protocol == 'place':
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:
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
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)
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]
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("'", "'")
+ title = HTMLParser().unescape(
+ title.replace("&", '&'))
+ title = title.replace("'", "'")
return title