Python-checkins
Threads by month
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
June 2009
- 14 participants
- 814 discussions
Author: benjamin.peterson
Date: Mon Jun 1 03:55:25 2009
New Revision: 73091
Log:
deprecate set_prefix() and get_prefix() in favor of a prefix property
Modified:
sandbox/trunk/2to3/lib2to3/fixer_base.py
sandbox/trunk/2to3/lib2to3/fixer_util.py
sandbox/trunk/2to3/lib2to3/fixes/fix_apply.py
sandbox/trunk/2to3/lib2to3/fixes/fix_basestring.py
sandbox/trunk/2to3/lib2to3/fixes/fix_buffer.py
sandbox/trunk/2to3/lib2to3/fixes/fix_callable.py
sandbox/trunk/2to3/lib2to3/fixes/fix_dict.py
sandbox/trunk/2to3/lib2to3/fixes/fix_except.py
sandbox/trunk/2to3/lib2to3/fixes/fix_exec.py
sandbox/trunk/2to3/lib2to3/fixes/fix_execfile.py
sandbox/trunk/2to3/lib2to3/fixes/fix_filter.py
sandbox/trunk/2to3/lib2to3/fixes/fix_funcattrs.py
sandbox/trunk/2to3/lib2to3/fixes/fix_future.py
sandbox/trunk/2to3/lib2to3/fixes/fix_getcwdu.py
sandbox/trunk/2to3/lib2to3/fixes/fix_has_key.py
sandbox/trunk/2to3/lib2to3/fixes/fix_idioms.py
sandbox/trunk/2to3/lib2to3/fixes/fix_import.py
sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
sandbox/trunk/2to3/lib2to3/fixes/fix_input.py
sandbox/trunk/2to3/lib2to3/fixes/fix_intern.py
sandbox/trunk/2to3/lib2to3/fixes/fix_isinstance.py
sandbox/trunk/2to3/lib2to3/fixes/fix_itertools.py
sandbox/trunk/2to3/lib2to3/fixes/fix_itertools_imports.py
sandbox/trunk/2to3/lib2to3/fixes/fix_long.py
sandbox/trunk/2to3/lib2to3/fixes/fix_map.py
sandbox/trunk/2to3/lib2to3/fixes/fix_metaclass.py
sandbox/trunk/2to3/lib2to3/fixes/fix_methodattrs.py
sandbox/trunk/2to3/lib2to3/fixes/fix_ne.py
sandbox/trunk/2to3/lib2to3/fixes/fix_next.py
sandbox/trunk/2to3/lib2to3/fixes/fix_nonzero.py
sandbox/trunk/2to3/lib2to3/fixes/fix_numliterals.py
sandbox/trunk/2to3/lib2to3/fixes/fix_paren.py
sandbox/trunk/2to3/lib2to3/fixes/fix_print.py
sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py
sandbox/trunk/2to3/lib2to3/fixes/fix_raw_input.py
sandbox/trunk/2to3/lib2to3/fixes/fix_renames.py
sandbox/trunk/2to3/lib2to3/fixes/fix_repr.py
sandbox/trunk/2to3/lib2to3/fixes/fix_set_literal.py
sandbox/trunk/2to3/lib2to3/fixes/fix_standarderror.py
sandbox/trunk/2to3/lib2to3/fixes/fix_sys_exc.py
sandbox/trunk/2to3/lib2to3/fixes/fix_throw.py
sandbox/trunk/2to3/lib2to3/fixes/fix_tuple_params.py
sandbox/trunk/2to3/lib2to3/fixes/fix_types.py
sandbox/trunk/2to3/lib2to3/fixes/fix_urllib.py
sandbox/trunk/2to3/lib2to3/fixes/fix_ws_comma.py
sandbox/trunk/2to3/lib2to3/fixes/fix_xrange.py
sandbox/trunk/2to3/lib2to3/fixes/fix_xreadlines.py
sandbox/trunk/2to3/lib2to3/fixes/fix_zip.py
sandbox/trunk/2to3/lib2to3/pytree.py
sandbox/trunk/2to3/lib2to3/tests/data/fixers/myfixes/fix_parrot.py
sandbox/trunk/2to3/lib2to3/tests/test_pytree.py
Modified: sandbox/trunk/2to3/lib2to3/fixer_base.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixer_base.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixer_base.py Mon Jun 1 03:55:25 2009
@@ -120,7 +120,7 @@
"""
lineno = node.get_lineno()
for_output = node.clone()
- for_output.set_prefix(u"")
+ for_output.prefix = u""
msg = "Line %d: could not convert: %s"
self.log_message(msg % (lineno, for_output))
if reason:
Modified: sandbox/trunk/2to3/lib2to3/fixer_util.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixer_util.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixer_util.py Mon Jun 1 03:55:25 2009
@@ -27,11 +27,11 @@
if not isinstance(target, list):
target = [target]
if not isinstance(source, list):
- source.set_prefix(" ")
+ source.prefix = u" "
source = [source]
return Node(syms.atom,
- target + [Leaf(token.EQUAL, "=", prefix=" ")] + source)
+ target + [Leaf(token.EQUAL, u"=", prefix=u" ")] + source)
def Name(name, prefix=None):
"""Return a NAME leaf"""
@@ -60,7 +60,7 @@
"""A function call"""
node = Node(syms.power, [func_name, ArgList(args)])
if prefix is not None:
- node.set_prefix(prefix)
+ node.prefix = prefix
return node
def Newline():
@@ -89,18 +89,18 @@
If test is None, the "if test" part is omitted.
"""
- xp.set_prefix(u"")
- fp.set_prefix(u" ")
- it.set_prefix(u" ")
+ xp.prefix = u""
+ fp.prefix = u" "
+ it.prefix = u" "
for_leaf = Leaf(token.NAME, u"for")
- for_leaf.set_prefix(u" ")
+ for_leaf.prefix = u" "
in_leaf = Leaf(token.NAME, u"in")
- in_leaf.set_prefix(u" ")
+ in_leaf.prefix = u" "
inner_args = [for_leaf, fp, in_leaf, it]
if test:
- test.set_prefix(u" ")
+ test.prefix = u" "
if_leaf = Leaf(token.NAME, u"if")
- if_leaf.set_prefix(u" ")
+ if_leaf.prefix = u" "
inner_args.append(Node(syms.comp_if, [if_leaf, test]))
inner = Node(syms.listmaker, [xp, Node(syms.comp_for, inner_args)])
return Node(syms.atom,
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_apply.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_apply.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_apply.py Mon Jun 1 03:55:25 2009
@@ -33,25 +33,25 @@
func = results["func"]
args = results["args"]
kwds = results.get("kwds")
- prefix = node.get_prefix()
+ prefix = node.prefix
func = func.clone()
if (func.type not in (token.NAME, syms.atom) and
(func.type != syms.power or
func.children[-2].type == token.DOUBLESTAR)):
# Need to parenthesize
func = parenthesize(func)
- func.set_prefix("")
+ func.prefix = ""
args = args.clone()
- args.set_prefix("")
+ args.prefix = ""
if kwds is not None:
kwds = kwds.clone()
- kwds.set_prefix("")
+ kwds.prefix = ""
l_newargs = [pytree.Leaf(token.STAR, u"*"), args]
if kwds is not None:
l_newargs.extend([Comma(),
pytree.Leaf(token.DOUBLESTAR, u"**"),
kwds])
- l_newargs[-2].set_prefix(u" ") # that's the ** token
+ l_newargs[-2].prefix = u" " # that's the ** token
# XXX Sometimes we could be cleverer, e.g. apply(f, (x, y) + t)
# can be translated into f(x, y, *t) instead of f(*(x, y) + t)
#new = pytree.Node(syms.power, (func, ArgList(l_newargs)))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_basestring.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_basestring.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_basestring.py Mon Jun 1 03:55:25 2009
@@ -10,4 +10,4 @@
PATTERN = "'basestring'"
def transform(self, node, results):
- return Name(u"str", prefix=node.get_prefix())
+ return Name(u"str", prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_buffer.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_buffer.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_buffer.py Mon Jun 1 03:55:25 2009
@@ -18,4 +18,4 @@
def transform(self, node, results):
name = results["name"]
- name.replace(Name(u"memoryview", prefix=name.get_prefix()))
+ name.replace(Name(u"memoryview", prefix=name.prefix))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_callable.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_callable.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_callable.py Mon Jun 1 03:55:25 2009
@@ -28,4 +28,4 @@
func = results["func"]
args = [func.clone(), String(u', '), String(u"'__call__'")]
- return Call(Name(u"hasattr"), args, prefix=node.get_prefix())
+ return Call(Name(u"hasattr"), args, prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_dict.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_dict.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_dict.py Mon Jun 1 03:55:25 2009
@@ -61,15 +61,15 @@
args = head + [pytree.Node(syms.trailer,
[Dot(),
Name(method_name,
- prefix=method.get_prefix())]),
+ prefix=method.prefix)]),
results["parens"].clone()]
new = pytree.Node(syms.power, args)
if not special:
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(isiter and u"iter" or u"list"), [new])
if tail:
new = pytree.Node(syms.power, [new] + tail)
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
P1 = "power< func=NAME trailer< '(' node=any ')' > any* >"
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_except.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_except.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_except.py Mon Jun 1 03:55:25 2009
@@ -58,7 +58,7 @@
# Generate a new N for the except clause
new_N = Name(self.new_name(), prefix=u" ")
target = N.clone()
- target.set_prefix(u"")
+ target.prefix = u""
N.replace(new_N)
new_N = new_N.clone()
@@ -82,10 +82,10 @@
for child in reversed(suite_stmts[:i]):
e_suite.insert_child(0, child)
e_suite.insert_child(i, assign)
- elif N.get_prefix() == u"":
+ elif N.prefix == u"":
# No space after a comma is legal; no space after "as",
# not so much.
- N.set_prefix(u" ")
+ N.prefix = u" "
#TODO(cwinter) fix this when children becomes a smart list
children = [c.clone() for c in node.children[:3]] + try_cleanup + tail
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_exec.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_exec.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_exec.py Mon Jun 1 03:55:25 2009
@@ -30,10 +30,10 @@
b = results.get("b")
c = results.get("c")
args = [a.clone()]
- args[0].set_prefix("")
+ args[0].prefix = ""
if b is not None:
args.extend([Comma(), b.clone()])
if c is not None:
args.extend([Comma(), c.clone()])
- return Call(Name(u"exec"), args, prefix=node.get_prefix())
+ return Call(Name(u"exec"), args, prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_execfile.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_execfile.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_execfile.py Mon Jun 1 03:55:25 2009
@@ -38,7 +38,7 @@
# Wrap the open call in a compile call. This is so the filename will be
# preserved in the execed code.
filename_arg = filename.clone()
- filename_arg.set_prefix(u" ")
+ filename_arg.prefix = u" "
exec_str = String(u"'exec'", u" ")
compile_args = open_expr + [Comma(), filename_arg, Comma(), exec_str]
compile_call = Call(Name(u"compile"), compile_args, u"")
@@ -48,4 +48,4 @@
args.extend([Comma(), globals.clone()])
if locals is not None:
args.extend([Comma(), locals.clone()])
- return Call(Name(u"exec"), args, prefix=node.get_prefix())
+ return Call(Name(u"exec"), args, prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_filter.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_filter.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_filter.py Mon Jun 1 03:55:25 2009
@@ -69,7 +69,7 @@
if in_special_context(node):
return None
new = node.clone()
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(u"list"), [new])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_funcattrs.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_funcattrs.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_funcattrs.py Mon Jun 1 03:55:25 2009
@@ -16,4 +16,4 @@
def transform(self, node, results):
attr = results["attr"][0]
attr.replace(Name((u"__%s__" % attr.value[5:]),
- prefix=attr.get_prefix()))
+ prefix=attr.prefix))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_future.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_future.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_future.py Mon Jun 1 03:55:25 2009
@@ -16,5 +16,5 @@
def transform(self, node, results):
new = BlankLine()
- new.prefix = node.get_prefix()
+ new.prefix = node.prefix
return new
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_getcwdu.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_getcwdu.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_getcwdu.py Mon Jun 1 03:55:25 2009
@@ -15,4 +15,4 @@
def transform(self, node, results):
name = results["name"]
- name.replace(Name(u"getcwd", prefix=name.get_prefix()))
+ name.replace(Name(u"getcwd", prefix=name.prefix))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_has_key.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_has_key.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_has_key.py Mon Jun 1 03:55:25 2009
@@ -78,7 +78,7 @@
return None
negation = results.get("negation")
anchor = results["anchor"]
- prefix = node.get_prefix()
+ prefix = node.prefix
before = [n.clone() for n in results["before"]]
arg = results["arg"].clone()
after = results.get("after")
@@ -91,7 +91,7 @@
before = before[0]
else:
before = pytree.Node(syms.power, before)
- before.set_prefix(u" ")
+ before.prefix = u" "
n_op = Name(u"in", prefix=u" ")
if negation:
n_not = Name(u"not", prefix=u" ")
@@ -105,5 +105,5 @@
syms.arith_expr, syms.term,
syms.factor, syms.power):
new = parenthesize(new)
- new.set_prefix(prefix)
+ new.prefix = prefix
return new
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_idioms.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_idioms.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_idioms.py Mon Jun 1 03:55:25 2009
@@ -101,18 +101,18 @@
def transform_isinstance(self, node, results):
x = results["x"].clone() # The thing inside of type()
T = results["T"].clone() # The type being compared against
- x.set_prefix("")
- T.set_prefix(" ")
- test = Call(Name("isinstance"), [x, Comma(), T])
+ x.prefix = u""
+ T.prefix = u" "
+ test = Call(Name(u"isinstance"), [x, Comma(), T])
if "n" in results:
- test.set_prefix(u" ")
+ test.prefix = u" "
test = Node(syms.not_test, [Name(u"not"), test])
- test.set_prefix(node.get_prefix())
+ test.prefix = node.prefix
return test
def transform_while(self, node, results):
one = results["while"]
- one.replace(Name(u"True", prefix=one.get_prefix()))
+ one.replace(Name(u"True", prefix=one.prefix))
def transform_sort(self, node, results):
sort_stmt = results["sort"]
@@ -121,14 +121,14 @@
simple_expr = results.get("expr")
if list_call:
- list_call.replace(Name(u"sorted", prefix=list_call.get_prefix()))
+ list_call.replace(Name(u"sorted", prefix=list_call.prefix))
elif simple_expr:
new = simple_expr.clone()
- new.set_prefix(u"")
+ new.prefix = u""
simple_expr.replace(Call(Name(u"sorted"), [new],
- prefix=simple_expr.get_prefix()))
+ prefix=simple_expr.prefix))
else:
raise RuntimeError("should not have reached here")
sort_stmt.remove()
if next_stmt:
- next_stmt[0].set_prefix(sort_stmt.get_prefix())
+ next_stmt[0].prefix = sort_stmt.prefix
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_import.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_import.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_import.py Mon Jun 1 03:55:25 2009
@@ -73,7 +73,7 @@
return
new = FromImport('.', [imp])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
def probably_a_local_import(self, imp_name):
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py Mon Jun 1 03:55:25 2009
@@ -124,7 +124,7 @@
if import_mod:
mod_name = import_mod.value
new_name = unicode(self.mapping[mod_name])
- import_mod.replace(Name(new_name, prefix=import_mod.get_prefix()))
+ import_mod.replace(Name(new_name, prefix=import_mod.prefix))
if "name_import" in results:
# If it's not a "from x import x, y" or "import x as y" import,
# marked its usage to be replaced.
@@ -142,4 +142,4 @@
bare_name = results["bare_with_attr"][0]
new_name = self.replace.get(bare_name.value)
if new_name:
- bare_name.replace(Name(new_name, prefix=bare_name.get_prefix()))
+ bare_name.replace(Name(new_name, prefix=bare_name.prefix))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_input.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_input.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_input.py Mon Jun 1 03:55:25 2009
@@ -22,5 +22,5 @@
return
new = node.clone()
- new.set_prefix(u"")
- return Call(Name(u"eval"), [new], prefix=node.get_prefix())
+ new.prefix = u""
+ return Call(Name(u"eval"), [new], prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_intern.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_intern.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_intern.py Mon Jun 1 03:55:25 2009
@@ -39,6 +39,6 @@
[results["lpar"].clone(),
newarglist,
results["rpar"].clone()])] + after)
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
touch_import(None, u'sys', node)
return new
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_isinstance.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_isinstance.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_isinstance.py Mon Jun 1 03:55:25 2009
@@ -45,7 +45,7 @@
del new_args[-1]
if len(new_args) == 1:
atom = testlist.parent
- new_args[0].set_prefix(atom.get_prefix())
+ new_args[0].prefix = atom.prefix
atom.replace(new_args[0])
else:
args[:] = new_args
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_itertools.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_itertools.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_itertools.py Mon Jun 1 03:55:25 2009
@@ -30,12 +30,12 @@
if 'it' in results and func.value != u'ifilterfalse':
dot, it = (results['dot'], results['it'])
# Remove the 'itertools'
- prefix = it.get_prefix()
+ prefix = it.prefix
it.remove()
# Replace the node wich contains ('.', 'function') with the
# function (to be consistant with the second part of the pattern)
dot.remove()
func.parent.replace(func)
- prefix = prefix or func.get_prefix()
+ prefix = prefix or func.prefix
func.replace(Name(func.value[1:], prefix=prefix))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_itertools_imports.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_itertools_imports.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_itertools_imports.py Mon Jun 1 03:55:25 2009
@@ -46,7 +46,7 @@
# If there are no imports left, just get rid of the entire statement
if not (imports.children or getattr(imports, 'value', None)) or \
imports.parent is None:
- p = node.get_prefix()
+ p = node.prefix
node = BlankLine()
node.prefix = p
return node
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_long.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_long.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_long.py Mon Jun 1 03:55:25 2009
@@ -18,5 +18,5 @@
def transform(self, node, results):
if is_probably_builtin(node):
new = self.static_int.clone()
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_map.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_map.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_map.py Mon Jun 1 03:55:25 2009
@@ -63,7 +63,7 @@
if node.parent.type == syms.simple_stmt:
self.warning(node, "You should use a for loop here")
new = node.clone()
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(u"list"), [new])
elif "map_lambda" in results:
new = ListComp(results.get("xp").clone(),
@@ -76,7 +76,7 @@
if in_special_context(node):
return None
new = node.clone()
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(u"list"), [new])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_metaclass.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_metaclass.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_metaclass.py Mon Jun 1 03:55:25 2009
@@ -89,7 +89,7 @@
parent.insert_child(i, new_stmt)
new_leaf1 = new_stmt.children[0].children[0]
old_leaf1 = stmt_node.children[0].children[0]
- new_leaf1.set_prefix(old_leaf1.get_prefix())
+ new_leaf1.prefix = old_leaf1.prefix
def remove_trailing_newline(node):
@@ -136,7 +136,7 @@
node = kids.pop()
if isinstance(node, Leaf) and node.type != token.DEDENT:
if node.prefix:
- node.set_prefix('')
+ node.prefix = u''
return
else:
kids.extend(node.children[::-1])
@@ -191,19 +191,19 @@
# now stick the metaclass in the arglist
meta_txt = last_metaclass.children[0].children[0]
meta_txt.value = 'metaclass'
- orig_meta_prefix = meta_txt.get_prefix()
+ orig_meta_prefix = meta_txt.prefix
if arglist.children:
arglist.append_child(Leaf(token.COMMA, u','))
- meta_txt.set_prefix(u' ')
+ meta_txt.prefix = u' '
else:
- meta_txt.set_prefix(u'')
+ meta_txt.prefix = u''
# compact the expression "metaclass = Meta" -> "metaclass=Meta"
expr_stmt = last_metaclass.children[0]
assert expr_stmt.type == syms.expr_stmt
- expr_stmt.children[1].set_prefix(u'')
- expr_stmt.children[2].set_prefix(u'')
+ expr_stmt.children[1].prefix = u''
+ expr_stmt.children[2].prefix = u''
arglist.append_child(last_metaclass)
@@ -214,7 +214,7 @@
# one-liner that was just __metaclass_
suite.remove()
pass_leaf = Leaf(text_type, u'pass')
- pass_leaf.set_prefix(orig_meta_prefix)
+ pass_leaf.prefix = orig_meta_prefix
node.append_child(pass_leaf)
node.append_child(Leaf(token.NEWLINE, u'\n'))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_methodattrs.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_methodattrs.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_methodattrs.py Mon Jun 1 03:55:25 2009
@@ -20,4 +20,4 @@
def transform(self, node, results):
attr = results["attr"][0]
new = unicode(MAP[attr.value])
- attr.replace(Name(new, prefix=attr.get_prefix()))
+ attr.replace(Name(new, prefix=attr.prefix))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_ne.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_ne.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_ne.py Mon Jun 1 03:55:25 2009
@@ -17,6 +17,5 @@
return node.type == token.NOTEQUAL and node.value == u"<>"
def transform(self, node, results):
- new = pytree.Leaf(token.NOTEQUAL, u"!=")
- new.set_prefix(node.get_prefix())
+ new = pytree.Leaf(token.NOTEQUAL, u"!=", prefix=node.prefix)
return new
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_next.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_next.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_next.py Mon Jun 1 03:55:25 2009
@@ -52,13 +52,13 @@
if base:
if self.shadowed_next:
- attr.replace(Name(u"__next__", prefix=attr.get_prefix()))
+ attr.replace(Name(u"__next__", prefix=attr.prefix))
else:
base = [n.clone() for n in base]
- base[0].set_prefix(u"")
- node.replace(Call(Name(u"next", prefix=node.get_prefix()), base))
+ base[0].prefix = u""
+ node.replace(Call(Name(u"next", prefix=node.prefix), base))
elif name:
- n = Name(u"__next__", prefix=name.get_prefix())
+ n = Name(u"__next__", prefix=name.prefix)
name.replace(n)
elif attr:
# We don't do this transformation if we're assigning to "x.next".
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_nonzero.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_nonzero.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_nonzero.py Mon Jun 1 03:55:25 2009
@@ -16,5 +16,5 @@
def transform(self, node, results):
name = results["name"]
- new = Name(u"__bool__", prefix=name.get_prefix())
+ new = Name(u"__bool__", prefix=name.prefix)
name.replace(new)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_numliterals.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_numliterals.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_numliterals.py Mon Jun 1 03:55:25 2009
@@ -24,4 +24,4 @@
elif val.startswith(u'0') and val.isdigit() and len(set(val)) > 1:
val = u"0o" + val[1:]
- return Number(val, prefix=node.get_prefix())
+ return Number(val, prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_paren.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_paren.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_paren.py Mon Jun 1 03:55:25 2009
@@ -36,7 +36,7 @@
target = results["target"]
lparen = LParen()
- lparen.set_prefix(target.get_prefix())
- target.set_prefix(u"") # Make it hug the parentheses
+ lparen.prefix = target.prefix
+ target.prefix = u"" # Make it hug the parentheses
target.insert_child(0, lparen)
target.append_child(RParen())
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_print.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_print.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_print.py Mon Jun 1 03:55:25 2009
@@ -45,7 +45,7 @@
if bare_print:
# Special-case print all by itself
bare_print.replace(Call(Name(u"print"), [],
- prefix=bare_print.get_prefix()))
+ prefix=bare_print.prefix))
return
assert node.children[0] == Name(u"print")
args = node.children[1:]
@@ -65,7 +65,7 @@
# Now synthesize a print(args, sep=..., end=..., file=...) node.
l_args = [arg.clone() for arg in args]
if l_args:
- l_args[0].set_prefix(u"")
+ 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)))
@@ -74,17 +74,17 @@
if file is not None:
self.add_kwarg(l_args, u"file", file)
n_stmt = Call(Name(u"print"), l_args)
- n_stmt.set_prefix(node.get_prefix())
+ n_stmt.prefix = node.prefix
return n_stmt
def add_kwarg(self, l_nodes, s_kwd, n_expr):
# XXX All this prefix-setting may lose comments (though rarely)
- n_expr.set_prefix(u"")
+ n_expr.prefix = u""
n_argument = pytree.Node(self.syms.argument,
(Name(s_kwd),
pytree.Leaf(token.EQUAL, u"="),
n_expr))
if l_nodes:
l_nodes.append(Comma())
- n_argument.set_prefix(u" ")
+ n_argument.prefix = u" "
l_nodes.append(n_argument)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py Mon Jun 1 03:55:25 2009
@@ -52,31 +52,31 @@
# exc.children[1:-1] is the unparenthesized tuple
# exc.children[1].children[0] is the first element of the tuple
exc = exc.children[1].children[0].clone()
- exc.set_prefix(" ")
+ exc.prefix = " "
if "val" not in results:
# One-argument raise
new = pytree.Node(syms.raise_stmt, [Name(u"raise"), exc])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
val = results["val"].clone()
if is_tuple(val):
args = [c.clone() for c in val.children[1:-1]]
else:
- val.set_prefix(u"")
+ val.prefix = u""
args = [val]
if "tb" in results:
tb = results["tb"].clone()
- tb.set_prefix(u"")
+ tb.prefix = u""
e = Call(exc, args)
with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])]
new = pytree.Node(syms.simple_stmt, [Name(u"raise")] + with_tb)
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
else:
return pytree.Node(syms.raise_stmt,
[Name(u"raise"), Call(exc, args)],
- prefix=node.get_prefix())
+ prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_raw_input.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_raw_input.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_raw_input.py Mon Jun 1 03:55:25 2009
@@ -13,4 +13,4 @@
def transform(self, node, results):
name = results["name"]
- name.replace(Name(u"input", prefix=name.get_prefix()))
+ name.replace(Name(u"input", prefix=name.prefix))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_renames.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_renames.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_renames.py Mon Jun 1 03:55:25 2009
@@ -66,4 +66,4 @@
if mod_name and attr_name:
new_attr = unicode(LOOKUP[(mod_name.value, attr_name.value)])
- attr_name.replace(Name(new_attr, prefix=attr_name.get_prefix()))
+ attr_name.replace(Name(new_attr, prefix=attr_name.prefix))
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_repr.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_repr.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_repr.py Mon Jun 1 03:55:25 2009
@@ -19,4 +19,4 @@
if expr.type == self.syms.testlist1:
expr = parenthesize(expr)
- return Call(Name(u"repr"), [expr], prefix=node.get_prefix())
+ return Call(Name(u"repr"), [expr], prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_set_literal.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_set_literal.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_set_literal.py Mon Jun 1 03:55:25 2009
@@ -38,15 +38,15 @@
literal.extend(n.clone() for n in items.children)
literal.append(pytree.Leaf(token.RBRACE, u"}"))
# Set the prefix of the right brace to that of the ')' or ']'
- literal[-1].set_prefix(items.next_sibling.get_prefix())
+ literal[-1].prefix = items.next_sibling.prefix
maker = pytree.Node(syms.dictsetmaker, literal)
- maker.set_prefix(node.get_prefix())
+ maker.prefix = node.prefix
# If the original was a one tuple, we need to remove the extra comma.
if len(maker.children) == 4:
n = maker.children[2]
n.remove()
- maker.children[-1].set_prefix(n.get_prefix())
+ maker.children[-1].prefix = n.prefix
# Finally, replace the set call with our shiny new literal.
return maker
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_standarderror.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_standarderror.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_standarderror.py Mon Jun 1 03:55:25 2009
@@ -15,4 +15,4 @@
"""
def transform(self, node, results):
- return Name(u"Exception", prefix=node.get_prefix())
+ return Name(u"Exception", prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_sys_exc.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_sys_exc.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_sys_exc.py Mon Jun 1 03:55:25 2009
@@ -22,8 +22,8 @@
sys_attr = results["attribute"][0]
index = Number(self.exc_info.index(sys_attr.value))
- call = Call(Name(u"exc_info"), prefix=sys_attr.get_prefix())
+ call = Call(Name(u"exc_info"), prefix=sys_attr.prefix)
attr = Attr(Name(u"sys"), call)
- attr[1].children[0].set_prefix(results["dot"].get_prefix())
+ attr[1].children[0].prefix = results["dot"].prefix
attr.append(Subscript(index))
- return Node(syms.power, attr, prefix=node.get_prefix())
+ return Node(syms.power, attr, prefix=node.prefix)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_throw.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_throw.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_throw.py Mon Jun 1 03:55:25 2009
@@ -40,14 +40,14 @@
if is_tuple(val):
args = [c.clone() for c in val.children[1:-1]]
else:
- val.set_prefix(u"")
+ val.prefix = u""
args = [val]
throw_args = results["args"]
if "tb" in results:
tb = results["tb"].clone()
- tb.set_prefix(u"")
+ tb.prefix = u""
e = Call(exc, args)
with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])]
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_tuple_params.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_tuple_params.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_tuple_params.py Mon Jun 1 03:55:25 2009
@@ -63,10 +63,10 @@
def handle_tuple(tuple_arg, add_prefix=False):
n = Name(self.new_name())
arg = tuple_arg.clone()
- arg.set_prefix(u"")
+ arg.prefix = u""
stmt = Assign(arg, n.clone())
if add_prefix:
- n.set_prefix(u" ")
+ n.prefix = u" "
tuple_arg.replace(n)
new_lines.append(pytree.Node(syms.simple_stmt,
[stmt, end.clone()]))
@@ -91,14 +91,14 @@
# TODO(cwinter) suite-cleanup
after = start
if start == 0:
- new_lines[0].set_prefix(u" ")
+ new_lines[0].prefix = u" "
elif is_docstring(suite[0].children[start]):
- new_lines[0].set_prefix(indent)
+ new_lines[0].prefix = indent
after = start + 1
suite[0].children[after:after] = new_lines
for i in range(after+1, after+len(new_lines)+1):
- suite[0].children[i].set_prefix(indent)
+ suite[0].children[i].prefix = indent
suite[0].changed()
def transform_lambda(self, node, results):
@@ -109,7 +109,7 @@
# Replace lambda ((((x)))): x with lambda x: x
if inner.type == token.NAME:
inner = inner.clone()
- inner.set_prefix(u" ")
+ inner.prefix = u" "
args.replace(inner)
return
@@ -124,7 +124,7 @@
subscripts = [c.clone() for c in to_index[n.value]]
new = pytree.Node(syms.power,
[new_param.clone()] + subscripts)
- new.set_prefix(n.get_prefix())
+ new.prefix = n.prefix
n.replace(new)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_types.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_types.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_types.py Mon Jun 1 03:55:25 2009
@@ -58,5 +58,5 @@
def transform(self, node, results):
new_value = unicode(_TYPE_MAPPING.get(results["name"].value))
if new_value:
- return Name(new_value, prefix=node.get_prefix())
+ return Name(new_value, prefix=node.prefix)
return None
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_urllib.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_urllib.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_urllib.py Mon Jun 1 03:55:25 2009
@@ -78,7 +78,7 @@
replacements.
"""
import_mod = results.get('module')
- pref = import_mod.get_prefix()
+ pref = import_mod.prefix
names = []
@@ -94,7 +94,7 @@
module.
"""
mod_member = results.get('mod_member')
- pref = mod_member.get_prefix()
+ pref = mod_member.prefix
member = results.get('member')
# Simple case with only a single member being imported
@@ -162,7 +162,7 @@
break
if new_name:
module_dot.replace(Name(new_name,
- prefix=module_dot.get_prefix()))
+ prefix=module_dot.prefix))
else:
self.cannot_convert(node, 'This is an invalid module element')
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_ws_comma.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_ws_comma.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_ws_comma.py Mon Jun 1 03:55:25 2009
@@ -26,14 +26,14 @@
comma = False
for child in new.children:
if child in self.SEPS:
- prefix = child.get_prefix()
+ prefix = child.prefix
if prefix.isspace() and u"\n" not in prefix:
- child.set_prefix(u"")
+ child.prefix = u""
comma = True
else:
if comma:
- prefix = child.get_prefix()
+ prefix = child.prefix
if not prefix:
- child.set_prefix(u" ")
+ child.prefix = u" "
comma = False
return new
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_xrange.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_xrange.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_xrange.py Mon Jun 1 03:55:25 2009
@@ -28,14 +28,14 @@
def transform_xrange(self, node, results):
name = results["name"]
- name.replace(Name(u"range", prefix=name.get_prefix()))
+ name.replace(Name(u"range", prefix=name.prefix))
def transform_range(self, node, results):
if not self.in_special_context(node):
range_call = Call(Name(u"range"), [results["args"].clone()])
# Encase the range call in list().
list_call = Call(Name(u"list"), [range_call],
- prefix=node.get_prefix())
+ prefix=node.prefix)
# Put things that were after the range() call after the list call.
for n in results["rest"]:
list_call.append_child(n)
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_xreadlines.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_xreadlines.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_xreadlines.py Mon Jun 1 03:55:25 2009
@@ -19,6 +19,6 @@
no_call = results.get("no_call")
if no_call:
- no_call.replace(Name(u"__iter__", prefix=no_call.get_prefix()))
+ no_call.replace(Name(u"__iter__", prefix=no_call.prefix))
else:
node.replace([x.clone() for x in results["call"]])
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_zip.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_zip.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_zip.py Mon Jun 1 03:55:25 2009
@@ -28,7 +28,7 @@
return None
new = node.clone()
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(u"list"), [new])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
Modified: sandbox/trunk/2to3/lib2to3/pytree.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/pytree.py (original)
+++ sandbox/trunk/2to3/lib2to3/pytree.py Mon Jun 1 03:55:25 2009
@@ -13,6 +13,7 @@
__author__ = "Guido van Rossum <guido(a)python.org>"
import sys
+import warnings
from StringIO import StringIO
@@ -111,17 +112,21 @@
"""
Set the prefix for the node (see Leaf class).
- This must be implemented by the concrete subclass.
+ DEPRECATED; use the prefix property directly.
"""
- raise NotImplementedError
+ warnings.warn("set_prefix() is deprecated; use the prefix property",
+ DeprecationWarning, stacklevel=2)
+ self.prefix = prefix
def get_prefix(self):
"""
Return the prefix for the node (see Leaf class).
- This must be implemented by the concrete subclass.
+ DEPRECATED; use the prefix property directly.
"""
- raise NotImplementedError
+ warnings.warn("get_prefix() is deprecated; use the prefix property",
+ DeprecationWarning, stacklevel=2)
+ return self.prefix
def replace(self, new):
"""Replace this node with a new one in the parent."""
@@ -209,12 +214,12 @@
def get_suffix(self):
"""
Return the string immediately following the invocant node. This is
- effectively equivalent to node.next_sibling.get_prefix()
+ effectively equivalent to node.next_sibling.prefix
"""
next_sib = self.next_sibling
if next_sib is None:
return u""
- return next_sib.get_prefix()
+ return next_sib.prefix
if sys.version_info < (3, 0):
def __str__(self):
@@ -241,7 +246,7 @@
assert ch.parent is None, repr(ch)
ch.parent = self
if prefix is not None:
- self.set_prefix(prefix)
+ self.prefix = prefix
def __repr__(self):
"""Return a canonical string representation."""
@@ -282,24 +287,19 @@
for node in child.post_order():
yield node
- def set_prefix(self, prefix):
- """
- Set the prefix for the node.
-
- This passes the responsibility on to the first child.
- """
- if self.children:
- self.children[0].set_prefix(prefix)
-
- def get_prefix(self):
+ @property
+ def prefix(self):
"""
- Return the prefix for the node.
-
- This passes the call on to the first child.
+ The whitespace and comments preceding this node in the input.
"""
if not self.children:
return ""
- return self.children[0].get_prefix()
+ return self.children[0].prefix
+
+ @prefix.setter
+ def prefix(self, prefix):
+ if self.children:
+ self.children[0].prefix = prefix
def set_child(self, i, child):
"""
@@ -335,9 +335,9 @@
"""Concrete implementation for leaf nodes."""
# Default values for instance variables
- prefix = "" # Whitespace and comments preceding this token in the input
- lineno = 0 # Line where this token starts in the input
- column = 0 # Column where this token tarts in the input
+ _prefix = "" # Whitespace and comments preceding this token in the input
+ lineno = 0 # Line where this token starts in the input
+ column = 0 # Column where this token tarts in the input
def __init__(self, type, value, context=None, prefix=None):
"""
@@ -348,11 +348,11 @@
"""
assert 0 <= type < 256, type
if context is not None:
- self.prefix, (self.lineno, self.column) = context
+ self._prefix, (self.lineno, self.column) = context
self.type = type
self.value = value
if prefix is not None:
- self.prefix = prefix
+ self._prefix = prefix
def __repr__(self):
"""Return a canonical string representation."""
@@ -388,14 +388,17 @@
"""Return a pre-order iterator for the tree."""
yield self
- def set_prefix(self, prefix):
- """Set the prefix for the node."""
- self.changed()
- self.prefix = prefix
+ @property
+ def prefix(self):
+ """
+ The whitespace and comments preceding this token in the input.
+ """
+ return self._prefix
- def get_prefix(self):
- """Return the prefix for the node."""
- return self.prefix
+ @prefix.setter
+ def prefix(self, prefix):
+ self.changed()
+ self._prefix = prefix
def convert(gr, raw_node):
Modified: sandbox/trunk/2to3/lib2to3/tests/data/fixers/myfixes/fix_parrot.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/data/fixers/myfixes/fix_parrot.py (original)
+++ sandbox/trunk/2to3/lib2to3/tests/data/fixers/myfixes/fix_parrot.py Mon Jun 1 03:55:25 2009
@@ -10,4 +10,4 @@
def transform(self, node, results):
name = results["name"]
- name.replace(Name("cheese", name.get_prefix()))
+ name.replace(Name("cheese", name.prefix))
Modified: sandbox/trunk/2to3/lib2to3/tests/test_pytree.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_pytree.py (original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_pytree.py Mon Jun 1 03:55:25 2009
@@ -10,6 +10,8 @@
especially when debugging a test.
"""
+import warnings
+
# Testing imports
from . import support
@@ -28,6 +30,20 @@
"""Unit tests for nodes (Base, Leaf, Node)."""
+ def test_deprecated_prefix_methods(self):
+ l = pytree.Leaf(100, "foo")
+ with warnings.catch_warnings(record=True) as w:
+ self.assertEqual(l.get_prefix(), "")
+ l.set_prefix("hi")
+ self.assertEqual(l.prefix, "hi")
+ self.assertEqual(len(w), 2)
+ for warning in w:
+ self.assertTrue(warning.category is DeprecationWarning)
+ self.assertEqual(str(w[0].message), "get_prefix() is deprecated; " \
+ "use the prefix property")
+ self.assertEqual(str(w[1].message), "set_prefix() is deprecated; " \
+ "use the prefix property")
+
def testBaseCantConstruct(self):
if __debug__:
# Test that instantiating Base() raises an AssertionError
@@ -52,7 +68,7 @@
# Make sure that the Leaf's value is stringified. Failing to
# do this can cause a TypeError in certain situations.
l1 = pytree.Leaf(2, 5)
- l1.set_prefix("foo_")
+ l1.prefix = "foo_"
self.assertEqual(str(l1), "foo_5")
def testLeafEq(self):
@@ -66,10 +82,10 @@
def testLeafPrefix(self):
l1 = pytree.Leaf(100, "foo")
- self.assertEqual(l1.get_prefix(), "")
+ self.assertEqual(l1.prefix, "")
self.failIf(l1.was_changed)
- l1.set_prefix(" ##\n\n")
- self.assertEqual(l1.get_prefix(), " ##\n\n")
+ l1.prefix = " ##\n\n"
+ self.assertEqual(l1.prefix, " ##\n\n")
self.failUnless(l1.was_changed)
def testNode(self):
@@ -94,26 +110,26 @@
def testNodePrefix(self):
l1 = pytree.Leaf(100, "foo")
- self.assertEqual(l1.get_prefix(), "")
+ self.assertEqual(l1.prefix, "")
n1 = pytree.Node(1000, [l1])
- self.assertEqual(n1.get_prefix(), "")
- n1.set_prefix(" ")
- self.assertEqual(n1.get_prefix(), " ")
- self.assertEqual(l1.get_prefix(), " ")
+ self.assertEqual(n1.prefix, "")
+ n1.prefix = " "
+ self.assertEqual(n1.prefix, " ")
+ self.assertEqual(l1.prefix, " ")
def testGetSuffix(self):
l1 = pytree.Leaf(100, "foo", prefix="a")
l2 = pytree.Leaf(100, "bar", prefix="b")
n1 = pytree.Node(1000, [l1, l2])
- self.assertEqual(l1.get_suffix(), l2.get_prefix())
+ self.assertEqual(l1.get_suffix(), l2.prefix)
self.assertEqual(l2.get_suffix(), "")
self.assertEqual(n1.get_suffix(), "")
l3 = pytree.Leaf(100, "bar", prefix="c")
n2 = pytree.Node(1000, [n1, l3])
- self.assertEqual(n1.get_suffix(), l3.get_prefix())
+ self.assertEqual(n1.get_suffix(), l3.prefix)
self.assertEqual(l3.get_suffix(), "")
self.assertEqual(n2.get_suffix(), "")
@@ -204,7 +220,7 @@
for prefix in ("xyz_", ""):
l1 = pytree.Leaf(100, "self", prefix=prefix)
self.failUnless(str(l1), prefix + "self")
- self.assertEqual(l1.get_prefix(), prefix)
+ self.assertEqual(l1.prefix, prefix)
def testNodeConstructorPrefix(self):
for prefix in ("xyz_", ""):
@@ -212,9 +228,9 @@
l2 = pytree.Leaf(100, "foo", prefix="_")
n1 = pytree.Node(1000, [l1, l2], prefix=prefix)
self.failUnless(str(n1), prefix + "self_foo")
- self.assertEqual(n1.get_prefix(), prefix)
- self.assertEqual(l1.get_prefix(), prefix)
- self.assertEqual(l2.get_prefix(), "_")
+ self.assertEqual(n1.prefix, prefix)
+ self.assertEqual(l1.prefix, prefix)
+ self.assertEqual(l2.prefix, "_")
def testRemove(self):
l1 = pytree.Leaf(100, "foo")
1
0
June 1, 2009
Author: guilherme.polo
Date: Mon Jun 1 03:45:08 2009
New Revision: 73090
Log:
Added support for passing keyword arguments in setup_master.
Modified:
python/branches/tk_and_idle_maintenance/Lib/lib-tk/ttk.py
Modified: python/branches/tk_and_idle_maintenance/Lib/lib-tk/ttk.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/lib-tk/ttk.py (original)
+++ python/branches/tk_and_idle_maintenance/Lib/lib-tk/ttk.py Mon Jun 1 03:45:08 2009
@@ -349,16 +349,18 @@
return adict
-def setup_master(master=None):
+def setup_master(master=None, **kw):
"""If master is not None, itself is returned. If master is None,
the default master is returned if there is one, otherwise a new
- master is created and returned.
+ master is created, defined as default and then returned. Any
+ other passed options will be repassed to the Tkinter.Tk class.
If it is not allowed to use the default root and master is None,
RuntimeError is raised."""
if master is None:
if Tkinter._support_default_root:
- master = Tkinter._default_root or Tkinter.Tk()
+ master = Tkinter._default_root or Tkinter.Tk(**kw)
+ Tkinter._default_root = master
else:
raise RuntimeError(
"No master specified and Tkinter is "
1
0
Author: andrew.kuchling
Date: Mon Jun 1 02:14:19 2009
New Revision: 73089
Log:
The class for regexes isn't called RegexObject any more; correct the text
Modified:
python/trunk/Doc/howto/regex.rst
Modified: python/trunk/Doc/howto/regex.rst
==============================================================================
--- python/trunk/Doc/howto/regex.rst (original)
+++ python/trunk/Doc/howto/regex.rst Mon Jun 1 02:14:19 2009
@@ -257,7 +257,7 @@
Compiling Regular Expressions
-----------------------------
-Regular expressions are compiled into :class:`RegexObject` instances, which have
+Regular expressions are compiled into pattern objects, which have
methods for various operations such as searching for pattern matches or
performing string substitutions. ::
@@ -336,7 +336,7 @@
------------------
Once you have an object representing a compiled regular expression, what do you
-do with it? :class:`RegexObject` instances have several methods and attributes.
+do with it? Pattern objects have several methods and attributes.
Only the most significant ones will be covered here; consult the :mod:`re` docs
for a complete listing.
@@ -427,8 +427,8 @@
and :meth:`end` return the starting and ending index of the match. :meth:`span`
returns both start and end indexes in a single tuple. Since the :meth:`match`
method only checks if the RE matches at the start of a string, :meth:`start`
-will always be zero. However, the :meth:`search` method of :class:`RegexObject`
-instances scans through the string, so the match may not start at zero in that
+will always be zero. However, the :meth:`search` method of patterns
+scans through the string, so the match may not start at zero in that
case. ::
>>> print p.match('::: message')
@@ -450,7 +450,7 @@
else:
print 'No match'
-Two :class:`RegexObject` methods return all of the matches for a pattern.
+Two pattern methods return all of the matches for a pattern.
:meth:`findall` returns a list of matching strings::
>>> p = re.compile('\d+')
@@ -475,10 +475,10 @@
Module-Level Functions
----------------------
-You don't have to create a :class:`RegexObject` and call its methods; the
+You don't have to create a pattern object and call its methods; the
:mod:`re` module also provides top-level functions called :func:`match`,
:func:`search`, :func:`findall`, :func:`sub`, and so forth. These functions
-take the same arguments as the corresponding :class:`RegexObject` method, with
+take the same arguments as the corresponding pattern method, with
the RE string added as the first argument, and still return either ``None`` or a
:class:`MatchObject` instance. ::
@@ -487,12 +487,12 @@
>>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998')
<re.MatchObject instance at 80c5978>
-Under the hood, these functions simply produce a :class:`RegexObject` for you
+Under the hood, these functions simply create a pattern object for you
and call the appropriate method on it. They also store the compiled object in a
cache, so future calls using the same RE are faster.
Should you use these module-level functions, or should you get the
-:class:`RegexObject` and call its methods yourself? That choice depends on how
+pattern and call its methods yourself? That choice depends on how
frequently the RE will be used, and on your personal coding style. If the RE is
being used at only one point in the code, then the module functions are probably
more convenient. If a program contains a lot of regular expressions, or re-uses
@@ -1030,7 +1030,7 @@
Up to this point, we've simply performed searches against a static string.
Regular expressions are also commonly used to modify strings in various ways,
-using the following :class:`RegexObject` methods:
+using the following pattern methods:
+------------------+-----------------------------------------------+
| Method/Attribute | Purpose |
@@ -1050,7 +1050,7 @@
Splitting Strings
-----------------
-The :meth:`split` method of a :class:`RegexObject` splits a string apart
+The :meth:`split` method of a pattern splits a string apart
wherever the RE matches, returning a list of the pieces. It's similar to the
:meth:`split` method of strings but provides much more generality in the
delimiters that you can split by; :meth:`split` only supports splitting by
@@ -1195,10 +1195,10 @@
'Call 0xffd2 for printing, 0xc000 for user code.'
When using the module-level :func:`re.sub` function, the pattern is passed as
-the first argument. The pattern may be a string or a :class:`RegexObject`; if
+the first argument. The pattern may be provided as an object or as a string; if
you need to specify regular expression flags, you must either use a
-:class:`RegexObject` as the first parameter, or use embedded modifiers in the
-pattern, e.g. ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``.
+pattern object as the first parameter, or use embedded modifiers in the
+pattern string, e.g. ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``.
Common Problems
1
0
Author: andrew.kuchling
Date: Mon Jun 1 02:11:36 2009
New Revision: 73088
Log:
Typo fix; constant name is uppercase
Modified:
python/branches/py3k/Doc/library/re.rst
Modified: python/branches/py3k/Doc/library/re.rst
==============================================================================
--- python/branches/py3k/Doc/library/re.rst (original)
+++ python/branches/py3k/Doc/library/re.rst Mon Jun 1 02:11:36 2009
@@ -215,7 +215,7 @@
``(?aiLmsux)``
(One or more letters from the set ``'a'``, ``'i'``, ``'L'``, ``'m'``,
``'s'``, ``'u'``, ``'x'``.) The group matches the empty string; the
- letters set the corresponding flags: :const:`re.a` (ASCII-only matching),
+ letters set the corresponding flags: :const:`re.A` (ASCII-only matching),
:const:`re.I` (ignore case), :const:`re.L` (locale dependent),
:const:`re.M` (multi-line), :const:`re.S` (dot matches all),
and :const:`re.X` (verbose), for the entire regular expression. (The
1
0