From cb9c36b39ed72cd1fa272130d2bcf162a89c3013 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 5 Sep 2023 20:55:16 +0300 Subject: [PATCH] Style: Fix flake8 E501 line too long --- Robots/bkmk_rforking.py | 7 +++- Robots/bkmk_rforking_sub.py | 2 +- Robots/bkmk_robot_base.py | 55 ++++++++++++++++++++-------- Robots/bkmk_rurllib.py | 16 +++++--- Robots/bkmk_rurllib2.py | 6 ++- Storage/bkmk_stflad.py | 22 ++++++++--- Storage/bkmk_stjson.py | 30 ++++++++++----- Writers/bkmk_wflad.py | 13 +++++-- Writers/bkmk_whtml.py | 6 ++- bkmk-add.py | 3 +- bkmk2db.py | 3 +- bkmk_objects.py | 12 ++++-- bkmk_parser.py | 6 ++- check_title.py | 7 ++-- check_url.py | 5 ++- check_urls.py | 3 +- db2bkmk.py | 11 ++++-- parse_html/__main__.py | 3 +- parse_html/bkmk_parse_html.py | 18 ++++++--- parse_html/bkmk_ph_beautifulsoup.py | 6 ++- parse_html/bkmk_ph_beautifulsoup4.py | 6 ++- parse_html/bkmk_ph_html5.py | 6 ++- parse_html/bkmk_ph_htmlparser.py | 13 +++++-- set-real_title.py | 4 +- set-title-list.py | 16 ++++++-- storage.py | 3 +- 26 files changed, 195 insertions(+), 87 deletions(-) diff --git a/Robots/bkmk_rforking.py b/Robots/bkmk_rforking.py index 30133dc..e128121 100644 --- a/Robots/bkmk_rforking.py +++ b/Robots/bkmk_rforking.py @@ -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] diff --git a/Robots/bkmk_rforking_sub.py b/Robots/bkmk_rforking_sub.py index f0bb912..2f444ab 100755 --- a/Robots/bkmk_rforking_sub.py +++ b/Robots/bkmk_rforking_sub.py @@ -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 diff --git a/Robots/bkmk_robot_base.py b/Robots/bkmk_robot_base.py index 9c9d8c5..d6a87d3 100644 --- a/Robots/bkmk_robot_base.py +++ b/Robots/bkmk_robot_base.py @@ -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) diff --git a/Robots/bkmk_rurllib.py b/Robots/bkmk_rurllib.py index 29421f1..20b7423 100644 --- a/Robots/bkmk_rurllib.py +++ b/Robots/bkmk_rurllib.py @@ -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) diff --git a/Robots/bkmk_rurllib2.py b/Robots/bkmk_rurllib2.py index 4cb684b..66f0460 100644 --- a/Robots/bkmk_rurllib2.py +++ b/Robots/bkmk_rurllib2.py @@ -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) diff --git a/Storage/bkmk_stflad.py b/Storage/bkmk_stflad.py index 8965bbe..156e956 100644 --- a/Storage/bkmk_stflad.py +++ b/Storage/bkmk_stflad.py @@ -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 diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index 1a34e3a..0b34ecb 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -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: diff --git a/Writers/bkmk_wflad.py b/Writers/bkmk_wflad.py index 64542bb..0d1acbb 100644 --- a/Writers/bkmk_wflad.py +++ b/Writers/bkmk_wflad.py @@ -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") diff --git a/Writers/bkmk_whtml.py b/Writers/bkmk_whtml.py index a9e46e8..058053d 100644 --- a/Writers/bkmk_whtml.py +++ b/Writers/bkmk_whtml.py @@ -39,7 +39,8 @@ class writer_html(Writer): def start_folder(self, f, level): self.outfile.write(ind_s*level + '

%s

\n' % quote_title(f.name)) self._folder(f, level) @@ -47,7 +48,8 @@ class writer_html(Writer): self.outfile.write(ind_s*level + "

\n") def bookmark(self, b, level): - self.outfile.write(ind_s*(level+1) + '

\n' % default_encoding self.accumulator += "" def end_title(self): diff --git a/check_title.py b/check_title.py index 870d968..554c2af 100755 --- a/check_title.py +++ b/check_title.py @@ -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: diff --git a/check_url.py b/check_url.py index 618ae64..ecaa2fb 100755 --- a/check_url.py +++ b/check_url.py @@ -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() diff --git a/check_urls.py b/check_urls.py index bf8df1a..bdf1cce 100755 --- a/check_urls.py +++ b/check_urls.py @@ -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) diff --git a/db2bkmk.py b/db2bkmk.py index 897aabc..7d9ab2c 100755 --- a/db2bkmk.py +++ b/db2bkmk.py @@ -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: diff --git a/parse_html/__main__.py b/parse_html/__main__.py index 34b891c..383aa57 100644 --- a/parse_html/__main__.py +++ b/parse_html/__main__.py @@ -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) diff --git a/parse_html/bkmk_parse_html.py b/parse_html/bkmk_parse_html.py index c14d055..6afb7f9 100644 --- a/parse_html/bkmk_parse_html.py +++ b/parse_html/bkmk_parse_html.py @@ -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 diff --git a/parse_html/bkmk_ph_beautifulsoup.py b/parse_html/bkmk_ph_beautifulsoup.py index e1969f3..f2f042e 100644 --- a/parse_html/bkmk_ph_beautifulsoup.py +++ b/parse_html/bkmk_ph_beautifulsoup.py @@ -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 diff --git a/parse_html/bkmk_ph_beautifulsoup4.py b/parse_html/bkmk_ph_beautifulsoup4.py index 182a123..1ce543e 100644 --- a/parse_html/bkmk_ph_beautifulsoup4.py +++ b/parse_html/bkmk_ph_beautifulsoup4.py @@ -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')) diff --git a/parse_html/bkmk_ph_html5.py b/parse_html/bkmk_ph_html5.py index 6d0d380..111e1ed 100644 --- a/parse_html/bkmk_ph_html5.py +++ b/parse_html/bkmk_ph_html5.py @@ -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: diff --git a/parse_html/bkmk_ph_htmlparser.py b/parse_html/bkmk_ph_htmlparser.py index 05ad658..b90618f 100644 --- a/parse_html/bkmk_ph_htmlparser.py +++ b/parse_html/bkmk_ph_htmlparser.py @@ -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 diff --git a/set-real_title.py b/set-real_title.py index 8f09137..eae7061 100755 --- a/set-real_title.py +++ b/set-real_title.py @@ -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") diff --git a/set-title-list.py b/set-title-list.py index 52c5ee8..8249c57 100755 --- a/set-title-list.py +++ b/set-title-list.py @@ -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 diff --git a/storage.py b/storage.py index c61d24c..abf8f48 100644 --- a/storage.py +++ b/storage.py @@ -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): -- 2.39.5