当前位置: 首页>>代码示例>>Python>>正文


Python InteractiveInterpreter.showsyntaxerror方法代码示例

本文整理汇总了Python中code.InteractiveInterpreter.showsyntaxerror方法的典型用法代码示例。如果您正苦于以下问题:Python InteractiveInterpreter.showsyntaxerror方法的具体用法?Python InteractiveInterpreter.showsyntaxerror怎么用?Python InteractiveInterpreter.showsyntaxerror使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在code.InteractiveInterpreter的用法示例。


在下文中一共展示了InteractiveInterpreter.showsyntaxerror方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execfile

# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def execfile(self, filename, source=None):
        "Execute an existing file"
        if source is None:
            with tokenize.open(filename) as fp:
                source = fp.read()
        try:
            code = compile(source, filename, "exec")
        except (OverflowError, SyntaxError):
            self.tkconsole.resetoutput()
            print('*** Error in script or command!\n'
                 'Traceback (most recent call last):',
                  file=self.tkconsole.stderr)
            InteractiveInterpreter.showsyntaxerror(self, filename)
            self.tkconsole.showprompt()
        else:
            self.runcode(code) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:PyShell.py

示例2: showsyntaxerror

# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def showsyntaxerror(self, filename=None):
        """Override Interactive Interpreter method: Use Colorizing

        Color the offending position instead of printing it and pointing at it
        with a caret.

        """
        tkconsole = self.tkconsole
        text = tkconsole.text
        text.tag_remove("ERROR", "1.0", "end")
        type, value, tb = sys.exc_info()
        msg = getattr(value, 'msg', '') or value or "<no detail available>"
        lineno = getattr(value, 'lineno', '') or 1
        offset = getattr(value, 'offset', '') or 0
        if offset == 0:
            lineno += 1 #mark end of offending line
        if lineno == 1:
            pos = "iomark + %d chars" % (offset-1)
        else:
            pos = "iomark linestart + %d lines + %d chars" % \
                  (lineno-1, offset-1)
        tkconsole.colorize_syntax_error(text, pos)
        tkconsole.resetoutput()
        self.write("SyntaxError: %s\n" % msg)
        tkconsole.showprompt() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:PyShell.py

示例3: execfile

# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def execfile(self, filename, source=None):
        "Execute an existing file"
        if source is None:
            source = open(filename, "r").read()
        try:
            code = compile(source, filename, "exec")
        except (OverflowError, SyntaxError):
            self.tkconsole.resetoutput()
            tkerr = self.tkconsole.stderr
            print>>tkerr, '*** Error in script or command!\n'
            print>>tkerr, 'Traceback (most recent call last):'
            InteractiveInterpreter.showsyntaxerror(self, filename)
            self.tkconsole.showprompt()
        else:
            self.runcode(code) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:17,代码来源:PyShell.py

示例4: showsyntaxerror

# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def showsyntaxerror(self, filename=None):
        """Extend base class method: Add Colorizing

        Color the offending position instead of printing it and pointing at it
        with a caret.

        """
        text = self.tkconsole.text
        stuff = self.unpackerror()
        if stuff:
            msg, lineno, offset, line = stuff
            if lineno == 1:
                pos = "iomark + %d chars" % (offset-1)
            else:
                pos = "iomark linestart + %d lines + %d chars" % \
                      (lineno-1, offset-1)
            text.tag_add("ERROR", pos)
            text.see(pos)
            char = text.get(pos)
            if char and char in IDENTCHARS:
                text.tag_add("ERROR", pos + " wordstart", pos)
            self.tkconsole.resetoutput()
            self.write("SyntaxError: %s\n" % str(msg))
        else:
            self.tkconsole.resetoutput()
            InteractiveInterpreter.showsyntaxerror(self, filename)
        self.tkconsole.showprompt() 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:29,代码来源:PyShell.py

示例5: execfile

# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def execfile(self, filename, source=None):
        "Execute an existing file"
        if source is None:
            source = open(filename, "r").read()
        try:
            code = compile(source, filename, "exec")
        except (OverflowError, SyntaxError):
            self.tkconsole.resetoutput()
            print('*** Error in script or command!\n'
                  'Traceback (most recent call last):',
                  file=self.tkconsole.stderr)
            InteractiveInterpreter.showsyntaxerror(self, filename)
            self.tkconsole.showprompt()
        else:
            self.runcode(code) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:17,代码来源:PyShell.py

示例6: showsyntaxerror

# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def showsyntaxerror(self, filename):
        self.stdout.write('\n')

        with disabled_excepthook():
            InteractiveInterpreter.showsyntaxerror(self, filename)
        self.done_signal.emit(False, None) 
开发者ID:marcus-oscarsson,项目名称:pyqtconsole,代码行数:8,代码来源:interpreter.py

示例7: execfile

# 需要导入模块: from code import InteractiveInterpreter [as 别名]
# 或者: from code.InteractiveInterpreter import showsyntaxerror [as 别名]
def execfile(self, filename, source=None):
        "Execute an existing file"
        if source is None:
            source = open(filename, "r").read()
        try:
            code = compile(source, filename, "exec", dont_inherit=True)
        except (OverflowError, SyntaxError):
            self.tkconsole.resetoutput()
            print('*** Error in script or command!\n'
                  'Traceback (most recent call last):',
                  file=self.tkconsole.stderr)
            InteractiveInterpreter.showsyntaxerror(self, filename)
            self.tkconsole.showprompt()
        else:
            self.runcode(code) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:17,代码来源:PyShell.py


注:本文中的code.InteractiveInterpreter.showsyntaxerror方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。