Python 2.6 tvsort bug (fix inside)
Posted: December 5th, 2009, 10:43 am
Found another bug that results in post processing crash with the following traceback:
The culprit is trying to re-compile an already compiled regex, which does not work in python 2.6:
Even though this works in python 2.5, there is no need to compile twice. I would either remove line 630, or not compile in 625-627. The function could probably be better written like so:
Code: Select all
File "/home/cjones/local/usenet/sabnzbd/tvsort.py", line 630, in check_for_multiple
regex = re.compile(regex, re.I)
File "/usr/lib/python2.6/re.py", line 190, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.6/re.py", line 238, in _compile
raise ValueError('Cannot process flags argument with a compiled pattern')
ValueError: Cannot process flags argument with a compiled pattern
Code: Select all
621: def check_for_multiple(self, files):
622: expressions = []
623: matched_files = []
624:
625: expressions.append(re.compile('cd\W?(\d)\W', re.I)) # .cd1.avi
626: expressions.append(re.compile('\w\W?([\w\d])$', re.I)) # blah1.avi blaha.avi
627: expressions.append(re.compile('\w\W([\w\d])\W', re.I)) # blah-1-ok.avi blah-a-ok.avi
628:
629: for regex in expressions:
630: regex = re.compile(regex, re.I)
631: matched_files = check_for_sequence(regex, files)
632: if matched_files:
633: return matched_files
634: return ''
Code: Select all
def check_for_multiple(self, files):
for regex in r'cd\W?(\d)\W', r'\w\W?([\w\d])$', r'\w\W([\w\d])\W':
matched_files = check_for_sequence(re.compile(regex, re.I), files)
if matched_files:
return matched_files
return ''