nginx_parser.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:gixy 作者: yandex 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号