mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Read the search replace patterns file differently
Might fix patterns not being recognized on windows
This commit is contained in:
parent
495bece5e8
commit
1d945ced65
@ -331,31 +331,29 @@ def abspath(x):
|
|||||||
|
|
||||||
|
|
||||||
def read_sr_patterns(path, log=None):
|
def read_sr_patterns(path, log=None):
|
||||||
import json, re, codecs
|
import json, re
|
||||||
pats = []
|
pats = []
|
||||||
with codecs.open(path, 'r', 'utf-8') as f:
|
with open(path, 'rb') as f:
|
||||||
pat = None
|
lines = f.read().decode('utf-8').splitlines()
|
||||||
for line in f.readlines():
|
pat = None
|
||||||
if line.endswith(u'\n'):
|
for line in lines:
|
||||||
line = line[:-1]
|
if pat is None:
|
||||||
|
if not line.strip():
|
||||||
if pat is None:
|
continue
|
||||||
if not line.strip():
|
try:
|
||||||
continue
|
re.compile(line)
|
||||||
try:
|
except:
|
||||||
re.compile(line)
|
msg = u'Invalid regular expression: %r from file: %r'%(
|
||||||
except:
|
line, path)
|
||||||
msg = u'Invalid regular expression: %r from file: %r'%(
|
if log is not None:
|
||||||
line, path)
|
log.error(msg)
|
||||||
if log is not None:
|
raise SystemExit(1)
|
||||||
log.error(msg)
|
else:
|
||||||
raise SystemExit(1)
|
raise ValueError(msg)
|
||||||
else:
|
pat = line
|
||||||
raise ValueError(msg)
|
else:
|
||||||
pat = line
|
pats.append((pat, line))
|
||||||
else:
|
pat = None
|
||||||
pats.append((pat, line))
|
|
||||||
pat = None
|
|
||||||
return json.dumps(pats)
|
return json.dumps(pats)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user