Read the search replace patterns file differently

Might fix patterns not being recognized on windows
This commit is contained in:
Kovid Goyal 2017-06-12 20:58:12 +05:30
parent 495bece5e8
commit 1d945ced65
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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)