本文整理汇总了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;未经允许,请勿转载。 |
请发表评论