[Telepathy-commits] [telepathy-spec/master] Add some checks for things that shouldn't be allowed to happen
Davyd Madeley
davyd at madeley.id.au
Mon Mar 23 12:29:30 PDT 2009
---
tools/specparser.py | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/tools/specparser.py b/tools/specparser.py
index ca255fa..cdd5ce5 100644
--- a/tools/specparser.py
+++ b/tools/specparser.py
@@ -32,6 +32,8 @@ XMLNS_TP = 'http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0'
class UnknownAccess(Exception): pass
class UnknownDirection(Exception): pass
class UnknownType(Exception): pass
+class UnnamedItem(Exception): pass
+class UntypedItem(Exception): pass
def getText(dom):
try:
@@ -85,6 +87,12 @@ class Base(object):
self.changed = getChildrenByName(dom, XMLNS_TP, 'changed')
+ self.validate()
+
+ def validate(self):
+ if self.short_name == '':
+ raise UnnamedItem("Node referred to by '%s' has no name" % dom.toxml())
+
def get_type_name(self):
return self.__class__.__name__
@@ -266,6 +274,9 @@ class Typed(Base):
self.type = dom.getAttributeNS(XMLNS_TP, 'type')
self.dbus_type = dom.getAttribute('type')
+ if self.dbus_type == '':
+ raise UntypedItem("Node referred to by '%s' has no type" % dom.toxml())
+
def get_type(self):
return self.get_spec().lookup_type(self.type)
@@ -477,6 +488,12 @@ class EnumLike(DBusType):
self.name = build_name(namespace, self.short_name)
self.value = dom.getAttribute('value')
+
+ super(EnumLike.EnumValue, self).validate()
+
+ def validate(self):
+ pass
+
def get_root_namespace(self):
return self.parent.get_root_namespace()
--
1.5.6.5
More information about the telepathy-commits
mailing list