Skip to contentSkip to conversation

cleanup sxp.py

PATCH New aq 1 participant 1 message Jun 3, 2005

lore
Share & tools
lore

aq

author
#0 lore raw

PATCH 1/1 cleanup sxp.py

This patch removes unused functions from sxp.py (against -unstable [email protected])

$ diffstat sxp.patch 
 sxp.py |  138 -----------------------------------------------------------------
 1 files changed, 138 deletions(-)

===== tools/python/xen/xend/sxp.py 1.16 vs edited =====

tools/python/xen/xend/sxp.py +0 -138
@@ -24,7 +24,6 @@
     "Parser", 
     "atomp", 
     "show", 
-    "show_xml", 
     "elementp", 
     "name", 
     "attributes", 
@@ -33,19 +32,9 @@
     "child", 
     "child_at", 
     "child0", 
-    "child1", 
-    "child2", 
-    "child3", 
-    "child4", 
     "child_value",
-    "has_id", 
-    "with_id", 
-    "child_with_id", 
-    "elements",
     "merge",
     "to_string",
-    "from_string",
-    "all_from_string",
     "parse", 
     ]
 
@@ -374,26 +363,6 @@
     else:
         out.write(repr(str(sxpr)))
 
-def show_xml(sxpr, out=sys.stdout):
-    """Print an sxpr in XML syntax.
-    """
-    if isinstance(sxpr, types.ListType):
-        element = name(sxpr)
-        out.write('<%s' % element)
-        for attr in attributes(sxpr):
-            out.write(' %s=%s' % (attr[0], attr[1]))
-        out.write('>')
-        i = 0
-        for x in children(sxpr):
-            if i: out.write(' ')
-            show_xml(x, out)
-            i += 1
-        out.write('</%s>' % element)
-    elif isinstance(sxpr, types.StringType) and atomp(sxpr):
-        out.write(sxpr)
-    else:
-        out.write(str(sxpr))
-
 def elementp(sxpr, elt=None):
     """Check if an sxpr is an element of the given type.
 
@@ -500,26 +469,6 @@
     """
     return child_at(sxpr, 0, val)
 
-def child1(sxpr, val=None):
-    """Get the first child.
-    """
-    return child_at(sxpr, 1, val)
-
-def child2(sxpr, val=None):
-    """Get the second child.
-    """
-    return child_at(sxpr, 2, val)
-
-def child3(sxpr, val=None):
-    """Get the third child.
-    """
-    return child_at(sxpr, 3, val)
-
-def child4(sxpr, val=None):
-    """Get the fourth child.
-    """
-    return child_at(sxpr, 4, val)
-
 def child_value(sxpr, elt, val=None):
     """Get the value of the first child of the given element type.
     Assumes the child has an atomic value.
@@ -533,69 +482,6 @@
         val = child_at(kid, 0, val)
     return val
 
-def has_id(sxpr, id):
-    """Test if an s-expression has a given id.
-    """
-    return attribute(sxpr, 'id') == id
-
-def with_id(sxpr, id, val=None):
-    """Find the first s-expression with a given id, at any depth.
-
-    sxpr   s-exp or list
-    id     id
-    val    value if not found (default None)
-
-    return s-exp or val
-    """
-    if isinstance(sxpr, types.ListType):
-        for n in sxpr:
-            if has_id(n, id):
-                val = n
-                break
-            v = with_id(n, id)
-            if v is None: continue
-            val = v
-            break
-    return val
-
-def child_with_id(sxpr, id, val=None):
-    """Find the first child with a given id.
-
-    sxpr   s-exp or list
-    id     id
-    val    value if not found (default None)
-
-    return s-exp or val
-    """
-    if isinstance(sxpr, types.ListType):
-        for n in sxpr:
-            if has_id(n, id):
-                val = n
-                break
-    return val
-
-def elements(sxpr, ctxt=None):
-    """Generate elements (at any depth).
-    Visit elements in pre-order.
-    Values generated are (node, context)
-    The context is None if there is no parent, otherwise
-    (index, parent, context) where index is the node's index w.r.t its parent,
-    and context is the parent's context.
-
-    sxpr   s-exp
-
-    returns generator
-    """
-    yield (sxpr, ctxt)
-    i = 0
-    for n in children(sxpr):
-        if isinstance(n, types.ListType):
-            # Calling elements() recursively does not generate recursively,
-            # it just returns a generator object. So we must iterate over it.
-            for v in elements(n, (i, sxpr, ctxt)):
-                yield v
-        i += 1
-
 def merge(s1, s2):
     """Merge sxprs s1 and s2.
     Returns an sxpr containing all the fields from s1 and s2, with
@@ -679,30 +565,6 @@
     val = io.getvalue()
     io.close()
     return val
-
-def from_string(str):
-    """Create an sxpr by parsing a string.
-
-    str string
-    returns sxpr
-    """
-    io = StringIO(str)
-    vals = parse(io)
-    if vals is []:
-        return None
-    else:
-        return vals[0]
-    
-
-def all_from_string(str):
-    """Create an sxpr list by parsing a string.
-
-    str string
-    returns sxpr list
-    """
-    io = StringIO(str)
-    vals = parse(io)
-    return vals
 
 def parse(io):
     """Completely parse all input from 'io'.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel