diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-09-19 19:22:43 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-09-19 19:22:43 +0000 |
commit | 047f0117bf3ccf5b7e1a36b760a5c75f988bc72e (patch) | |
tree | e88519e576f0b671a601427d09ebf695dba9fce2 /lib/sexp | |
parent | ddc03061218dc00a664aaf10a6a2fec2b604deac (diff) |
More repository/signing/marshalling/crypto work for glider.
git-svn-id: file:///home/or/svnrepo/updater/trunk@16928 55e972cd-5a19-0410-ae62-a4d7a52db4cd
Diffstat (limited to 'lib/sexp')
-rw-r--r-- | lib/sexp/access.py | 27 | ||||
-rw-r--r-- | lib/sexp/tests.py | 1 |
2 files changed, 23 insertions, 5 deletions
diff --git a/lib/sexp/access.py b/lib/sexp/access.py index c5182f0..74f5022 100644 --- a/lib/sexp/access.py +++ b/lib/sexp/access.py @@ -97,6 +97,21 @@ def s_descendants(s, tags=()): s = s[idx] idx = 0 +def attrs_to_dict(sexpr): + """Return a dictionary mapping keys of the attributes in sexpr to + their values. Only the last element in the attribute list counts. + + >>> s = [ 'given-name', + ... ["Tigra", 'Rachel'], ["Bunny", "Elana"] ] + >>> attrs_to_dict(s) + {'Tigra': ['Rachel'], 'Bunny': ['Elana']} + """ + result = {} + for ch in sexpr: + tag = s_tag(ch) + if tag is not None: + result[tag]=ch[1:] + return result class SExpr(list): """Wraps an s-expresion list to return its tagged children as attributes. @@ -177,9 +192,9 @@ def _s_lookup_all(s, path, callback): if s_tag(ch) == p_item[2:]: _s_lookup_all(ch, path[p_idx+1:], callback) else: - s = s_child(s, p_item) - if s is None: - return + for ch in s_children(s, p_item): + _s_lookup_all(ch, path[p_idx+1:], callback) + return callback(s) @@ -190,7 +205,9 @@ def s_lookup_all(s, path): >>> x = ['alice', ... ['father', 'bob', ['mother', 'carol'], ['father', 'dave']], ... ['mother', 'eve', ['mother', 'frances', ['dog', 'spot']], - ... ['father', 'gill']]] + ... ['father', 'gill']], + ... ['marmoset', 'tiffany'], + ... ['marmoset', 'gilbert'] ] >>> s_lookup_all(x, "father") [['father', 'bob', ['mother', 'carol'], ['father', 'dave']]] >>> s_lookup_all(x, "father.mother") @@ -203,6 +220,8 @@ def s_lookup_all(s, path): [['dog', 'spot']] >>> s_lookup_all(x, "mother.*.dog") [['dog', 'spot']] + >>> s_lookup_all(x, "marmoset") + [['marmoset', 'tiffany'], ['marmoset', 'gilbert']] """ result = [] _s_lookup_all(s, path, result.append) diff --git a/lib/sexp/tests.py b/lib/sexp/tests.py index 7decd03..bfd1053 100644 --- a/lib/sexp/tests.py +++ b/lib/sexp/tests.py @@ -11,7 +11,6 @@ class EncodingTest(unittest.TestCase): self.assertEquals(1,1) - def suite(): import sexp.tests suite = unittest.TestSuite() |