console.py 文件源码

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

项目:scimitar 作者: parsa 项目源码 文件源码
def query(self, cmd):
        if not self.con.isalive():
            raise errors.DeadConsoleError
        self.con.sendline(cmd)
        try:
            p_re = [self.ps1_re]
            if self.exit_re:
                p_re.insert(0, self.exit_re)
            if self.prompt_re:
                p_re.insert(0, self.prompt_re)

            pattern_index = self.con.expect(p_re)
            if pattern_index == 0:
                return self.con.before
            elif pattern_index == 1:
                self.close()
                return '^exit'
            elif pattern_index == 2:
                self.con.close()
                return '^kill'
        except (pexpect.TIMEOUT, pexpect.EOF):
            ## Connection's probably dead, close the socket
            self.close()
            raise errors.ConsoleSessionError
        raise errors.UnexpectedResponseError
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号