[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] [XEND] Make SXP be compatible with sequencetypes (Tuples and Lists)



# HG changeset patch
# User Alastair Tse <atse@xxxxxxxxxxxxx>
# Node ID aab988d497eadd058087c615a3882ebec56770bb
# Parent  137d40894a8b8e130a4be4f29582e8ad5450b4ec
[XEND] Make SXP be compatible with sequencetypes (Tuples and Lists)

Signed-off-by: Alastair Tse <atse@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/sxp.py |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff -r 137d40894a8b -r aab988d497ea tools/python/xen/xend/sxp.py
--- a/tools/python/xen/xend/sxp.py      Thu Oct 05 17:29:19 2006 +0100
+++ b/tools/python/xen/xend/sxp.py      Thu Oct 05 17:29:19 2006 +0100
@@ -378,7 +378,7 @@ def show(sxpr, out=sys.stdout):
 def show(sxpr, out=sys.stdout):
     """Print an sxpr in bracketed (lisp-style) syntax.
     """
-    if isinstance(sxpr, types.ListType):
+    if isinstance(sxpr, (types.ListType, types.TupleType)):
         out.write(k_list_open)
         i = 0
         for x in sxpr:
@@ -396,7 +396,7 @@ def show_xml(sxpr, out=sys.stdout):
 def show_xml(sxpr, out=sys.stdout):
     """Print an sxpr in XML syntax.
     """
-    if isinstance(sxpr, types.ListType):
+    if isinstance(sxpr, (types.ListType, types.TupleType)):
         element = name(sxpr)
         out.write('<%s' % element)
         for attr in attributes(sxpr):
@@ -419,7 +419,7 @@ def elementp(sxpr, elt=None):
     sxpr sxpr
     elt  element type
     """
-    return (isinstance(sxpr, types.ListType)
+    return (isinstance(sxpr, (types.ListType, types.TupleType))
             and len(sxpr)
             and (None == elt or sxpr[0] == elt))
 
@@ -435,7 +435,7 @@ def name(sxpr):
     val = None
     if isinstance(sxpr, types.StringType):
         val = sxpr
-    elif isinstance(sxpr, types.ListType) and len(sxpr):
+    elif isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr):
         val = sxpr[0]
     return val
 
@@ -447,7 +447,7 @@ def attributes(sxpr):
     returns attribute list
     """
     val = []
-    if isinstance(sxpr, types.ListType) and len(sxpr) > 1:
+    if isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr) > 1:
         attr = sxpr[1]
         if elementp(attr, k_attr_open):
             val = attr[1:]
@@ -477,7 +477,7 @@ def children(sxpr, elt=None):
     returns children (filtered by elt if specified)
     """
     val = []
-    if isinstance(sxpr, types.ListType) and len(sxpr) > 1:
+    if isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr) > 1:
         i = 1
         x = sxpr[i]
         if elementp(x, k_attr_open):
@@ -566,7 +566,7 @@ def with_id(sxpr, id, val=None):
 
     return s-exp or val
     """
-    if isinstance(sxpr, types.ListType):
+    if isinstance(sxpr, (types.ListType, types.TupleType)):
         for n in sxpr:
             if has_id(n, id):
                 val = n
@@ -586,7 +586,7 @@ def child_with_id(sxpr, id, val=None):
 
     return s-exp or val
     """
-    if isinstance(sxpr, types.ListType):
+    if isinstance(sxpr, (types.ListType, types.TupleType)):
         for n in sxpr:
             if has_id(n, id):
                 val = n
@@ -608,7 +608,7 @@ def elements(sxpr, ctxt=None):
     yield (sxpr, ctxt)
     i = 0
     for n in children(sxpr):
-        if isinstance(n, types.ListType):
+        if isinstance(n, (types.ListType, types.TupleType)):
             # 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)):

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.