Improved error reporting for regular expressions in personal.ini.

This commit is contained in:
Jim Miller 2014-11-02 09:45:13 -06:00
parent 34990ff044
commit 69ee06e2ce
2 changed files with 20 additions and 5 deletions

View file

@ -75,3 +75,12 @@ class FailedToWriteOutput(Exception):
def __str__(self):
return self.error
class RegularExpresssionFailed(Exception):
def __init__(self,error,regex,line):
self.error=error
self.regex=regex
self.line=line
def __str__(self):
return "Regular Expression Error '%s' in regex '%s' in line '%s'"%(self.error,self.regex,self.line)

View file

@ -224,6 +224,12 @@ langs = {
"Devanagari":"hi",
}
def re_compile(regex,line):
try:
return re.compile(regex)
except Exception, e:
raise exceptions.RegularExpresssionFailed(e,regex,line)
class InExMatch:
keys = []
regex = None
@ -234,11 +240,11 @@ class InExMatch:
if "=~" in line:
(self.keys,self.match) = line.split("=~")
self.match = self.match.replace(SPACE_REPLACE,' ')
self.regex = re.compile(self.match)
self.regex = re_compile(self.match,line)
elif "!~" in line:
(self.keys,self.match) = line.split("!~")
self.match = self.match.replace(SPACE_REPLACE,' ')
self.regex = re.compile(self.match)
self.regex = re_compile(self.match,line)
self.negate = True
elif "==" in line:
(self.keys,self.match) = line.split("==")
@ -423,9 +429,9 @@ class Story(Configurable):
(regexp,replacement)=parts
if regexp:
regexp = re.compile(regexp)
regexp = re_compile(regexp,line)
if condregexp:
condregexp = re.compile(condregexp)
condregexp = re_compile(condregexp,line)
# A way to explicitly include spaces in the
# replacement string. The .ini parser eats any
# trailing spaces.
@ -722,7 +728,7 @@ class Story(Configurable):
if not allowunsafefilename:
values={}
pattern = re.compile(self.getConfig("output_filename_safepattern",r"[^a-zA-Z0-9_\. \[\]\(\)&'-]+"))
pattern = re_compile(self.getConfig("output_filename_safepattern",r"[^a-zA-Z0-9_\. \[\]\(\)&'-]+"),"output_filename_safepattern")
for k in origvalues.keys():
values[k]=re.sub(pattern,'_', removeAllEntities(self.getMetadata(k)))