本文整理汇总了Python中lib2to3.pgen2.token.RIGHTSHIFT属性的典型用法代码示例。如果您正苦于以下问题:Python token.RIGHTSHIFT属性的具体用法?Python token.RIGHTSHIFT怎么用?Python token.RIGHTSHIFT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类lib2to3.pgen2.token
的用法示例。
在下文中一共展示了token.RIGHTSHIFT属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transform
# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import RIGHTSHIFT [as 别名]
def transform(self, node, results):
assert results
bare_print = results.get("bare")
if bare_print:
# Special-case print all by itself.
bare_print.replace(Call(Name(u"print"), [],
prefix=bare_print.prefix))
# The "from __future__ import print_function"" declaration is added
# by the fix_print_with_import fixer, so we skip it here.
# add_future(node, u'print_function')
return
assert node.children[0] == Name(u"print")
args = node.children[1:]
if len(args) == 1 and parend_expr.match(args[0]):
# We don't want to keep sticking parens around an
# already-parenthesised expression.
return
sep = end = file = None
if args and args[-1] == Comma():
args = args[:-1]
end = " "
if args and args[0] == pytree.Leaf(token.RIGHTSHIFT, u">>"):
assert len(args) >= 2
file = args[1].clone()
args = args[3:] # Strip a possible comma after the file expression
# Now synthesize a print(args, sep=..., end=..., file=...) node.
l_args = [arg.clone() for arg in args]
if l_args:
l_args[0].prefix = u""
if sep is not None or end is not None or file is not None:
if sep is not None:
self.add_kwarg(l_args, u"sep", String(repr(sep)))
if end is not None:
self.add_kwarg(l_args, u"end", String(repr(end)))
if file is not None:
self.add_kwarg(l_args, u"file", file)
n_stmt = Call(Name(u"print"), l_args)
n_stmt.prefix = node.prefix
# Note that there are corner cases where adding this future-import is
# incorrect, for example when the file also has a 'print ()' statement
# that was intended to print "()".
# add_future(node, u'print_function')
return n_stmt