]> git.phdru.name Git - bookmarks_db.git/commitdiff
Style: Fix flake8 E501 line too long
authorOleg Broytman <phd@phdru.name>
Tue, 5 Sep 2023 17:55:16 +0000 (20:55 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 12 Nov 2023 10:24:32 +0000 (13:24 +0300)
26 files changed:
Robots/bkmk_rforking.py
Robots/bkmk_rforking_sub.py
Robots/bkmk_robot_base.py
Robots/bkmk_rurllib.py
Robots/bkmk_rurllib2.py
Storage/bkmk_stflad.py
Storage/bkmk_stjson.py
Writers/bkmk_wflad.py
Writers/bkmk_whtml.py
bkmk-add.py
bkmk2db.py
bkmk_objects.py
bkmk_parser.py
check_title.py
check_url.py
check_urls.py
db2bkmk.py
parse_html/__main__.py
parse_html/bkmk_parse_html.py
parse_html/bkmk_ph_beautifulsoup.py
parse_html/bkmk_ph_beautifulsoup4.py
parse_html/bkmk_ph_html5.py
parse_html/bkmk_ph_htmlparser.py
set-real_title.py
set-title-list.py
storage.py

index 30133dcb4011fcb908ddb6f011732adf5217fc40..e1281219c66974d70c1b8d538744638e99bfc315 100644 (file)
@@ -42,7 +42,8 @@ def restart_subp(log):
     global check_subp, subp_pipe
     stop_subp(log)
 
-    check_subp = Subprocess("%s/Robots/bkmk_rforking_sub.py" % os.path.dirname(sys.argv[0]),
+    check_subp = Subprocess("%s/Robots/bkmk_rforking_sub.py"
+                            % os.path.dirname(sys.argv[0]),
                             control_stderr=True)
     subp_pipe = RecordFile(check_subp)
 
@@ -62,7 +63,9 @@ class robot_forking(Robot):
             subproc_attrs = []
             for attr in dir(self):
                 if attr.startswith('subproc_'):
-                    subproc_attrs.append((attr[len('subproc_'):], getattr(self, attr)))
+                    subproc_attrs.append(
+                        (attr[len('subproc_'):], getattr(self, attr))
+                    )
             if subproc_attrs:
                 subproc += ':' + ':'.join(
                     ['='.join((k, v)) for k, v in subproc_attrs]
index f0bb9129b78059f4f8978c300df59416581de57f..2f444ab0045338deef4408363ae753b16f12b5f9 100755 (executable)
@@ -23,7 +23,7 @@ except ImportError:
 
 from subproc import RecordFile
 
-lib_dir = os.path.normpath(os.path.join(os.path.dirname(sys.argv[0]), os.pardir))
+lib_dir = os.path.normpath(os.path.dirname(os.path.dirname(sys.argv[0])))
 sys.path.append(lib_dir)  # for bkmk_objects.py
 
 
index 9c9d8c5823543bc442472274068da5acbf8417b0..d6a87d31cd41682ee3d48549868442814a15cebe 100644 (file)
@@ -68,7 +68,8 @@ class robot_base(Robot):
             #                            multiple spaces before operator
 
             url = "%s://%s%s" % (url_type, url_host, url_path)
-            error, redirect_code, redirect_to, headers, content = self.get(bookmark, url, True)
+            error, redirect_code, redirect_to, headers, content = \
+                self.get(bookmark, url, True)
 
             if error:
                 bookmark.error = error
@@ -117,7 +118,8 @@ class robot_base(Robot):
                     content_type = headers["Content-Type"]
                     self.log("   Content-Type: %s" % content_type)
                     try:
-                        # extract charset from "text/html; foo; charset=UTF-8, bar; baz;"
+                        # extract charset from
+                        # "text/html; foo; charset=UTF-8, bar; baz;"
                         content_type, charset = content_type.split(';', 1)
                         content_type = content_type.strip()
                         charset = charset.split('=')[1].strip().split(',')[0]
@@ -140,7 +142,8 @@ class robot_base(Robot):
                             icon = None
                         if not icon:
                             icon = "/favicon.ico"
-                        icon_url = urljoin("%s://%s%s" % (url_type, url_host, url_path), icon)
+                        icon_url = urljoin(
+                            "%s://%s%s" % (url_type, url_host, url_path), icon)
                         self.log("   looking for icon at: %s" % icon_url)
                         if icon_url in icons:
                             if icons[icon_url]:
@@ -153,12 +156,14 @@ class robot_base(Robot):
                             try:
                                 _icon_url = icon_url
                                 for i in range(8):
-                                    error, icon_redirect_code, icon_redirect_to, \
-                                        icon_headers, icon_data = \
+                                    error, icon_redirect_code, \
+                                        icon_redirect_to, icon_headers, \
+                                        icon_data = \
                                         self.get(bookmark, _icon_url)
                                     if icon_redirect_code:
                                         _icon_url = icon_redirect_to
-                                        self.log("   redirect to : %s" % _icon_url)
+                                        self.log("   redirect to : %s"
+                                                 % _icon_url)
                                     else:
                                         if icon_data is None:
                                             raise IOError("No icon")
@@ -167,7 +172,8 @@ class robot_base(Robot):
                                     raise IOError("Too many redirects")
                             except:
                                 etype, emsg, tb = sys.exc_info()
-                                self.log("   no icon        : %s %s" % (etype, emsg))
+                                self.log("   no icon        : %s %s"
+                                         % (etype, emsg))
                                 etype = emsg = tb = None
                                 icons[icon_url] = None
                             else:
@@ -176,15 +182,26 @@ class robot_base(Robot):
                                    or content_type.startswith("image/") \
                                    or content_type.startswith("text/plain"):
                                     bookmark.icon_href = icon_url
-                                    self.log("   got icon       : %s" % content_type)
-                                    if content_type.startswith("application/") \
-                                       or content_type.startswith("text/plain"):
-                                        self.log("   non-image content type, assume x-icon")
+                                    self.log("   got icon       : %s"
+                                             % content_type)
+                                    if (
+                                        content_type.startswith("application/")
+                                        or content_type.startswith(
+                                            "text/plain")
+                                    ):
+                                        self.log("   non-image content type,"
+                                                 " assume x-icon")
                                         content_type = 'image/x-icon'
-                                    bookmark.icon = "data:%s;base64,%s" % (content_type, b64encode(icon_data))
-                                    icons[icon_url] = (content_type, bookmark.icon)
+                                    bookmark.icon = "data:%s;base64,%s" \
+                                        % (content_type, b64encode(icon_data))
+                                    icons[icon_url] = (content_type,
+                                                       bookmark.icon
+                                                       )
                                 else:
-                                    self.log("   no icon        : bad content type '%s'" % content_type)
+                                    self.log("   no icon        :"
+                                             "bad content type '%s'"
+                                             % content_type
+                                             )
                                     icons[icon_url] = None
                         if parser and parser.refresh:
                             refresh = parser.refresh
@@ -195,13 +212,19 @@ class robot_base(Robot):
                             try:
                                 timeout = float(refresh.split(';')[0])
                             except (IndexError, ValueError):
-                                self.set_redirect(bookmark, "html", "Bad redirect to %s (%s)" % (url, refresh))
+                                self.set_redirect(bookmark, "html",
+                                                  "Bad redirect to %s (%s)"
+                                                  % (url, refresh)
+                                                  )
                             else:
                                 try:
                                     timeout = int(refresh.split(';')[0])
                                 except ValueError:
                                     pass  # float timeout
-                                self.set_redirect(bookmark, "html", "%s (%s sec)" % (url, timeout))
+                                self.set_redirect(bookmark, "html",
+                                                  "%s (%s sec)"
+                                                  % (url, timeout)
+                                                  )
 
                 except KeyError as key:
                     self.log("   no header: %s" % key)
index 29421f1624b7926cd86a6791000dd062755a72bb..20b74239b8fb55fc184b08e2cf686ce8ca150983 100644 (file)
@@ -46,7 +46,8 @@ class MyURLopener(urllib.URLopener):
 
     # Error 401 -- authentication required
     def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
-        raise IOError(('http error', errcode, "Authentication required ", headers))
+        raise IOError(
+            ('http error', errcode, "Authentication required ", headers))
 
     def http_error_default(self, url, fp, errcode, errmsg, headers):
         if fp:
@@ -58,10 +59,13 @@ class MyURLopener(urllib.URLopener):
 urllib._urlopener = MyURLopener()
 
 # Fake headers to pretend this is a real browser
-_user_agent = "Mozilla/5.0 (X11; U; Linux 2.6 i686; en) Gecko/20001221 Firefox/2.0.0"
+_user_agent = "Mozilla/5.0 (X11; U; Linux 2.6 i686; en)"
+" Gecko/20001221 Firefox/2.0.0"
 urllib._urlopener.addheaders[0] = ('User-Agent', _user_agent)
 _x_user_agent = "bookmarks_db (Python %d.%d.%d; urllib/%s)" % (
-   sys.version_info[0], sys.version_info[1], sys.version_info[2], urllib.__version__)
+   sys.version_info[0], sys.version_info[1],
+   sys.version_info[2], urllib.__version__
+)
 urllib._urlopener.addheader('X-User-Agent', _x_user_agent)
 urllib._urlopener.addheader('Referer', '')
 
@@ -97,7 +101,8 @@ class robot_urllib(robot_base):
                 fname, headers = urllib.urlretrieve(url)
             finally:
                 if accept_charset and bookmark.charset:
-                    del urllib._urlopener.addheaders[-1]  # Remove Accept-Charset
+                    # Remove Accept-Charset
+                    del urllib._urlopener.addheaders[-1]
 
             infile = open(fname, 'rb')
             content = infile.read()
@@ -111,7 +116,8 @@ class robot_urllib(robot_base):
         except IOError as e:
             if (e[0] == "http error") and (e[1] == -1):
                 error = None
-                bookmark.no_error = "The server did not return any header - it is not an error, actually"
+                bookmark.no_error = "The server did not return any header - "
+                    "it is not an error, actually"
                 self.log('   no headers: %s' % bookmark.no_error)
             else:
                 error = get_error(e)
index 4cb684bae94fbc642f9af0a4594783f15fab3be8..66f04600135d648b281e52952a3e53c84d44bc22 100644 (file)
@@ -40,7 +40,8 @@ urllib2.install_opener(opener)
 
 
 # Fake headers to pretend this is a real browser
-_user_agent = "Mozilla/5.0 (X11; Linux i686; rv:30.0) Gecko/20100101 Firefox/30.0"
+_user_agent = "Mozilla/5.0 (X11; Linux i686; rv:30.0)"
+" Gecko/20100101 Firefox/30.0"
 _x_user_agent = "bookmarks_db (Python %d.%d.%d; urllib2)" % (
     sys.version_info[0], sys.version_info[1], sys.version_info[2])
 
@@ -69,7 +70,8 @@ class robot_urllib2(robot_base):
                 return None, e.code, e.hdrs['Location'], None, None
             else:
                 self.log('   HTTP Error %s: %s' % (e.code, e.msg))
-                return "HTTP Error %s: %s" % (e.code, e.msg), None, None, None, None
+                return ("HTTP Error %s: %s" % (e.code, e.msg),
+                        None, None, None, None)
 
         except urllib2.URLError as e:
             self.log('   URL Error: %s' % e.reason)
index 8965bbeda649afdc78e9b8382e31d61b0ac7dc05..156e956f7244fdc09809646917d12a707d6821d7 100644 (file)
@@ -77,7 +77,8 @@ Charset: %s
             self.current_folder = None
 
     def load(self):
-        bookmarks_db = fladm.load_from_file(self.filename, fladm.check_record, ["Level"])
+        bookmarks_db = fladm.load_from_file(
+            self.filename, fladm.check_record, ["Level"])
 
         root_folder = Folder()
         self.folder_stack = [root_folder]
@@ -106,10 +107,12 @@ Charset: %s
             elif level <= save_level - 1:
                 self.unindent(save_level, level)
             else:
-                raise ValueError("new level (%d) too big; must be %d - %d" % (level, save_level-1, save_level+1))
+                raise ValueError("new level (%d) too big; must be %d - %d"
+                                 % (level, save_level-1, save_level+1))
 
             save_level = level
-            got_folder = record.has_key("Folder")  # Test here to save got_folder for next loop
+            # Test here to save got_folder for next loop
+            got_folder = record.has_key("Folder")
 
             if record.has_key("URL"):
                 comment = record["Comment"].replace("\\n", '\n')
@@ -121,7 +124,10 @@ Charset: %s
                 self.current_folder.append(bookmark)
 
             elif record.has_key("Folder"):
-                folder = Folder(record["AddDate"], record["Comment"], record["LastModified"])
+                folder = Folder(
+                    record["AddDate"], record["Comment"],
+                    record["LastModified"]
+                )
                 folder.name = record["Folder"]
                 self.current_folder.append(folder)
                 self.folder_stack.append(folder)
@@ -131,11 +137,15 @@ Charset: %s
                 self.current_folder.append(Ruler())
 
             else:
-                raise KeyError("neither \"URL\" nor \"Folder\" nor \"Ruler\" in record " + str(record))
+                raise KeyError(
+                    'neither "URL" nor "Folder" nor "Ruler" in record '
+                    + str(record)
+                )
 
         if save_level >= 0:
             self.unindent(save_level, 0)
         else:
-            raise ValueError("new level (%d) too little - must be >= 0" % save_level)
+            raise ValueError("new level (%d) too little - must be >= 0"
+                             % save_level)
 
         return root_folder
index 1a34e3a1a02658c75dbe3736e207261009893d4a..0b34ecb079e005c41a4d37f29b0804129401185f 100644 (file)
@@ -108,9 +108,11 @@ class storage_json(Walker):
 
         root_folder = Folder()
         root_folder.header = ''
-        root_folder.add_date = convert_date_from_json(bookmarks_dict.get("dateAdded"))
+        root_folder.add_date = convert_date_from_json(
+            bookmarks_dict.get("dateAdded"))
         root_folder.comment = ''
-        root_folder.last_modified = convert_date_from_json(bookmarks_dict.get("lastModified"))
+        root_folder.last_modified = convert_date_from_json(
+            bookmarks_dict.get("lastModified"))
         self.folder_stack = [root_folder]
         self.current_folder = root_folder
 
@@ -120,7 +122,8 @@ class storage_json(Walker):
             bookmarks_dict["type"] = "text/x-moz-place-container"
         self.load_folder(root_folder, bookmarks_dict)
         if self.folder_stack:
-            raise RuntimeError('Excessive folder stack: %s' % self.folder_stack)
+            raise RuntimeError('Excessive folder stack: %s'
+                               % self.folder_stack)
 
         return root_folder
 
@@ -138,9 +141,11 @@ class storage_json(Walker):
             for record in fdict["children"]:
                 if record["type"] == "text/x-moz-place-container":
                     folder = Folder(
-                        add_date=convert_date_from_json(record.get("dateAdded")),
+                        add_date=convert_date_from_json(
+                            record.get("dateAdded")),
                         comment=get_comment(record.get("annos")),
-                        last_modified=convert_date_from_json(record.get("lastModified")))
+                        last_modified=convert_date_from_json(
+                            record.get("lastModified")))
                     folder.guid = record.get("guid")
                     self.current_folder.append(folder)
                     self.folder_stack.append(folder)
@@ -150,8 +155,10 @@ class storage_json(Walker):
                 elif record["type"] == "text/x-moz-place":
                     bookmark = Bookmark(
                         href=record["uri"].encode('utf-8'),
-                        add_date=convert_date_from_json(record.get("dateAdded")),
-                        last_modified=convert_date_from_json(record.get("lastModified")),
+                        add_date=convert_date_from_json(
+                            record.get("dateAdded")),
+                        last_modified=convert_date_from_json(
+                            record.get("lastModified")),
                         keyword=get_str(record, "keyword"),
                         comment=get_comment(record.get("annos")),
                         icon_href=record.get("iconuri"),
@@ -164,17 +171,20 @@ class storage_json(Walker):
 
                 elif record["type"] == "text/x-moz-place-separator":
                     ruler = Ruler()
-                    ruler.add_date = convert_date_from_json(record.get("dateAdded"))
+                    ruler.add_date = convert_date_from_json(
+                        record.get("dateAdded"))
                     ruler.guid = record.get("guid")
                     ruler.id = record["id"]
                     ruler.index = record["index"]
-                    ruler.last_modified = convert_date_from_json(record.get("lastModified"))
+                    ruler.last_modified = convert_date_from_json(
+                        record.get("lastModified"))
                     ruler.name = encode_title(record.get("title"))
                     ruler.comment = get_comment(record.get("annos"))
                     self.current_folder.append(ruler)
 
                 else:
-                    raise ValueError('Unknown record type "%s"' % record["type"])
+                    raise ValueError('Unknown record type "%s"'
+                                     % record["type"])
 
         del self.folder_stack[-1]
         if self.folder_stack:
index 64542bbdf929f262cc4d3af089de498a2fc8adf4..0d1acbb96d1d896e49ef6e5e4fbca1924f5e15b1 100644 (file)
@@ -35,7 +35,10 @@ Folder: %s
 AddDate: %s
 Comment: %s
 LastModified: %s
-""" % (level, f.name, strftime(f.add_date), f.comment, strftime(f.last_modified)))
+""" % (
+            level, f.name, strftime(f.add_date), f.comment,
+            strftime(f.last_modified))
+        )
 
     def bookmark(self, b, level):
         self.outfile.write("""
@@ -46,7 +49,11 @@ AddDate: %s
 LastVisit: %s
 LastModified: %s
 Keyword: %s
-Comment: %s""" % (level+1, b.name, b.href, strftime(b.add_date), strftime(b.last_visit), strftime(b.last_modified), b.keyword, b.comment))
+Comment: %s""" % (
+            level+1, b.name, b.href, strftime(b.add_date),
+            strftime(b.last_visit), strftime(b.last_modified),
+            b.keyword, b.comment)
+        )
 
         for attr_name, attr_out in (
             ("error", "Error"), ("no_error", "NoError"),
@@ -61,7 +68,7 @@ Comment: %s""" % (level+1, b.name, b.href, strftime(b.add_date), strftime(b.last
                 self.outfile.write("\n%s: %s" % (attr_out, value))
 
         if hasattr(b, "last_tested"):
-            self.outfile.write("\n%s: %s" % ("LastTested", strftime(getattr(b, "last_tested"))))
+            self.outfile.write("\nLastTested: %s" % strftime(b.last_tested))
 
         self.outfile.write("\n")
 
index a9e46e872d3500f89c56b15950258395825de6ef..058053d01131f5bb6057f7ca6499e4cb1de79993 100644 (file)
@@ -39,7 +39,8 @@ class writer_html(Writer):
 
     def start_folder(self, f, level):
         self.outfile.write(ind_s*level + '<DT><H3 ADD_DATE="%s"' % f.add_date)
-        if (BKMK_FORMAT == "MOZILLA") and f.last_modified: self.outfile.write(' LAST_MODIFIED="%s"' % f.last_modified)
+        if (BKMK_FORMAT == "MOZILLA") and f.last_modified:
+            self.outfile.write(' LAST_MODIFIED="%s"' % f.last_modified)
         self.outfile.write('>%s</H3>\n' % quote_title(f.name))
         self._folder(f, level)
 
@@ -47,7 +48,8 @@ class writer_html(Writer):
         self.outfile.write(ind_s*level + "</DL><p>\n")
 
     def bookmark(self, b, level):
-        self.outfile.write(ind_s*(level+1) + '<DT><A HREF="%s" ADD_DATE="%s"' % (b.href, b.add_date))
+        self.outfile.write(ind_s*(level+1) + '<DT><A HREF="%s" ADD_DATE="%s"'
+                           % (b.href, b.add_date))
         if b.last_visit: self.outfile.write(' LAST_VISIT="%s"' % b.last_visit)
         if b.last_modified:
             self.outfile.write(' LAST_MODIFIED="%s"' % b.last_modified)
index 39ef666f2b432e6d3d7eaa6a0871e77415664760..a21a1b131570ab94e953d45b9c15b24238f3b8da 100755 (executable)
@@ -66,7 +66,8 @@ def run():
         elif hasattr(bookmark, "real_title"):
             bookmark.name = bookmark.real_title
         if report_stats:
-            sys.stdout.write("Adding %s with title '%s'\n" % (href, bookmark.name))
+            sys.stdout.write("Adding %s with title '%s'\n"
+                             % (href, bookmark.name))
         del bookmark.parent
         root_folder.append(bookmark)
 
index e274108f4d03bd42e1d82200ea98df9f0b801565..e3971a6b3177c53368b93d04674515b7eda12e5c 100755 (executable)
@@ -42,7 +42,8 @@ def run():
         filename = args[0]
 
     else:
-        filename = 'bookmarks.html'  # good name both for DOS (bookmark.htm) and UNIX
+        # good name both for DOS (bookmark.htm) and UNIX
+        filename = 'bookmarks.html'
 
     if report_stats:
         from storage import storage_name
index 7777ba33fc0bb9b35a862690e9d95238d355374e..89647aa52eb57ecced2d4681834bba4b79f4ffaf 100644 (file)
@@ -152,7 +152,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 +184,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 +194,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]
@@ -219,7 +222,8 @@ def quote_title(title):
 def unquote_title(title):
     if BKMK_FORMAT == "MOZILLA":
         from HTMLParser import HTMLParser
-        title = HTMLParser().unescape(title.replace("&amp;", '&').decode('utf-8'))
+        title = HTMLParser().unescape(
+            title.replace("&amp;", '&').decode('utf-8'))
         title = title.encode('utf-8').replace("&#39;", "'")
     return title
 
index 00cfcd4c4ce298efc4d4da643b188b391230f325..b929721cedca3d68b84734bce4aa0bc4be1be09f 100644 (file)
@@ -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 = unicode(data, 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):
index 870d968f785e8dc55429e269c4ee5b6108035741..554c2af2e3ce5179423fbd6ff1349f7cb92ef96e 100755 (executable)
@@ -54,11 +54,12 @@ def run():
         object = root_folder.linear[object_no]
 
         if object.isBookmark:
-            if hasattr(object, "moved") or hasattr(object, "error") \
-                  or object.href.startswith('place:'):  # Firefox SmartBookmarks
+            if hasattr(object, "moved") or hasattr(object, "error") or \
+                    object.href.startswith('place:'):  # Firefox SmartBookmarks
                 continue
 
-            if hasattr(object, "real_title") and (object.real_title is not None):
+            if hasattr(object, "real_title") \
+                    and (object.real_title is not None):
                 unquoted_title = unquote_title(quote_title(object.real_title))
                 unquoted_name = unquote_title(object.name)
                 if unquoted_name != unquoted_title:
index 618ae6437a904b242e55a095cc33a912fc3abf86..ecaa2fb26582f1daf12209b803fc64dca3b19bbf 100755 (executable)
@@ -56,7 +56,10 @@ def run():
   LastModified: %s
   IconURI: %s
   Icon: %s
-  """ % (bookmark.href, getattr(bookmark, 'real_title', ''), strftime(bookmark.last_modified), bookmark.icon_href, bookmark.icon))
+  """ % (
+              bookmark.href, getattr(bookmark, 'real_title', ''),
+              strftime(bookmark.last_modified), bookmark.icon_href,
+              bookmark.icon))
 
     robot.stop()
     log.close()
index bf8df1a28c5d05da8ba21a79bd67806a78790082..bdf1ccec25a22ec9e1c420b943d17e5c626f95ee 100755 (executable)
@@ -128,7 +128,8 @@ def run():
                     "last_tested", "test_time", "icon", "charset",
                 ):
                     if hasattr(old_object, attr_name):
