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


Python tabnanny.NannyNag方法代码示例

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


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

示例1: get_parse_error

# 需要导入模块: import tabnanny [as 别名]
# 或者: from tabnanny import NannyNag [as 别名]
def get_parse_error(code):
    """
    Checks code for ambiguous tabs or other basic parsing issues.

    :param code: a string containing a file's worth of Python code
    :returns: a string containing a description of the first parse error encountered,
              or None if the code is ok
    """
    # note that this uses non-public elements from stdlib's tabnanny, because tabnanny
    # is (very frustratingly) written only to be used as a script, but using it that way
    # in this context requires writing temporarily files, running subprocesses, blah blah blah
    code_buffer = StringIO(code)
    try:
        tabnanny.process_tokens(tokenize.generate_tokens(code_buffer.readline))
    except tokenize.TokenError as err:
        return "Could not parse code: %s" % err
    except IndentationError as err:
        return "Indentation error: %s" % err
    except tabnanny.NannyNag as err:
        return "Ambiguous tab at line %d; line is '%s'." % (err.get_lineno(), err.get_line())
    return None 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:23,代码来源:check_whitespace.py

示例2: tabnanny

# 需要导入模块: import tabnanny [as 别名]
# 或者: from tabnanny import NannyNag [as 别名]
def tabnanny(self, filename):
        f = open(filename, 'r')
        try:
            tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
        except tokenize.TokenError as msg:
            msgtxt, (lineno, start) = msg
            self.editwin.gotoline(lineno)
            self.errorbox("Tabnanny Tokenizing Error",
                          "Token Error: %s" % msgtxt)
            return False
        except tabnanny.NannyNag as nag:
            # The error messages from tabnanny are too confusing...
            self.editwin.gotoline(nag.get_lineno())
            self.errorbox("Tab/space error", indent_message)
            return False
        return True 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:18,代码来源:ScriptBinding.py

示例3: tabnanny

# 需要导入模块: import tabnanny [as 别名]
# 或者: from tabnanny import NannyNag [as 别名]
def tabnanny(self, filename):
        # XXX: tabnanny should work on binary files as well
        with tokenize.open(filename) as f:
            try:
                tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
            except tokenize.TokenError as msg:
                msgtxt, (lineno, start) = msg.args
                self.editwin.gotoline(lineno)
                self.errorbox("Tabnanny Tokenizing Error",
                              "Token Error: %s" % msgtxt)
                return False
            except tabnanny.NannyNag as nag:
                # The error messages from tabnanny are too confusing...
                self.editwin.gotoline(nag.get_lineno())
                self.errorbox("Tab/space error", indent_message)
                return False
        return True 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:ScriptBinding.py

示例4: tabnanny

# 需要导入模块: import tabnanny [as 别名]
# 或者: from tabnanny import NannyNag [as 别名]
def tabnanny(self, filename):
        f = open(filename, 'r')
        try:
            tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
        except tokenize.TokenError as msg:
            msgtxt, (lineno, start) = msg.args
            self.editwin.gotoline(lineno)
            self.errorbox("Tabnanny Tokenizing Error",
                          "Token Error: %s" % msgtxt)
            return False
        except tabnanny.NannyNag as nag:
            # The error messages from tabnanny are too confusing...
            self.editwin.gotoline(nag.get_lineno())
            self.errorbox("Tab/space error", indent_message)
            return False
        return True 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:18,代码来源:ScriptBinding.py


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