diff options
author | Alex Merry <dev@randomguy3.me.uk> | 2011-08-14 12:38:18 +0100 |
---|---|---|
committer | Alex Merry <dev@randomguy3.me.uk> | 2011-08-14 12:38:18 +0100 |
commit | 5fc31cba870c1a0d8924638089b71a42278a1c6a (patch) | |
tree | 4c63c02812266f0c77ac3c6f84ba65b4efaad01d /tools | |
parent | 8badc1d8fcaa46937585be6284b051444465d2ec (diff) |
Import tooling fixes from telepathy-spec
Diffstat (limited to 'tools')
-rw-r--r-- | tools/specparser.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tools/specparser.py b/tools/specparser.py index 697d4af..d680896 100644 --- a/tools/specparser.py +++ b/tools/specparser.py @@ -305,6 +305,37 @@ class Base(object): n.namespaceURI = None n.setAttribute('href', t.get_url()) + # rewrite <tp:value-ref> + for n in node.getElementsByTagNameNS(XMLNS_TP, 'value-ref'): + if n.hasAttribute('type'): + type_name = n.getAttribute('type') + value_name = getText(n) + t = spec.lookup_type(type_name) + assert isinstance(t, EnumLike), ("%s is not an enum or flags type" + % type_name) + else: + type_name = getText(n) + value_name_parts = [] + while type_name not in spec.types: + type_name, _, rest = type_name.rpartition('_') + value_name_parts.insert(0, rest) + if not type_name: + raise ValueError("No substrings of '%s' describe " + "a valid type." % getText(n)) + value_name = '_'.join(value_name_parts) + t = spec.lookup_type(type_name) + assert isinstance(t, EnumLike), ("%s is not an enum or flags type" + % type_name) + + n.tagName = 'a' + n.namespaceURI = None + n.setAttribute('href', t.get_url()) + short_names = [val.short_name for val in t.values] + if value_name not in short_names: + raise ValueError("'%s' is not a valid value of '%s'. " + "Valid values are %s" % + (value_name, type_name, short_names)) + # rewrite <tp:error-ref> error_ns = spec.spec_namespace + '.Error.' for n in node.getElementsByTagNameNS(XMLNS_TP, 'error-ref'): |