-                        setattr(object, attr_name, getattr(old_object, attr_name))
+                        setattr(object, attr_name,
+                                getattr(old_object, attr_name))
             else:
                 log("Checking %s" % href)
                 rcode = robot.check_url(object)
index 897aabcafa922ee64a7c22f3aa92571d544c9a6d..7d9ab2cd6e8a65b0989f5828b3c4299f662307c7 100755 (executable)
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
-"""Convert a bkmk database back to bookmarks.html (or other format defined by writer)
+"""Convert a bkmk database back to bookmarks.html
+(or other format defined by writer)
 
 This file is a part of Bookmarks database and Internet robot.
 """
@@ -43,7 +44,8 @@ def run():
 
     if args:
         sys.stderr.write("db2bkmk: too many arguments\n")
-        sys.stderr.write("Usage: db2bkmk [-s] [-p prune_folder] [-o filename] [-t trans] [-r]\n")
+        sys.stderr.write("Usage: db2bkmk [-s] [-p prune_folder]"
+                         " [-o filename] [-t trans] [-r]\n")
         sys.exit(1)
 
     from storage import storage
@@ -65,8 +67,9 @@ def run():
         transl_d = {}
 
         from m_lib.flad import fladm
-        transl_db = fladm.load_from_file(transl_name, fladm.check_record, ["URL1", "URL2"], [""])
-        #                                 This prevents any other key to appear in transl_db ^
+        transl_db = fladm.load_from_file(
+            transl_name, fladm.check_record, ["URL1", "URL2"], [""])
+        #    This prevents any other key to appear in transl_db ^
 
         # Generate translation dictionary (hash table)
         if transl == 1:
index 34b891c1f66c1e47f03baf1c2e51d366c3b7fed3..383aa57dcb035e7723274d3ff2e6b53ada66a7ff 100644 (file)
@@ -27,7 +27,8 @@ def main():
     else:
         sys.exit("Usage: main filename [charset]")
 
-    parser = parse_filename(filename, charset, log=lambda s: sys.stdout.write(s + '\n'))
+    parser = parse_filename(filename, charset,
+                            log=lambda s: sys.stdout.write(s + '\n'))
     print("   refresh:", parser.refresh)
     print("   icon   :", parser.icon)
 
index c14d055dfe9213556b48bf60fc4ee467d3888a39..6afb7f9df735f6a487b6b7537fc23f2c3daa71c2 100644 (file)
@@ -186,12 +186,19 @@ def parse_html(html_text, charset=None, log=None):
             if log: log("   title          : %s" % title)
             if parser.charset != universal_charset:
                 try:
-                    converted_title = unicode(title, parser.charset).encode(universal_charset)
+                    converted_title = unicode(title, parser.charset).\
+                        encode(universal_charset)
                 except UnicodeError:
-                    if log: log("   incorrect conversion from %s, converting from %s" % (parser.charset, DEFAULT_CHARSET))
-                    converted_title = unicode(title, DEFAULT_CHARSET, "replace").encode(universal_charset, "replace")
+                    if log:
+                        log("   incorrect conversion from %s,"
+                            "converting from %s"
+                            % (parser.charset, DEFAULT_CHARSET))
+                    converted_title = \
+                        unicode(title, DEFAULT_CHARSET, "replace").\
+                        encode(universal_charset, "replace")
                     parser.charset = DEFAULT_CHARSET
-            if log and (converted_title != title): log("   converted title: %s" % converted_title)
+            if log and (converted_title != title):
+                log("   converted title: %s" % converted_title)
         except LookupError:
             if log: log("   unknown charset: '%s'" % parser.charset)
     else:
@@ -201,7 +208,8 @@ def parse_html(html_text, charset=None, log=None):
         final_title = recode_entities(converted_title, universal_charset)
         parts = [s.strip() for s in final_title.replace('\r', '').split('\n')]
         final_title = ' '.join([s for s in parts if s])
-        if log and (final_title != converted_title): log("   final title    : %s" % final_title)
+        if log and (final_title != converted_title):
+            log("   final title    : %s" % final_title)
         parser.title = final_title
 
     icon = parser.icon
index e1969f3250aa73d6e46e24883dd264f6df7ccd94..f2f042e33b18aae1303f5fdbfa5f365f7aeeca78 100644 (file)
@@ -65,7 +65,8 @@ def parse_html(html_text, charset=None, log=None):
         return None
 
     _charset = root.originalEncoding
-    if _charset in ("ISO-8859-2", "windows-1252", "MacCyrillic"):  # Replace default
+    if _charset in ("ISO-8859-2", "windows-1252", "MacCyrillic"):
+        # Replace with default and re-parse
         _charset = DEFAULT_CHARSET
         root = _parse_html(html_text, _charset)
         if root is None:
@@ -104,7 +105,8 @@ def parse_html(html_text, charset=None, log=None):
         try:
             meta_content = meta.get("content")
             if meta_content:
-                __charset = meta_content.lower().split('charset=')[1].split(';')[0]
+                __charset = meta_content.lower().split('charset=')[1].\
+                    split(';')[0]
             else:
                 __charset = False
         except IndexError:  # No charset in the META Content-Type
index 182a123b402173d6a29c5e12d8971646541ba07f..1ce543e828936284bc469f6037bf4f0a77ca14c4 100644 (file)
@@ -65,7 +65,8 @@ def parse_html(html_text, charset=None, log=None):
         try:
             meta_content = meta.get("content")
             if meta_content:
-                __charset = meta_content.lower().split('charset=')[1].split(';')[0]
+                __charset = meta_content.lower().split('charset=')[1].\
+                    split(';')[0]
             else:
                 __charset = False
         except IndexError:  # No charset in the META Content-Type
@@ -122,4 +123,5 @@ def _find_refresh(Tag):
 
 def _find_icon(Tag):
     return (Tag.name == "link") and \
-       (Tag.get_attribute_list("rel", '')[0].lower() in ('icon', 'shortcut icon'))
+       (Tag.get_attribute_list("rel", '')[0].lower()
+        in ('icon', 'shortcut icon'))
index 6d0d38094bea6bd8935b4ddb29455ca458cd7cbf..111e1ed4b4b38360fef84ca41a9276351d0e6c5e 100644 (file)
@@ -17,7 +17,8 @@ from .bkmk_ph_util import HTMLParser
 
 def parse_html(html_text, charset=None, log=None):
     parser = HTML5Parser()
-    html_tree = parser.parse(html_text, encoding=charset, parseMeta=bool(charset))
+    html_tree = parser.parse(
+        html_text, encoding=charset, parseMeta=bool(charset))
 
     html = None
     if hasattr(html_tree, 'childNodes'):
@@ -59,7 +60,8 @@ def parse_html(html_text, charset=None, log=None):
                 if meta_content:
                     try:
                         meta_charset = \
-                            meta_content.lower().split('charset=')[1].split(';')[0]
+                            meta_content.lower().split('charset=')[1].\
+                            split(';')[0]
                     except IndexError:
                         meta_charset = False
                     else:
index 05ad6584d47ec37f67ae5883181fdc6de5328880..b90618f1856d37a99bd78e7931421aa67e6d45b3 100644 (file)
@@ -47,8 +47,10 @@ class HTMLParser(_HTMLParser):
 
         if (not self.charset) and (http_equiv == "content-type"):
             try:
-                # extract charset from "text/html; foo; charset=UTF-8, bar; baz;"
-                self.charset = content.lower().split('charset=')[1].split(';')[0].split(',')[0]
+                # extract charset from
+                # "text/html; foo; charset=UTF-8, bar; baz;"
+                self.charset = content.lower().split('charset=')[1].\
+                    split(';')[0].split(',')[0]
                 # Remember that the charset was retrieved from
                 # META tag, not from the Content-Type header
                 self.meta_charset = 1
@@ -72,7 +74,9 @@ class HTMLParser(_HTMLParser):
         for attrname, value in attrs:
             if value:
                 value = value.strip()
-                if (attrname == 'rel') and (value.lower() in ('icon', 'shortcut icon')):
+                if (attrname == 'rel') and (
+                        value.lower() in ('icon', 'shortcut icon')
+                ):
                     has_icon = True
                 elif attrname == 'href':
                     href = value
@@ -94,6 +98,7 @@ def parse_html(html_text, charset=None, log=None):
     except (HTMLParseError, HTMLHeadDone):
         pass
 
-    if (parser.title is None) and (parser.refresh is None) and (parser.icon is None):
+    if (parser.title is None) and (parser.refresh is None) \
+            and (parser.icon is None):
         return None
     return parser
index 8f091377f1d922968b66bced34de5d347128a0f5..eae7061aea713d8c0d8123e371712f6250e894bb 100755 (executable)
@@ -28,8 +28,8 @@ def run():
         pass
 
     if report_stats:
-        print("Broytman set-real_title, Copyright (C) 2003-2023 PhiloSoft Design")
-
+        print("Broytman set-real_title, Copyright (C)"
+              " 2003-2023 PhiloSoft Design")
     if args:
         sys.stderr.write("set-real_title: too many arguments\n")
         sys.stderr.write("Usage: set-real_title [-s]\n")
index 52c5ee8d6d0ad2fd751b700f3415721865a97425..8249c5789d3e642627c433ad609a5ee4b235f191 100755 (executable)
@@ -1,5 +1,6 @@
 #! /usr/bin/env python
-"""Run through the bookmarks database and set names to titles from an external file
+"""Run through the bookmarks database and set names to titles
+from an external file
 
 This file is a part of Bookmarks database and Internet robot.
 """
