[Python-checkins] r54574 - sandbox/trunk/2to3/fixes/util.py

collin.winter python-checkins at python.org
Mon Mar 26 16:55:24 CEST 2007


Author: collin.winter
Date: Mon Mar 26 16:55:22 2007
New Revision: 54574

Modified:
   sandbox/trunk/2to3/fixes/util.py
Log:
Add comments, new portability section.

Modified: sandbox/trunk/2to3/fixes/util.py
==============================================================================
--- sandbox/trunk/2to3/fixes/util.py	(original)
+++ sandbox/trunk/2to3/fixes/util.py	Mon Mar 26 16:55:22 2007
@@ -15,6 +15,10 @@
 lparen_leaf = Leaf(token.LPAR, "(")
 rparen_leaf = Leaf(token.RPAR, ")")
 
+###########################################################
+### Common node-construction "macros"
+###########################################################
+
 def Assign(target, source):
     """Build an assignment statement"""
     if not isinstance(target, tuple):
@@ -66,6 +70,10 @@
 def String(string, prefix=None):
     """A string leaf"""
     return Leaf(token.STRING, string, prefix=prefix)
+    
+###########################################################
+### Determine whether a node represents a given literal
+###########################################################
 
 def is_tuple(node):
     """Does the node represent a tuple literal?"""
@@ -84,5 +92,23 @@
             and isinstance(node.children[0], Leaf)
             and isinstance(node.children[-1], Leaf)
             and node.children[0].value == "["
-            and node.children[-1].value == "]") 
+            and node.children[-1].value == "]")
+
+###########################################################
+### Common portability code. This allows fixers to do, eg,
+###  "from fixes.util import set" and forget about it.
+###########################################################
        
+try:
+    any = any
+except NameError:
+    def any(l):
+        for o in l:
+            if o:
+                return True
+        return False
+
+try:
+    set = set
+except NameError:
+    from sets import Set as set


More information about the Python-checkins mailing list