From 9faa13f6f8199790cf01533e857c593520559649 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 4 Sep 2023 19:56:48 +0300 Subject: [PATCH] Style: Fix flake8 E302 expected 2 blank lines, found 1 --- Robots/bkmk_rforking.py | 3 +++ Robots/bkmk_rurllib.py | 2 ++ Robots/bkmk_rurllib2.py | 3 ++- Storage/bkmk_stjson.py | 7 ++++++- Writers/bkmk_whtml.py | 3 ++- bkmk_objects.py | 4 ++++ check_dups.py | 5 +++-- check_url.py | 5 +++-- parse_html/bkmk_parse_html.py | 3 +++ parse_html/bkmk_ph_beautifulsoup.py | 7 +++++++ parse_html/bkmk_ph_beautifulsoup4.py | 6 ++++++ parse_html/bkmk_ph_util.py | 3 ++- robots.py | 3 ++- storage.py | 3 ++- writers.py | 3 ++- 15 files changed, 49 insertions(+), 11 deletions(-) diff --git a/Robots/bkmk_rforking.py b/Robots/bkmk_rforking.py index 6250af9..c5bbb62 100644 --- a/Robots/bkmk_rforking.py +++ b/Robots/bkmk_rforking.py @@ -28,6 +28,7 @@ sys.stderr = open("err.log", 'a') check_subp = None subp_pipe = None + def stop_subp(log): global check_subp, subp_pipe if check_subp: @@ -35,6 +36,7 @@ def stop_subp(log): del check_subp del subp_pipe + def restart_subp(log): global check_subp, subp_pipe stop_subp(log) @@ -46,6 +48,7 @@ def restart_subp(log): _set_subproc = True + class robot_forking(Robot): subproc = 'urllib2' # Default subprocess diff --git a/Robots/bkmk_rurllib.py b/Robots/bkmk_rurllib.py index 2c32291..3ef47eb 100644 --- a/Robots/bkmk_rurllib.py +++ b/Robots/bkmk_rurllib.py @@ -22,6 +22,7 @@ class RedirectException(Exception): self.errcode = errcode self.newurl = newurl + class MyURLopener(urllib.URLopener): # Error 301 -- relocated (permanently) def http_error_301(self, url, fp, errcode, errmsg, headers, data=None): @@ -70,6 +71,7 @@ urllib._urlopener.addheader('Connection', 'close') urllib_ftpwrapper = urllib.ftpwrapper ftpcache_key = None + class myftpwrapper(urllib_ftpwrapper): def __init__(self, user, passwd, host, port, dirs): urllib_ftpwrapper.__init__(self, user, passwd, host, port, dirs) diff --git a/Robots/bkmk_rurllib2.py b/Robots/bkmk_rurllib2.py index a5714a1..4cb684b 100644 --- a/Robots/bkmk_rurllib2.py +++ b/Robots/bkmk_rurllib2.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2014-2017 PhiloSoft Design" +__copyright__ = "Copyright (C) 2014-2023 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['robot_urllib2'] @@ -19,6 +19,7 @@ from Robots.bkmk_robot_base import robot_base, get_error _fw = None + class FTPHandler(urllib2.FTPHandler): def connect_ftp(self, user, passwd, host, port, dirs, timeout): global _fw diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index 6053bd1..1a34e3a 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2010-2017 PhiloSoft Design" +__copyright__ = "Copyright (C) 2010-2023 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['storage_json'] @@ -188,6 +188,7 @@ def convert_date_to_json(date): date = int(float(date) * 10**6) return date + def convert_date_from_json(date): if date: date = float(date) @@ -195,16 +196,19 @@ def convert_date_from_json(date): date /= 10.0**6 return date + def encode_title(title): if title: return title.encode("UTF-8", "xmlcharrefreplace") return title + def get_str(record, name): if name in record: return record[name].encode('utf-8') return '' + def get_comment(annos): if not annos: return '' @@ -215,6 +219,7 @@ def get_comment(annos): return '' + def make_annos(value, name="bookmarkProperties/description"): return [{ "expires": 4, diff --git a/Writers/bkmk_whtml.py b/Writers/bkmk_whtml.py index f7a1d65..eae6e5f 100644 --- a/Writers/bkmk_whtml.py +++ b/Writers/bkmk_whtml.py @@ -4,7 +4,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design" +__copyright__ = "Copyright (C) 2000-2023 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['writer_html'] @@ -22,6 +22,7 @@ def dump_comment(comment): ind_s = " "*4 + class writer_html(Writer): filename = "bookmarks.html" diff --git a/bkmk_objects.py b/bkmk_objects.py index f313bd3..f66272b 100644 --- a/bkmk_objects.py +++ b/bkmk_objects.py @@ -18,6 +18,7 @@ import os, urllib BKMK_FORMAT = os.environ.get("BKMK_FORMAT", "MOZILLA") + class Folder(list): isFolder = 1 isBookmark = 0 @@ -200,6 +201,7 @@ def make_tree(linear): return root_folder + def break_tree(linear): del linear[0] @@ -212,6 +214,7 @@ def quote_title(title): title = title.replace("'", "'") return title + def unquote_title(title): if BKMK_FORMAT == "MOZILLA": from HTMLParser import HTMLParser @@ -229,6 +232,7 @@ def parse_params(param_str): param_list[key] = value return main_param, param_list + def set_params(obj, params): if hasattr(params, "items"): params = params.items() diff --git a/check_dups.py b/check_dups.py index 0a267ac..94ae3f0 100755 --- a/check_dups.py +++ b/check_dups.py @@ -9,12 +9,13 @@ import sys __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design" +__copyright__ = "Copyright (C) 2000-2023 PhiloSoft Design" __license__ = "GNU GPL" log_file = None + def report_dup(href, object_no): s = "Duplicate URL: %s (first at rec. %d)" % (href, object_no) @@ -43,7 +44,7 @@ def run(): pass if report_stats: - print("Broytman check_dups, Copyright (C) 2000-2017 PhiloSoft Design") + print("Broytman check_dups, Copyright (C) 2000-2023 PhiloSoft Design") if args: sys.stderr.write("check_urls: too many arguments\n") diff --git a/check_url.py b/check_url.py index 46135c5..7b52c70 100755 --- a/check_url.py +++ b/check_url.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2010-2017 PhiloSoft Design" +__copyright__ = "Copyright (C) 2010-2023 PhiloSoft Design" __license__ = "GNU GPL" import sys @@ -13,6 +13,7 @@ import httplib HTTP = httplib.HTTP + class MyHTTP(HTTP): def _setup(self, conn): HTTP._setup(self, conn) @@ -25,7 +26,7 @@ from Writers.bkmk_wflad import strftime def run(): - print("Broytman check_url, Copyright (C) 2010-2017 PhiloSoft Design") + print("Broytman check_url, Copyright (C) 2010-2023 PhiloSoft Design") if len(sys.argv) < 2: sys.stderr.write("Usage: check_url.py url1 [url2...]\n") diff --git a/parse_html/bkmk_parse_html.py b/parse_html/bkmk_parse_html.py index 7bdc566..07fe32e 100644 --- a/parse_html/bkmk_parse_html.py +++ b/parse_html/bkmk_parse_html.py @@ -69,6 +69,7 @@ from htmlentitydefs import name2codepoint entity_re = re.compile("(&\w+;)") num_entity_re = re.compile("(&#[0-9]+;)") + def recode_entities(title, charset): output = [] for part in entity_re.split(title): @@ -95,6 +96,7 @@ def recode_entities(title, charset): import os BKMK_DEBUG_HTML_PARSERS = os.environ.get("BKMK_DEBUG_HTML_PARSERS") + def parse_html(html_text, charset=None, log=None): if not parsers: return None @@ -211,6 +213,7 @@ def parse_html(html_text, charset=None, log=None): parser.icon = icon.encode(parser.charset) return parser + def parse_filename(filename, charset=None, log=None): fp = open(filename, 'r') try: diff --git a/parse_html/bkmk_ph_beautifulsoup.py b/parse_html/bkmk_ph_beautifulsoup.py index 1479f03..e1969f3 100644 --- a/parse_html/bkmk_ph_beautifulsoup.py +++ b/parse_html/bkmk_ph_beautifulsoup.py @@ -19,6 +19,8 @@ from .bkmk_ph_util import HTMLParser DEFAULT_CHARSET = "cp1251" # Stupid default for Russian Cyrillic # http://groups.google.com/group/beautifulsoup/browse_thread/thread/69093cb0d3a3cf63 + + class BadDeclParser(BeautifulSoup): def parse_declaration(self, i): """Treat a bogus SGML declaration as raw data. Treat a CDATA @@ -56,6 +58,7 @@ def _parse_html(html_text, charset): except TypeError: return None + def parse_html(html_text, charset=None, log=None): root = _parse_html(html_text, charset) if root is None: @@ -137,17 +140,21 @@ def parse_html(html_text, charset=None, log=None): return None return HTMLParser(_charset, meta_charset, title, refresh, icon) + def _find_contenttype(Tag): return (Tag.name == "meta") and \ (Tag.get("http-equiv", '').lower() == "content-type") + def _find_charset(Tag): return (Tag.name == "meta") and Tag.get("charset", '') + def _find_refresh(Tag): return (Tag.name == "meta") and \ (Tag.get("http-equiv", '').lower() == "refresh") + def _find_icon(Tag): return (Tag.name == "link") and \ (Tag.get("rel", '').lower() in ('icon', 'shortcut icon')) diff --git a/parse_html/bkmk_ph_beautifulsoup4.py b/parse_html/bkmk_ph_beautifulsoup4.py index b7f60ff..182a123 100644 --- a/parse_html/bkmk_ph_beautifulsoup4.py +++ b/parse_html/bkmk_ph_beautifulsoup4.py @@ -18,12 +18,14 @@ from .bkmk_ph_util import HTMLParser universal_charset = "utf-8" DEFAULT_CHARSET = "cp1251" # Stupid default for Russian Cyrillic + def _parse_html(html_text, charset): try: return BeautifulSoup(html_text, from_encoding=charset) except TypeError: return None + def parse_html(html_text, charset=None, log=None): root = _parse_html(html_text, charset) if root is None: @@ -103,17 +105,21 @@ def parse_html(html_text, charset=None, log=None): return None return HTMLParser(_charset, meta_charset, title, refresh, icon) + def _find_contenttype(Tag): return (Tag.name == "meta") and \ (Tag.get_attribute_list("http-equiv", '')[0].lower() == "content-type") + def _find_charset(Tag): return (Tag.name == "meta") and Tag.get("charset", '') + def _find_refresh(Tag): return (Tag.name == "meta") and \ (Tag.get_attribute_list("http-equiv", '')[0].lower() == "refresh") + def _find_icon(Tag): return (Tag.name == "link") and \ (Tag.get_attribute_list("rel", '')[0].lower() in ('icon', 'shortcut icon')) diff --git a/parse_html/bkmk_ph_util.py b/parse_html/bkmk_ph_util.py index 0e2d529..0fd09f2 100644 --- a/parse_html/bkmk_ph_util.py +++ b/parse_html/bkmk_ph_util.py @@ -4,7 +4,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2010-2017 PhiloSoft Design" +__copyright__ = "Copyright (C) 2010-2023 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['HTMLParser'] @@ -12,6 +12,7 @@ __all__ = ['HTMLParser'] from HTMLParser import HTMLParser + class HTMLParser(HTMLParser): def __init__(self, charset, meta_charset, title, refresh, icon): object.__init__(self) diff --git a/robots.py b/robots.py index 543e6ec..2527a0c 100644 --- a/robots.py +++ b/robots.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 1997-2017 PhiloSoft Design" +__copyright__ = "Copyright (C) 1997-2023 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['import_robot', 'robot'] @@ -16,6 +16,7 @@ from bkmk_objects import parse_params, set_params robot_name, robot_params = parse_params(environ.get("BKMK_ROBOT", "forking")) + def import_robot(robot_name): exec("from Robots import bkmk_r%s" % robot_name) exec("robot = bkmk_r%s.robot_%s" % (robot_name, robot_name)) diff --git a/storage.py b/storage.py index a71cdeb..407fa24 100644 --- a/storage.py +++ b/storage.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 1997-2017 PhiloSoft Design" +__copyright__ = "Copyright (C) 1997-2023 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['import_storage', 'storage'] @@ -16,6 +16,7 @@ from bkmk_objects import parse_params, set_params storage_name, storage_params = parse_params(environ.get("BKMK_STORAGE", "pickle")) + def import_storage(storage_name): exec("from Storage import bkmk_st%s" % storage_name) exec("storage = bkmk_st%s.storage_%s" % (storage_name, storage_name)) diff --git a/writers.py b/writers.py index 25c3cdb..3212e5a 100644 --- a/writers.py +++ b/writers.py @@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 1997-2017 PhiloSoft Design" +__copyright__ = "Copyright (C) 1997-2023 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['import_writer', 'writer'] @@ -16,6 +16,7 @@ from bkmk_objects import parse_params, set_params writer_name, writer_params = parse_params(environ.get("BKMK_WRITER", "html")) + def import_writer(writer_name): exec("from Writers import bkmk_w%s" % writer_name) exec("writer = bkmk_w%s.writer_%s" % (writer_name, writer_name)) -- 2.39.5