@@ -28,7 +29,8 @@ def run():
         pass
 
     if report_stats:
-        print("Broytman set-title-list, Copyright (C) 2003-2023 PhiloSoft Design")
+        print("Broytman set-title-list, Copyright (C)"
+              " 2003-2023 PhiloSoft Design")
 
     if len(args) != 1:
         sys.stderr.write("Usage: set-title-list [-s] title_list_file\n")
@@ -50,12 +52,18 @@ def run():
             title = line
 
         elif line:  # the third line in every 3 lines must be empty
-            raise ValueError("line is not empty for URL `%s', title `%s': line `%s'" % (URL, title, line))
+            raise ValueError(
+                "line is not empty for URL `%s', title `%s': line `%s'"
+                % (URL, title, line)
+            )
 
         else:  # We've got 3 lines - add new entry to the mapping
             if titles_dict.has_key(URL):
                 if title != titles_dict[URL]:
-                    raise ValueError("titles are not identical for URL `%s': `%s' != `%s'" % (URL, title, titles_dict[URL]))
+                    raise ValueError(
+                        "titles are not identical for URL `%s': `%s' != `%s'"
+                        % (URL, title, titles_dict[URL])
+                    )
 
             else:
                 titles_dict[URL] = title
index c61d24cad0bac4b4b4210669c3fb32b7d77eaa2f..abf8f48014a9d35d2442ded84822386dbb086830 100644 (file)
@@ -14,7 +14,8 @@ __all__ = ['import_storage', 'storage']
 from os import environ
 from bkmk_objects import parse_params, set_params
 
-storage_name, storage_params = parse_params(environ.get("BKMK_STORAGE", "pickle"))
+storage_name, storage_params = parse_params(
+    environ.get("BKMK_STORAGE", "pickle"))
 
 
 def import_storage(storage_name):