mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
[XEND] Make SXP be compatible with sequencetypes (Tuples and Lists)
Signed-off-by: Alastair Tse <atse@xensource.com>
This commit is contained in:
1 parent
97465697cb
commit
7904cd04b9
1 file changed
+9
-9
@@ -378,7 +378,7 @@ def atomp(sxpr):
|
||||
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(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)):
|
||||
|
||||