diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2010-01-25 13:12:51 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2010-01-25 13:12:51 +0000 |
| commit | 44510813d26dca74622497b0217c730b779205b4 (patch) | |
| tree | 9028252b4b1135dddeec55500d389097430f26a6 /python/qpid/validator.py | |
| parent | cdee35e16d30c13132a5c6b7ce5f84db2e5fdfd8 (diff) | |
| download | qpid-python-44510813d26dca74622497b0217c730b779205b4.tar.gz | |
verify that bindings are only specified for queues
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@902803 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/validator.py')
| -rw-r--r-- | python/qpid/validator.py | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/python/qpid/validator.py b/python/qpid/validator.py index 8bd1c98736..7bd62b68f8 100644 --- a/python/qpid/validator.py +++ b/python/qpid/validator.py @@ -17,12 +17,23 @@ # under the License. # +class Context: + + def __init__(self): + self.containers = [] + + def push(self, o): + self.containers.append(o) + + def pop(self): + return self.containers.pop() + class Values: def __init__(self, *values): self.values = values - def validate(self, o): + def validate(self, o, ctx): if not o in self.values: return "%s not in %s" % (o, self.values) @@ -34,7 +45,7 @@ class Types: def __init__(self, *types): self.types = types - def validate(self, o): + def validate(self, o, ctx): for t in self.types: if isinstance(o, t): return @@ -49,20 +60,34 @@ class Map: self.map = map self.restricted = restricted - def validate(self, o): + def validate(self, o, ctx): errors = [] if not hasattr(o, "get"): return "%s is not a map" % o + ctx.push(o) for k, t in self.map.items(): v = o.get(k) if v is not None: - err = t.validate(v) + err = t.validate(v, ctx) if err: errors.append("%s: %s" % (k, err)) if self.restricted: for k in o: if not k in self.map: errors.append("%s: illegal key" % k) + ctx.pop() + if errors: return ", ".join(errors) + +class And: + + def __init__(self, *conditions): + self.conditions = conditions + + def validate(self, o, ctx): + for c in self.conditions: + err = c.validate(o, ctx) + if err: + return err |
