Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vivodi committed Jan 24, 2025
1 parent 69b1163 commit a3c69be
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions flexget/components/bittorrent/trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion flexget/components/emby/api_emby.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
logger = logger.bind(name='api_emby')


class EmbyApiBase(ABC):
class EmbyApiBase(ABC): # noqa: B024
"""
Base Class to all API integratios
"""
Expand Down
2 changes: 1 addition & 1 deletion flexget/components/imdb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
12 changes: 4 additions & 8 deletions flexget/components/irc/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion flexget/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion flexget/plugins/cli/try_regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions flexget/plugins/filter/regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion flexget/plugins/metainfo/content_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions flexget/utils/parsers/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions flexget/utils/parsers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion flexget/utils/parsers/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion flexget/utils/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit a3c69be

Please sign in to comment.