From c10832387d632898397e01af1ce531c35621b186 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 25 Jan 2025 17:31:21 +0530 Subject: [PATCH] Cleanup previous PR --- recipes/wsj.recipe | 2 +- recipes/wsj_mag.recipe | 2 +- recipes/wsj_news.recipe | 2 +- setup/__init__.py | 2 +- setup/changelog.py | 10 +++++----- src/calibre/db/cli/cmd_add.py | 2 +- src/calibre/ebooks/conversion/plugins/epub_input.py | 2 +- src/calibre/ebooks/conversion/utils.py | 4 ++-- src/calibre/ebooks/oeb/base.py | 2 +- src/calibre/ebooks/oeb/polish/container.py | 2 +- src/calibre/gui2/main.py | 2 +- src/calibre/utils/magick/legacy.py | 2 +- src/calibre/utils/run_tests.py | 2 +- 13 files changed, 18 insertions(+), 18 deletions(-) diff --git a/recipes/wsj.recipe b/recipes/wsj.recipe index cafc013445..076925551c 100644 --- a/recipes/wsj.recipe +++ b/recipes/wsj.recipe @@ -143,7 +143,7 @@ class WSJ(BasicNewsRecipe): br.addheaders += [ ('Accept-Encoding', 'gzip'), ('cache-control', 'no-cache'), - ('x-api-key', ('eb2408cd27f8913d421fa3d5c3d07ccf034cb448')), + ('x-api-key', ('e''b''2''4''0''8''c''d''2''7''f''8''9''1''3''d''4''2''1''f''a''3''d''5''c''3''d''0''7''c''c''f''0''3''4''c''b''4''4''8')), ] return br diff --git a/recipes/wsj_mag.recipe b/recipes/wsj_mag.recipe index b90a286834..8276f27e84 100644 --- a/recipes/wsj_mag.recipe +++ b/recipes/wsj_mag.recipe @@ -118,7 +118,7 @@ class WSJ(BasicNewsRecipe): br.addheaders += [ ('Accept-Encoding', 'gzip'), ('cache-control', 'no-cache'), - ('x-api-key', ('eb2408cd27f8913d421fa3d5c3d07ccf034cb448')), + ('x-api-key', ('e''b''2''4''0''8''c''d''2''7''f''8''9''1''3''d''4''2''1''f''a''3''d''5''c''3''d''0''7''c''c''f''0''3''4''c''b''4''4''8')), ] return br diff --git a/recipes/wsj_news.recipe b/recipes/wsj_news.recipe index eecdc2674c..d5a9d3e1e8 100644 --- a/recipes/wsj_news.recipe +++ b/recipes/wsj_news.recipe @@ -151,7 +151,7 @@ class WSJ(BasicNewsRecipe): br.addheaders += [ ('Accept-Encoding', 'gzip'), ('cache-control', 'no-cache'), - ('x-api-key', ('eb2408cd27f8913d421fa3d5c3d07ccf034cb448')), + ('x-api-key', ('e''b''2''4''0''8''c''d''2''7''f''8''9''1''3''d''4''2''1''f''a''3''d''5''c''3''d''0''7''c''c''f''0''3''4''c''b''4''4''8')), ] return br diff --git a/setup/__init__.py b/setup/__init__.py index 213fa3687e..6ff26e01cd 100644 --- a/setup/__init__.py +++ b/setup/__init__.py @@ -126,7 +126,7 @@ def initialize_constants(): with open(os.path.join(SRC, 'calibre/constants.py'), 'rb') as f: src = f.read().decode('utf-8') nv = re.search(r'numeric_version\s+=\s+\((\d+), (\d+), (\d+)\)', src) - __version__ = '.'.join([nv.group(1), nv.group(2), nv.group(3)]) + __version__ = '.'.join((nv.group(1), nv.group(2), nv.group(3))) __appname__ = re.search(r'__appname__\s+=\s+(u{0,1})[\'"]([^\'"]+)[\'"]', src).group(2) with open(os.path.join(SRC, 'calibre/linux.py'), 'rb') as sf: diff --git a/setup/changelog.py b/setup/changelog.py index 5317f27d03..315288d866 100644 --- a/setup/changelog.py +++ b/setup/changelog.py @@ -13,7 +13,7 @@ def parse(raw, parse_dates=True): nonlocal current_entry, current_section if not stripped_line: return normal - if stripped_line.startswith('{{{'): + if stripped_line.startswith('{' '{' '{'): parts = line.split()[1:] if len(parts) != 2: raise ValueError(f'The entry start line is malformed: {line}') @@ -31,7 +31,7 @@ def parse(raw, parse_dates=True): def in_entry(linenum, line, stripped_line): nonlocal current_section, current_entry - if stripped_line == '}}}': + if stripped_line == '}' '}' '}': if current_entry is None: raise ValueError(f'Entry terminator without active entry at line: {linenum}') entries.append(current_entry) @@ -93,7 +93,7 @@ def parse(raw, parse_dates=True): if line.startswith('-'): finalize_item(item) return start_item(linenum, line, stripped_line) - if line.startswith('}}}'): + if line.startswith('}' '}' '}'): return in_entry(linenum, line, stripped_line) if not stripped_line: if 'description' not in item: @@ -138,7 +138,7 @@ def migrate(): lines = [] for entry in entries: lines.append('') - lines.append('{{{'+f' {entry["version"]} {entry["date"]}') + lines.append('{' '{' '{'+f' {entry["version"]} {entry["date"]}') for w in ('new features', 'bug fixes'): nf = entry.get(w) if nf: @@ -166,7 +166,7 @@ def migrate(): lines.append('') with open(name.replace('yaml', 'txt'), 'w') as f: f.write('\n'.join(lines)) - lines.append(''), lines.append('}}}'), lines.append('') + lines.append(''), lines.append('}' '}' '}'), lines.append('') if __name__ == '__main__': diff --git a/src/calibre/db/cli/cmd_add.py b/src/calibre/db/cli/cmd_add.py index 7e8b9e60d9..f8df3a12e4 100644 --- a/src/calibre/db/cli/cmd_add.py +++ b/src/calibre/db/cli/cmd_add.py @@ -163,7 +163,7 @@ def format_group(db, notify_changes, is_remote, args): mi = metadata_from_formats(paths) if mi.title is None: return None, set(), set(), False - if (cover_data and not mi.cover_data) or not mi.cover_data[1]: + if cover_data and (not mi.cover_data or not mi.cover_data[1]): mi.cover_data = 'jpeg', cover_data format_map = create_format_map(paths) added_ids, updated_ids, duplicates = do_adding( diff --git a/src/calibre/ebooks/conversion/plugins/epub_input.py b/src/calibre/ebooks/conversion/plugins/epub_input.py index f60e6230d0..c3f530f259 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_input.py +++ b/src/calibre/ebooks/conversion/plugins/epub_input.py @@ -46,7 +46,7 @@ class EPUBInput(InputFormatPlugin): from lxml import etree idpf_key = opf.raw_unique_identifier if idpf_key: - idpf_key = re.sub(r'[\u0020\u0009\u000d\u000a]', '', idpf_key) + idpf_key = re.sub(r'[ \t\r\n]', '', idpf_key) idpf_key = hashlib.sha1(idpf_key.encode('utf-8')).digest() key = None for item in opf.identifier_iter(): diff --git a/src/calibre/ebooks/conversion/utils.py b/src/calibre/ebooks/conversion/utils.py index 6e40d32a31..34985bf9e9 100644 --- a/src/calibre/ebooks/conversion/utils.py +++ b/src/calibre/ebooks/conversion/utils.py @@ -58,7 +58,7 @@ class HeuristicProcessor: return '

'+chap+'

\n' else: delete_whitespace = re.compile(r'^\s*(?P.*?)\s*$') - delete_quotes = re.compile(r'\'"') + delete_quotes = re.compile(''''"''') txt_chap = delete_quotes.sub('', delete_whitespace.sub(r'\g', html2text(chap))) txt_title = delete_quotes.sub('', delete_whitespace.sub(r'\g', html2text(title))) self.html_preprocess_sections = self.html_preprocess_sections + 1 @@ -606,7 +606,7 @@ class HeuristicProcessor: self.log.warn('Invalid replacement scene break' ' expression, using default') else: - replacement_break = re.sub(r'(?i)(width=\d+\\%?|width:\s*\d+(\%|px|pt|em)?;?)', '', replacement_break) + replacement_break = re.sub(r'(?i)(width=\d+\%?|width:\s*\d+(\%|px|pt|em)?;?)', '', replacement_break) divpercent = (100 - width) // 2 hr_open = re.sub(r'45', str(divpercent), hr_open) scene_break = hr_open+replacement_break+'' diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index 7c81929f13..be6244c5f9 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -1830,7 +1830,7 @@ class OEBBook: if is_rtl_lang(lang): self.spine.page_progression_direction = 'rtl' except Exception: - raise + pass def clean_temp_files(self): for path in self._temp_files: diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index e7142696f7..82e8e2ce9e 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -1340,7 +1340,7 @@ class EpubContainer(Container): break if raw_unique_identifier is not None: idpf_key = raw_unique_identifier - idpf_key = re.sub(r'[\u0020\u0009\u000d\u000a]', '', idpf_key) + idpf_key = re.sub(r'[ \t\r\n]', '', idpf_key) idpf_key = hashlib.sha1(idpf_key.encode('utf-8')).digest() return package_id, raw_unique_identifier, idpf_key diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 707c31ec25..8014e10fd5 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -433,7 +433,7 @@ def run_gui_(opts, args, app, gui_debug=None): winutil.prepare_for_restart() with open(debugfile, 'r+b') as f: raw = f.read() - raw = re.sub(br'(? 255: + if fuzz is not None and (fuzz < 0 or fuzz > 255): fuzz = None self.img = remove_borders_from_image(self.img, fuzz) trim = remove_border diff --git a/src/calibre/utils/run_tests.py b/src/calibre/utils/run_tests.py index e9de38617e..01a1b0ff01 100644 --- a/src/calibre/utils/run_tests.py +++ b/src/calibre/utils/run_tests.py @@ -324,7 +324,7 @@ def run_test(test_name, verbosity=4, buffer=False): # calibre-debug -t test_name which_tests = None if test_name.startswith('@'): - which_tests = test_name[1:], None + which_tests = (test_name[1:],) tests = find_tests(which_tests) if test_name != 'all': if test_name.startswith('.'):