def parse(self, content, root=None, path_info=None):
if not root:
root = block.Root()
try:
parsed = self.parser.parse(content)
except ParseException as e:
error_msg = 'char {char} (line:{line}, col:{col})'.format(char=e.loc, line=e.lineno, col=e.col)
if path_info:
LOG.error('Failed to parse config "{file}": {error}'.format(file=path_info, error=error_msg))
else:
LOG.error('Failed to parse config: {error}'.format(error=error_msg))
raise InvalidConfiguration(error_msg)
if len(parsed) and parsed[0].getName() == 'file_delimiter':
# Were parse nginx dump
LOG.info('Switched to parse nginx configuration dump.')
root_filename = self._prepare_dump(parsed)
self.is_dump = True
self.cwd = os.path.dirname(root_filename)
parsed = self.configs[root_filename]
self.parse_block(parsed, root)
return root
评论列表
文章目录