• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tabnanny.process_tokens函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_with_correct_code

    def test_with_correct_code(self, MockNannyNag):
        """A python source code without any whitespace related problems."""

        with TemporaryPyFile(SOURCE_CODES["error_free"]) as file_path:
            with open(file_path) as f:
                tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
            self.assertFalse(MockNannyNag.called)
开发者ID:Eyepea,项目名称:cpython,代码行数:7,代码来源:test_tabnanny.py


示例2: tabnanny

 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:jiangxilong,项目名称:OpenSPARC_T1,代码行数:10,代码来源:ScriptBinding.py


示例3: tabnanny

 def tabnanny(self, filename):
     import tabnanny
     import tokenize
     f = open(filename, 'r')
     try:
         tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
     except tokenize.TokenError, msg:
         self.errorbox("Token error",
                       "Token error:\n%s" % str(msg))
         return 0
开发者ID:Edude01,项目名称:movable-python,代码行数:10,代码来源:ScriptBinding.py


示例4: tabnanny

    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:
            self.editwin.gotoline(nag.get_lineno())
            self.errorbox("Tab/space error", indent_message)
            return False

        return True
开发者ID:webiumsk,项目名称:WOT-0.9.12,代码行数:15,代码来源:scriptbinding.py


示例5: file_passes

    def file_passes(self, temp_filename, original_filename=None):
        if original_filename is None:
            original_filename = temp_filename

        with open(temp_filename, "r") as temp_file:
            code = temp_file.read()

        # 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.StringIO(code)
        try:
            tabnanny.process_tokens(tokenize.generate_tokens(code_buffer.readline))
        except tokenize.TokenError, e:
            return False, "# Could not parse code in %(f)s: %(e)s" % dict(e=e, f=original_filename)
开发者ID:nouiz,项目名称:pygithooks,代码行数:15,代码来源:check_tabs.py


示例6: get_parse_error

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, err:
        return "Could not parse code: %s" % err
开发者ID:AlexArgus,项目名称:Theano,代码行数:16,代码来源:check_whitespace.py


示例7: test_with_errored_codes_samples

    def test_with_errored_codes_samples(self):
        """A python source code with whitespace related sampled problems."""

        # "tab_space_errored_1": executes block under type == tokenize.INDENT
        #                        at `tabnanny.process_tokens()`.
        # "tab space_errored_2": executes block under
        #                        `check_equal and type not in JUNK` condition at
        #                        `tabnanny.process_tokens()`.

        for key in ["tab_space_errored_1", "tab_space_errored_2"]:
            with self.subTest(key=key):
                with TemporaryPyFile(SOURCE_CODES[key]) as file_path:
                    with open(file_path) as f:
                        tokens = tokenize.generate_tokens(f.readline)
                        with self.assertRaises(tabnanny.NannyNag):
                            tabnanny.process_tokens(tokens)
开发者ID:Eyepea,项目名称:cpython,代码行数:16,代码来源:test_tabnanny.py


示例8: tabnanny

 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:Apoorvadabhere,项目名称:cpython,代码行数:17,代码来源:runscript.py


示例9: tabnanny

 def tabnanny(self, filename):
     # XXX: tabnanny should work on binary files as well
     with open(filename, 'r', encoding='iso-8859-1') as f:
         two_lines = f.readline() + f.readline()
     encoding = IOBinding.coding_spec(two_lines)
     if not encoding:
         encoding = 'utf-8'
     f = open(filename, 'r', encoding=encoding)
     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:AndyPanda95,项目名称:python-for-android,代码行数:22,代码来源:ScriptBinding.py


示例10: file_passes

    def file_passes(self, temp_filename, original_filename=None):
        if original_filename is None:
            original_filename = temp_filename

        with open(temp_filename, "r") as temp_file:
            code = temp_file.read()

        # 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.StringIO(code)
        try:
            tabnanny.process_tokens(tokenize.generate_tokens(code_buffer.readline))
        except tokenize.TokenError as e:
            return False, "# Could not parse code in {f}: {e}".format(e=e, f=original_filename)
        except IndentationError as e:
            return False, "# Indentation error in {f}: {e}".format(e=e, f=original_filename)
        except tabnanny.NannyNag as e:
            return False, "# Ambiguous tab in {f} at line {line}; line is '{contents}'.".format(line=e.get_lineno(),
                                                                                                contents=e.get_line().rstrip(),
                                                                                                f=original_filename)
        return True, None
开发者ID:delallea,项目名称:pygithooks,代码行数:22,代码来源:check_tabs.py


示例11:

"""Extension to execute code outside the Python shell window.
开发者ID:mcyril,项目名称:ravel-ftn,代码行数:1,代码来源:ScriptBinding.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tabular.tabarray函数代码示例发布时间:2022-05-27
下一篇:
Python tablib.Dataset类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap