candidates=self.subsections.get(parts[0])# [s for s in self.subsections if s.name == parts[0]]
ifnotcandidates:
print_debug("Subsection '{}' not found.".format(parts[0]))
logger.debug("Subsection '{}' not found.".format(parts[0]))
returnNone
eliflen(candidates)>1:
print_warning("Multiple subsections with the same name found with name '{}' If no index is given, the first occurence in the input file is returned.".format(parts[0]))
logger.warning("Multiple subsections with the same name found with name '{}' If no index is given, the first occurence in the input file is returned.".format(parts[0]))
try:
subsection=candidates[index]
exceptIndexError:
print_error("Invalid subsection index given.")
logger.error("Invalid subsection index given.")
iflen(parts)==1:
returnsubsection
...
...
@@ -146,17 +147,17 @@ class InputSection(object):
"""
candidates=self.keywords.get(keyword)# [s for s in self.subsections if s.name == parts[0]]
ifnotcandidates:
print_debug("No keywords with name '{}' found in subsection '{}'".format(keyword,self.name))
logger.debug("No keywords with name '{}' found in subsection '{}'".format(keyword,self.name))
returnNone
eliflen(candidates)>1:
print_warning("Multiple keywords with the same name found with name '{}' If no index is given, the first occurence in the input file is returned.".format(parts[0]))
logger.warning("Multiple keywords found with name '{}'. If no index is given, the first occurence in the input file is returned.".format(keyword))
try:
result=candidates[index]
exceptIndexError:
print_error("Invalid keyword index given.")
logger.error("Invalid keyword index given.")
returnresult
defget_parameter(self):
ifself.paramsisNone:
print_debug("The section '{}' has no parameters set".format(self.name))
logger.debug("The section '{}' has no parameters set".format(self.name))
print_debug("Doing full string search from beginning.")
logger.debug("Doing full string search from beginning.")
returnregex.match(contents)
elifindex=="all":
print_debug("Doing full string search for all results.")
logger.debug("Doing full string search for all results.")
result=regex.findall(contents)
ifnotresult:
print_debug("No matches.")
logger.debug("No matches.")
elifindex>=0:
print_debug("Doing full string search with specified index.")
logger.debug("Doing full string search with specified index.")
iter=regex.finditer(contents)
i=0
whilei<=index:
...
...
@@ -180,9 +181,9 @@ class RegexEngine(object):
match=iter.next()
exceptStopIteration:
ifi==0:
print_debug("No results.")
logger.debug("No results.")
else:
print_debug("Invalid regex index.")
logger.debug("Invalid regex index.")
break
ifi==index:
result=match.groups()[0]
...
...
@@ -190,12 +191,12 @@ class RegexEngine(object):
elifindex<0:
matches=regex.findall(contents)
ifnotmatches:
print_debug("No matches.")
logger.debug("No matches.")
else:
try:
result=matches[index]
exceptIndexError:
print_debug("Invalid regex index.")
logger.debug("Invalid regex index.")
returnresult
...
...
@@ -208,33 +209,30 @@ class RegexEngine(object):
direction=regex.direction
index=regex.index
from_beginning=regex.from_beginning
print_debug("Doing blockwise search with separator: '{}', direction: '{}', from_beginning: '{}' and index '{}'".format(separator,direction,from_beginning,index))
logger.debug("Doing blockwise search with separator: '{}', direction: '{}', from_beginning: '{}' and index '{}'".format(separator,direction,from_beginning,index))
# Determine the direction in which the blocks are read