[Telepathy-commits] [telepathy-spec/master] parse() now returns a Spec() object rather than the interfaces dict
Davyd Madeley
davyd at madeley.id.au
Mon Mar 23 12:29:19 PDT 2009
---
tools/doc-generator.py | 7 +++----
tools/specparser.py | 48 ++++++++++++++++++++++++++----------------------
2 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/tools/doc-generator.py b/tools/doc-generator.py
index 27b13a0..4a28ae5 100755
--- a/tools/doc-generator.py
+++ b/tools/doc-generator.py
@@ -30,11 +30,11 @@ def load_template (filename):
return template_def
# write out HTML files for each of the interfaces
-interfaces = specparser.parse (sys.argv[1])
+spec = specparser.parse (sys.argv[1])
namespace = {}
template_def = load_template ('interface.html')
t = Template (template_def, namespaces = [namespace])
-for interface in interfaces.values ():
+for interface in spec.interfaces.values ():
namespace['interface'] = interface
# open the output file
@@ -44,8 +44,7 @@ for interface in interfaces.values ():
# write out a TOC
template_def = load_template ('index.html')
-namespace = { 'interfaces': interfaces }
-t = Template (template_def, namespaces = [namespace])
+t = Template (template_def, namespaces = [spec])
# open the output file
out = open (os.path.join (output_path, 'index.html'), 'w')
diff --git a/tools/specparser.py b/tools/specparser.py
index d6c70e3..926c9cd 100644
--- a/tools/specparser.py
+++ b/tools/specparser.py
@@ -9,10 +9,6 @@ import xincludator
XMLNS_TP = 'http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0'
-# dictionaries for global errors and types
-errors = {}
-types = {}
-
def getText (dom):
if dom.childNodes[0].nodeType == dom.TEXT_NODE:
return dom.childNodes[0].data
@@ -47,6 +43,9 @@ class base (object):
except IndexError:
self.docstring = None
+ def get_spec (self):
+ return self.parent.get_spec ()
+
def get_interface (self):
return self.parent.get_interface ()
@@ -122,7 +121,7 @@ class Property (base):
super (Property, self).__init__ (parent, namespace, dom)
type_ = dom.getAttributeNS (XMLNS_TP, 'type')
- self.type = lookup_type (type_)
+ self.type = self.get_spec ().lookup_type (type_)
self.dbus_type = dom.getAttribute ('type')
@@ -148,7 +147,7 @@ class Arg (base):
super (Arg, self).__init__ (parent, namespace, dom)
type_ = dom.getAttributeNS (XMLNS_TP, 'type')
- self.type = lookup_type (type_)
+ self.type = self.get_spec ().lookup_type (type_)
self.dbus_type = dom.getAttribute ('type')
@@ -233,18 +232,21 @@ class Enum (DBusType): pass
class Flags (DBusType): pass
-def lookup_type (type_):
- if type_.endswith ('[]'):
- # FIXME: should this be wrapped in some sort of Array() class?
- return lookup_type (type_[:-2])
-
- if type_ == '': return None
- elif type_ in types:
- return types[type_]
-
- class UnknownType (Exception): pass
+class Spec (object):
+ def get_spec (self):
+ return self
- raise UnknownType ("Type `%s' is unknown" % type_)
+ def lookup_type (self, type_):
+ if type_.endswith ('[]'):
+ # FIXME: should this be wrapped in some sort of Array() class?
+ return self.lookup_type (type_[:-2])
+
+ if type_ == '': return None
+ elif type_ in self.types:
+ return self.types[type_]
+
+ class UnknownType (Exception): pass
+ raise UnknownType ("Type `%s' is unknown" % type_)
def build_dict (parent, type_, namespace, nodes):
"""Build a dictionary of D-Bus names to Python objects representing that
@@ -286,20 +288,22 @@ def parse (filename):
dom = xml.dom.minidom.parse (filename)
xincludator.xincludate (dom, filename)
+ spec = Spec ()
+
# build a dictionary of errors in this spec
errorsnode = dom.getElementsByTagNameNS (XMLNS_TP, 'errors')[0]
- errors.update (build_dict (None, Error,
+ spec.errors = build_dict (spec, Error,
errorsnode.getAttribute ('namespace'),
- errorsnode.getElementsByTagNameNS (XMLNS_TP, 'error')))
+ errorsnode.getElementsByTagNameNS (XMLNS_TP, 'error'))
# build a dictionary of ALL types in this spec
# FIXME: if we're doing all type parsing here, work out how to associate
# types with an Interface
- parse_types (None, dom, types)
+ spec.types = parse_types (spec, dom)
# build a dictionary of interfaces in this spec
- interfaces = build_dict (None, Interface, None,
+ spec.interfaces = build_dict (spec, Interface, None,
dom.getElementsByTagName ('interface'))
- return interfaces
+ return spec
if __name__ == '__main__':
parse (sys.argv[1])
--
1.5.6.5
More information about the telepathy-commits
mailing list