當前位置: 首頁>>代碼示例>>Python>>正文


Python tabnanny.process_tokens方法代碼示例

本文整理匯總了Python中tabnanny.process_tokens方法的典型用法代碼示例。如果您正苦於以下問題:Python tabnanny.process_tokens方法的具體用法?Python tabnanny.process_tokens怎麽用?Python tabnanny.process_tokens使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tabnanny的用法示例。


在下文中一共展示了tabnanny.process_tokens方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_parse_error

# 需要導入模塊: import tabnanny [as 別名]
# 或者: from tabnanny import process_tokens [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 process_tokens [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 process_tokens [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 process_tokens [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

示例5: tabnanny

# 需要導入模塊: import tabnanny [as 別名]
# 或者: from tabnanny import process_tokens [as 別名]
def tabnanny(self, filename):
        f = open(filename, 'r')
        try:
            tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
        except tokenize.TokenError, msg:
            msgtxt, (lineno, start) = msg
            self.editwin.gotoline(lineno)
            self.errorbox("Tabnanny Tokenizing Error",
                          "Token Error: %s" % msgtxt)
            return False 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:12,代碼來源:ScriptBinding.py


注:本文中的tabnanny.process_tokens方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。