diff --git a/flexget/components/bittorrent/trackers.py b/flexget/components/bittorrent/trackers.py index 875fcd1d98..8a7c347a2e 100644 --- a/flexget/components/bittorrent/trackers.py +++ b/flexget/components/bittorrent/trackers.py @@ -54,7 +54,7 @@ def on_task_modify(self, task, config): if 'torrent' in entry: for tracker in entry['torrent'].trackers: for regexp in config or []: - if re.search(regexp, tracker, re.IGNORECASE | re.UNICODE): + if re.search(regexp, tracker, re.IGNORECASE): logger.debug( 'remove_trackers removing {} because of {}', tracker, regexp ) @@ -65,7 +65,7 @@ def on_task_modify(self, task, config): for regexp in config: # Replace any tracker strings that match the regexp with nothing tr_search = rf'&tr=([^&]*{regexp}[^&]*)' - entry['url'] = re.sub(tr_search, '', entry['url'], re.IGNORECASE | re.UNICODE) + entry['url'] = re.sub(tr_search, '', entry['url'], flags=re.IGNORECASE) class ModifyTrackers: diff --git a/flexget/components/emby/api_emby.py b/flexget/components/emby/api_emby.py index 6cd2a05c6f..194a3891fd 100644 --- a/flexget/components/emby/api_emby.py +++ b/flexget/components/emby/api_emby.py @@ -49,7 +49,7 @@ logger = logger.bind(name='api_emby') -class EmbyApiBase(ABC): +class EmbyApiBase(ABC): # noqa: B024 """ Base Class to all API integratios """ diff --git a/flexget/components/imdb/utils.py b/flexget/components/imdb/utils.py index 11c836251e..49437fe1f8 100644 --- a/flexget/components/imdb/utils.py +++ b/flexget/components/imdb/utils.py @@ -88,7 +88,7 @@ def __init__(self): def ireplace(self, text, old, new, count=0): """Case insensitive string replace""" pattern = re.compile(re.escape(old), re.I) - return re.sub(pattern, new, text, count) + return re.sub(pattern, new, text, count=count) def smart_match(self, raw_name, single_match=True): """Accepts messy name, cleans it and uses information available to make smartest and best match""" diff --git a/flexget/components/irc/irc.py b/flexget/components/irc/irc.py index ca07e38b15..6bc3ce85e5 100644 --- a/flexget/components/irc/irc.py +++ b/flexget/components/irc/irc.py @@ -26,12 +26,8 @@ logger = logger.bind(name='irc') -MESSAGE_CLEAN = re.compile( - r"\x0f|\x1f|\x02|\x03(?:[\d]{1,2}(?:,[\d]{1,2})?)?", re.MULTILINE | re.UNICODE -) -URL_MATCHER = re.compile( - r'(https?://[\da-z\.-]+\.[a-z\.]{2,6}[/\w\.-\?&]*/?)', re.MULTILINE | re.UNICODE -) +MESSAGE_CLEAN = re.compile(r"\x0f|\x1f|\x02|\x03(?:[\d]{1,2}(?:,[\d]{1,2})?)?", re.MULTILINE) +URL_MATCHER = re.compile(r'(https?://[\da-z\.-]+\.[a-z\.]{2,6}[/\w\.-\?&]*/?)', re.MULTILINE) channel_pattern = { 'type': 'string', @@ -202,7 +198,7 @@ def __init__(self, config, config_name): # Process ignore lines for regex_values in self.tracker_config.findall('parseinfo/ignore/regex'): - rx = re.compile(regex_values.get('value'), re.UNICODE | re.MULTILINE) + rx = re.compile(regex_values.get('value'), re.MULTILINE) self.ignore_lines.append((rx, regex_values.get('expected') != 'false')) # Parse patterns @@ -374,7 +370,7 @@ def parse_patterns(self, patterns): """ result = [] for pattern in patterns: - rx = re.compile(pattern.find('regex').get('value'), re.UNICODE | re.MULTILINE) + rx = re.compile(pattern.find('regex').get('value'), re.MULTILINE) vals = [var.get('name') for idx, var in enumerate(pattern.find('vars'))] optional = pattern.get('optional', 'false').lower() == 'true' result.append((rx, vals, optional)) diff --git a/flexget/components/managed_lists/lists/entry_list/entry_list.py b/flexget/components/managed_lists/lists/entry_list/entry_list.py index d1dba90c3f..cd4fb2d25e 100644 --- a/flexget/components/managed_lists/lists/entry_list/entry_list.py +++ b/flexget/components/managed_lists/lists/entry_list/entry_list.py @@ -27,6 +27,7 @@ def search(self, task, entry, config=None): entry_list = db.get_list_by_exact_name(config, session=session) except NoResultFound: logger.warning("Entry list with name '{}' does not exist", config) + return entries else: for search_string in entry.get('search_strings', [entry['title']]): logger.debug( @@ -39,7 +40,6 @@ def search(self, task, entry, config=None): db.EntryListEntry.title.like('%' + search_string + '%') ) entries += [e.entry for e in query.all()] - finally: return entries diff --git a/flexget/log.py b/flexget/log.py index c1a9abaa73..3a02337540 100644 --- a/flexget/log.py +++ b/flexget/log.py @@ -206,6 +206,6 @@ def start( if _startup_buffer: for record in _startup_buffer: level, message = record['level'].name, record['message'] - logger.patch(lambda r: r.update(record)).log(level, message) + logger.patch(lambda r, record=record: r.update(record)).log(level, message) _startup_buffer = [] _logging_started = True diff --git a/flexget/plugins/cli/try_regexp.py b/flexget/plugins/cli/try_regexp.py index dae8ba0ebf..d1e3aa314c 100644 --- a/flexget/plugins/cli/try_regexp.py +++ b/flexget/plugins/cli/try_regexp.py @@ -22,7 +22,7 @@ def matches(self, entry, regexp): for field, value in entry.items(): if not isinstance(value, str): continue - if re.search(regexp, value, re.IGNORECASE | re.UNICODE): + if re.search(regexp, value, re.IGNORECASE): return (True, field) return (False, None) diff --git a/flexget/plugins/filter/regexp.py b/flexget/plugins/filter/regexp.py index 8a746c721f..61270962b7 100644 --- a/flexget/plugins/filter/regexp.py +++ b/flexget/plugins/filter/regexp.py @@ -123,13 +123,11 @@ def prepare_config(self, config): # compile `not` option regexps if 'not' in opts: - opts['not'] = [ - re.compile(not_re, re.IGNORECASE | re.UNICODE) for not_re in opts['not'] - ] + opts['not'] = [re.compile(not_re, re.IGNORECASE) for not_re in opts['not']] # compile regexp and make sure regexp is a string for series like '24' try: - regexp = re.compile(str(regexp), re.IGNORECASE | re.UNICODE) + regexp = re.compile(str(regexp), re.IGNORECASE) except re.error as e: # Since validator can't validate dict keys (when an option is defined for the pattern) make sure we # raise a proper error here. diff --git a/flexget/plugins/metainfo/content_size.py b/flexget/plugins/metainfo/content_size.py index 1133061c9e..030e505314 100644 --- a/flexget/plugins/metainfo/content_size.py +++ b/flexget/plugins/metainfo/content_size.py @@ -10,7 +10,7 @@ logger = logger.bind(name='metanfo_csize') -SIZE_RE = re.compile(r'Size[^\d]{0,7}(\d*\.?\d+).{0,5}(MB|GB)', re.IGNORECASE | re.UNICODE) +SIZE_RE = re.compile(r'Size[^\d]{0,7}(\d*\.?\d+).{0,5}(MB|GB)', re.IGNORECASE) class MetainfoContentSize: diff --git a/flexget/utils/parsers/generic.py b/flexget/utils/parsers/generic.py index 7752b13ab5..5b2e4bbf57 100644 --- a/flexget/utils/parsers/generic.py +++ b/flexget/utils/parsers/generic.py @@ -43,12 +43,12 @@ def name_to_re(name, ignore_prefixes=None, parser=None): # Blanks are any non word characters except & and _ blank = r'(?:[^\w&]|_)' ignore = '(?:' + '|'.join(ignore_prefixes) + ')?' - res = re.sub(re.compile(blank + '+', re.UNICODE), ' ', name) + res = re.sub(re.compile(blank + '+'), ' ', name) res = res.strip() # accept either '&' or 'and' - res = re.sub(' (&|and) ', ' (?:and|&) ', res, re.UNICODE) + res = re.sub(' (&|and) ', ' (?:and|&) ', res) # The replacement has a regex escape in it (\w) which needs to be escaped again in python 3.7+ - res = re.sub(' +', blank.replace('\\', '\\\\') + '*', res, re.UNICODE) + res = re.sub(' +', blank.replace('\\', '\\\\') + '*', res) if parenthetical: res += '(?:' + blank + '+' + parenthetical + ')?' # Turn on exact mode for series ending with a parenthetical, diff --git a/flexget/utils/parsers/parser.py b/flexget/utils/parsers/parser.py index a4e085a3cd..0f3d0cd9ab 100644 --- a/flexget/utils/parsers/parser.py +++ b/flexget/utils/parsers/parser.py @@ -56,9 +56,9 @@ def remove_words(text, words, not_in_word=False): @staticmethod def ireplace(data, old, new, count=0, not_in_word=False): - """Case insensitive string replace""" + """Case-insensitive string replace""" old = re.escape(old) if not_in_word: old = TitleParser.re_not_in_word(old) pattern = re.compile(old, re.I) - return re.sub(pattern, new, data, count) + return re.sub(pattern, new, data, count=count) diff --git a/flexget/utils/parsers/series.py b/flexget/utils/parsers/series.py index f19dd3d534..e6c76ac45b 100644 --- a/flexget/utils/parsers/series.py +++ b/flexget/utils/parsers/series.py @@ -405,7 +405,7 @@ def parse(self, data=None, field=None, quality=None): match = re.search( self.re_not_in_word(r'(\d?\d)(\d\d)'), desperate, - re.IGNORECASE | re.UNICODE, + re.IGNORECASE, ) if match: logger.trace('-> had luck with SEE') diff --git a/flexget/utils/template.py b/flexget/utils/template.py index d379a0cad0..8089d713dd 100644 --- a/flexget/utils/template.py +++ b/flexget/utils/template.py @@ -252,7 +252,7 @@ def filter_strip_symbols(text: str) -> str: # Symbols that should be converted to white space result = re.sub(r'[ \(\)\-_\[\]\.]+', ' ', text) # Leftovers - result = re.sub(r"[^\w\d\s]", "", result, flags=re.UNICODE) + result = re.sub(r"[^\w\d\s]", "", result) # Replace multiple white spaces with one return ' '.join(result.split())