1#!/usr/bin/env python
2
3#
4# Generated Thu Jun 11 18:43:54 2009 by generateDS.py.
5#
6
7from __future__ import print_function
8from __future__ import unicode_literals
9
10import sys
11
12from xml.dom import minidom
13from xml.dom import Node
14
15import six
16
17#
18# User methods
19#
20# Calls to the methods in these classes are generated by generateDS.py.
21# You can replace these methods by re-implementing the following class
22#   in a module named generatedssuper.py.
23
24try:
25    from generatedssuper import GeneratedsSuper
26except ImportError as exp:
27
28    class GeneratedsSuper(object):
29        def format_string(self, input_data, input_name=''):
30            return input_data
31        def format_integer(self, input_data, input_name=''):
32            return '%d' % input_data
33        def format_float(self, input_data, input_name=''):
34            return '%f' % input_data
35        def format_double(self, input_data, input_name=''):
36            return '%e' % input_data
37        def format_boolean(self, input_data, input_name=''):
38            return '%s' % input_data
39
40
41#
42# If you have installed IPython you can uncomment and use the following.
43# IPython is available from http://ipython.scipy.org/.
44#
45
46## from IPython.Shell import IPShellEmbed
47## args = ''
48## ipshell = IPShellEmbed(args,
49##     banner = 'Dropping into IPython',
50##     exit_msg = 'Leaving Interpreter, back to program.')
51
52# Then use the following line where and when you want to drop into the
53# IPython shell:
54#    ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit')
55
56#
57# Globals
58#
59
60ExternalEncoding = 'ascii'
61
62#
63# Support/utility functions.
64#
65
66def showIndent(outfile, level):
67    for idx in range(level):
68        outfile.write('    ')
69
70def quote_xml(inStr):
71    s1 = (isinstance(inStr, six.string_types) and inStr or
72          '%s' % inStr)
73    s1 = s1.replace('&', '&amp;')
74    s1 = s1.replace('<', '&lt;')
75    s1 = s1.replace('>', '&gt;')
76    return s1
77
78def quote_attrib(inStr):
79    s1 = (isinstance(inStr, six.string_types) and inStr or
80          '%s' % inStr)
81    s1 = s1.replace('&', '&amp;')
82    s1 = s1.replace('<', '&lt;')
83    s1 = s1.replace('>', '&gt;')
84    if '"' in s1:
85        if "'" in s1:
86            s1 = '"%s"' % s1.replace('"', "&quot;")
87        else:
88            s1 = "'%s'" % s1
89    else:
90        s1 = '"%s"' % s1
91    return s1
92
93def quote_python(inStr):
94    s1 = inStr
95    if s1.find("'") == -1:
96        if s1.find('\n') == -1:
97            return "'%s'" % s1
98        else:
99            return "'''%s'''" % s1
100    else:
101        if s1.find('"') != -1:
102            s1 = s1.replace('"', '\\"')
103        if s1.find('\n') == -1:
104            return '"%s"' % s1
105        else:
106            return '"""%s"""' % s1
107
108
109class MixedContainer(object):
110    # Constants for category:
111    CategoryNone = 0
112    CategoryText = 1
113    CategorySimple = 2
114    CategoryComplex = 3
115    # Constants for content_type:
116    TypeNone = 0
117    TypeText = 1
118    TypeString = 2
119    TypeInteger = 3
120    TypeFloat = 4
121    TypeDecimal = 5
122    TypeDouble = 6
123    TypeBoolean = 7
124    def __init__(self, category, content_type, name, value):
125        self.category = category
126        self.content_type = content_type
127        self.name = name
128        self.value = value
129    def getCategory(self):
130        return self.category
131    def getContenttype(self, content_type):
132        return self.content_type
133    def getValue(self):
134        return self.value
135    def getName(self):
136        return self.name
137    def export(self, outfile, level, name, namespace):
138        if self.category == MixedContainer.CategoryText:
139            outfile.write(self.value)
140        elif self.category == MixedContainer.CategorySimple:
141            self.exportSimple(outfile, level, name)
142        else:    # category == MixedContainer.CategoryComplex
143            self.value.export(outfile, level, namespace,name)
144    def exportSimple(self, outfile, level, name):
145        if self.content_type == MixedContainer.TypeString:
146            outfile.write('<%s>%s</%s>' % (self.name, self.value, self.name))
147        elif self.content_type == MixedContainer.TypeInteger or \
148                self.content_type == MixedContainer.TypeBoolean:
149            outfile.write('<%s>%d</%s>' % (self.name, self.value, self.name))
150        elif self.content_type == MixedContainer.TypeFloat or \
151                self.content_type == MixedContainer.TypeDecimal:
152            outfile.write('<%s>%f</%s>' % (self.name, self.value, self.name))
153        elif self.content_type == MixedContainer.TypeDouble:
154            outfile.write('<%s>%g</%s>' % (self.name, self.value, self.name))
155    def exportLiteral(self, outfile, level, name):
156        if self.category == MixedContainer.CategoryText:
157            showIndent(outfile, level)
158            outfile.write('MixedContainer(%d, %d, "%s", "%s"),\n' % \
159                (self.category, self.content_type, self.name, self.value))
160        elif self.category == MixedContainer.CategorySimple:
161            showIndent(outfile, level)
162            outfile.write('MixedContainer(%d, %d, "%s", "%s"),\n' % \
163                (self.category, self.content_type, self.name, self.value))
164        else:    # category == MixedContainer.CategoryComplex
165            showIndent(outfile, level)
166            outfile.write('MixedContainer(%d, %d, "%s",\n' % \
167                (self.category, self.content_type, self.name,))
168            self.value.exportLiteral(outfile, level + 1)
169            showIndent(outfile, level)
170            outfile.write(')\n')
171
172
173class _MemberSpec(object):
174    def __init__(self, name='', data_type='', container=0):
175        self.name = name
176        self.data_type = data_type
177        self.container = container
178    def set_name(self, name): self.name = name
179    def get_name(self): return self.name
180    def set_data_type(self, data_type): self.data_type = data_type
181    def get_data_type(self): return self.data_type
182    def set_container(self, container): self.container = container
183    def get_container(self): return self.container
184
185
186#
187# Data representation classes.
188#
189
190class DoxygenType(GeneratedsSuper):
191    subclass = None
192    superclass = None
193    def __init__(self, version=None, compound=None):
194        self.version = version
195        if compound is None:
196            self.compound = []
197        else:
198            self.compound = compound
199    def factory(*args_, **kwargs_):
200        if DoxygenType.subclass:
201            return DoxygenType.subclass(*args_, **kwargs_)
202        else:
203            return DoxygenType(*args_, **kwargs_)
204    factory = staticmethod(factory)
205    def get_compound(self): return self.compound
206    def set_compound(self, compound): self.compound = compound
207    def add_compound(self, value): self.compound.append(value)
208    def insert_compound(self, index, value): self.compound[index] = value
209    def get_version(self): return self.version
210    def set_version(self, version): self.version = version
211    def export(self, outfile, level, namespace_='', name_='DoxygenType', namespacedef_=''):
212        showIndent(outfile, level)
213        outfile.write('<%s%s %s' % (namespace_, name_, namespacedef_, ))
214        self.exportAttributes(outfile, level, namespace_, name_='DoxygenType')
215        if self.hasContent_():
216            outfile.write('>\n')
217            self.exportChildren(outfile, level + 1, namespace_, name_)
218            showIndent(outfile, level)
219            outfile.write('</%s%s>\n' % (namespace_, name_))
220        else:
221            outfile.write(' />\n')
222    def exportAttributes(self, outfile, level, namespace_='', name_='DoxygenType'):
223        outfile.write(' version=%s' % (self.format_string(quote_attrib(self.version).encode(ExternalEncoding), input_name='version'), ))
224    def exportChildren(self, outfile, level, namespace_='', name_='DoxygenType'):
225        for compound_ in self.compound:
226            compound_.export(outfile, level, namespace_, name_='compound')
227    def hasContent_(self):
228        if (
229            self.compound is not None
230            ):
231            return True
232        else:
233            return False
234    def exportLiteral(self, outfile, level, name_='DoxygenType'):
235        level += 1
236        self.exportLiteralAttributes(outfile, level, name_)
237        if self.hasContent_():
238            self.exportLiteralChildren(outfile, level, name_)
239    def exportLiteralAttributes(self, outfile, level, name_):
240        if self.version is not None:
241            showIndent(outfile, level)
242            outfile.write('version = %s,\n' % (self.version,))
243    def exportLiteralChildren(self, outfile, level, name_):
244        showIndent(outfile, level)
245        outfile.write('compound=[\n')
246        level += 1
247        for compound in self.compound:
248            showIndent(outfile, level)
249            outfile.write('model_.compound(\n')
250            compound.exportLiteral(outfile, level, name_='compound')
251            showIndent(outfile, level)
252            outfile.write('),\n')
253        level -= 1
254        showIndent(outfile, level)
255        outfile.write('],\n')
256    def build(self, node_):
257        attrs = node_.attributes
258        self.buildAttributes(attrs)
259        for child_ in node_.childNodes:
260            nodeName_ = child_.nodeName.split(':')[-1]
261            self.buildChildren(child_, nodeName_)
262    def buildAttributes(self, attrs):
263        if attrs.get('version'):
264            self.version = attrs.get('version').value
265    def buildChildren(self, child_, nodeName_):
266        if child_.nodeType == Node.ELEMENT_NODE and \
267            nodeName_ == 'compound':
268            obj_ = CompoundType.factory()
269            obj_.build(child_)
270            self.compound.append(obj_)
271# end class DoxygenType
272
273
274class CompoundType(GeneratedsSuper):
275    subclass = None
276    superclass = None
277    def __init__(self, kind=None, refid=None, name=None, member=None):
278        self.kind = kind
279        self.refid = refid
280        self.name = name
281        if member is None:
282            self.member = []
283        else:
284            self.member = member
285    def factory(*args_, **kwargs_):
286        if CompoundType.subclass:
287            return CompoundType.subclass(*args_, **kwargs_)
288        else:
289            return CompoundType(*args_, **kwargs_)
290    factory = staticmethod(factory)
291    def get_name(self): return self.name
292    def set_name(self, name): self.name = name
293    def get_member(self): return self.member
294    def set_member(self, member): self.member = member
295    def add_member(self, value): self.member.append(value)
296    def insert_member(self, index, value): self.member[index] = value
297    def get_kind(self): return self.kind
298    def set_kind(self, kind): self.kind = kind
299    def get_refid(self): return self.refid
300    def set_refid(self, refid): self.refid = refid
301    def export(self, outfile, level, namespace_='', name_='CompoundType', namespacedef_=''):
302        showIndent(outfile, level)
303        outfile.write('<%s%s %s' % (namespace_, name_, namespacedef_, ))
304        self.exportAttributes(outfile, level, namespace_, name_='CompoundType')
305        if self.hasContent_():
306            outfile.write('>\n')
307            self.exportChildren(outfile, level + 1, namespace_, name_)
308            showIndent(outfile, level)
309            outfile.write('</%s%s>\n' % (namespace_, name_))
310        else:
311            outfile.write(' />\n')
312    def exportAttributes(self, outfile, level, namespace_='', name_='CompoundType'):
313        outfile.write(' kind=%s' % (quote_attrib(self.kind), ))
314        outfile.write(' refid=%s' % (self.format_string(quote_attrib(self.refid).encode(ExternalEncoding), input_name='refid'), ))
315    def exportChildren(self, outfile, level, namespace_='', name_='CompoundType'):
316        if self.name is not None:
317            showIndent(outfile, level)
318            outfile.write('<%sname>%s</%sname>\n' % (namespace_, self.format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_))
319        for member_ in self.member:
320            member_.export(outfile, level, namespace_, name_='member')
321    def hasContent_(self):
322        if (
323            self.name is not None or
324            self.member is not None
325            ):
326            return True
327        else:
328            return False
329    def exportLiteral(self, outfile, level, name_='CompoundType'):
330        level += 1
331        self.exportLiteralAttributes(outfile, level, name_)
332        if self.hasContent_():
333            self.exportLiteralChildren(outfile, level, name_)
334    def exportLiteralAttributes(self, outfile, level, name_):
335        if self.kind is not None:
336            showIndent(outfile, level)
337            outfile.write('kind = "%s",\n' % (self.kind,))
338        if self.refid is not None:
339            showIndent(outfile, level)
340            outfile.write('refid = %s,\n' % (self.refid,))
341    def exportLiteralChildren(self, outfile, level, name_):
342        showIndent(outfile, level)
343        outfile.write('name=%s,\n' % quote_python(self.name).encode(ExternalEncoding))
344        showIndent(outfile, level)
345        outfile.write('member=[\n')
346        level += 1
347        for member in self.member:
348            showIndent(outfile, level)
349            outfile.write('model_.member(\n')
350            member.exportLiteral(outfile, level, name_='member')
351            showIndent(outfile, level)
352            outfile.write('),\n')
353        level -= 1
354        showIndent(outfile, level)
355        outfile.write('],\n')
356    def build(self, node_):
357        attrs = node_.attributes
358        self.buildAttributes(attrs)
359        for child_ in node_.childNodes:
360            nodeName_ = child_.nodeName.split(':')[-1]
361            self.buildChildren(child_, nodeName_)
362    def buildAttributes(self, attrs):
363        if attrs.get('kind'):
364            self.kind = attrs.get('kind').value
365        if attrs.get('refid'):
366            self.refid = attrs.get('refid').value
367    def buildChildren(self, child_, nodeName_):
368        if child_.nodeType == Node.ELEMENT_NODE and \
369            nodeName_ == 'name':
370            name_ = ''
371            for text__content_ in child_.childNodes:
372                name_ += text__content_.nodeValue
373            self.name = name_
374        elif child_.nodeType == Node.ELEMENT_NODE and \
375            nodeName_ == 'member':
376            obj_ = MemberType.factory()
377            obj_.build(child_)
378            self.member.append(obj_)
379# end class CompoundType
380
381
382class MemberType(GeneratedsSuper):
383    subclass = None
384    superclass = None
385    def __init__(self, kind=None, refid=None, name=None):
386        self.kind = kind
387        self.refid = refid
388        self.name = name
389    def factory(*args_, **kwargs_):
390        if MemberType.subclass:
391            return MemberType.subclass(*args_, **kwargs_)
392        else:
393            return MemberType(*args_, **kwargs_)
394    factory = staticmethod(factory)
395    def get_name(self): return self.name
396    def set_name(self, name): self.name = name
397    def get_kind(self): return self.kind
398    def set_kind(self, kind): self.kind = kind
399    def get_refid(self): return self.refid
400    def set_refid(self, refid): self.refid = refid
401    def export(self, outfile, level, namespace_='', name_='MemberType', namespacedef_=''):
402        showIndent(outfile, level)
403        outfile.write('<%s%s %s' % (namespace_, name_, namespacedef_, ))
404        self.exportAttributes(outfile, level, namespace_, name_='MemberType')
405        if self.hasContent_():
406            outfile.write('>\n')
407            self.exportChildren(outfile, level + 1, namespace_, name_)
408            showIndent(outfile, level)
409            outfile.write('</%s%s>\n' % (namespace_, name_))
410        else:
411            outfile.write(' />\n')
412    def exportAttributes(self, outfile, level, namespace_='', name_='MemberType'):
413        outfile.write(' kind=%s' % (quote_attrib(self.kind), ))
414        outfile.write(' refid=%s' % (self.format_string(quote_attrib(self.refid).encode(ExternalEncoding), input_name='refid'), ))
415    def exportChildren(self, outfile, level, namespace_='', name_='MemberType'):
416        if self.name is not None:
417            showIndent(outfile, level)
418            outfile.write('<%sname>%s</%sname>\n' % (namespace_, self.format_string(quote_xml(self.name).encode(ExternalEncoding), input_name='name'), namespace_))
419    def hasContent_(self):
420        if (
421            self.name is not None
422            ):
423            return True
424        else:
425            return False
426    def exportLiteral(self, outfile, level, name_='MemberType'):
427        level += 1
428        self.exportLiteralAttributes(outfile, level, name_)
429        if self.hasContent_():
430            self.exportLiteralChildren(outfile, level, name_)
431    def exportLiteralAttributes(self, outfile, level, name_):
432        if self.kind is not None:
433            showIndent(outfile, level)
434            outfile.write('kind = "%s",\n' % (self.kind,))
435        if self.refid is not None:
436            showIndent(outfile, level)
437            outfile.write('refid = %s,\n' % (self.refid,))
438    def exportLiteralChildren(self, outfile, level, name_):
439        showIndent(outfile, level)
440        outfile.write('name=%s,\n' % quote_python(self.name).encode(ExternalEncoding))
441    def build(self, node_):
442        attrs = node_.attributes
443        self.buildAttributes(attrs)
444        for child_ in node_.childNodes:
445            nodeName_ = child_.nodeName.split(':')[-1]
446            self.buildChildren(child_, nodeName_)
447    def buildAttributes(self, attrs):
448        if attrs.get('kind'):
449            self.kind = attrs.get('kind').value
450        if attrs.get('refid'):
451            self.refid = attrs.get('refid').value
452    def buildChildren(self, child_, nodeName_):
453        if child_.nodeType == Node.ELEMENT_NODE and \
454            nodeName_ == 'name':
455            name_ = ''
456            for text__content_ in child_.childNodes:
457                name_ += text__content_.nodeValue
458            self.name = name_
459# end class MemberType
460
461
462USAGE_TEXT = """
463Usage: python <Parser>.py [ -s ] <in_xml_file>
464Options:
465    -s        Use the SAX parser, not the minidom parser.
466"""
467
468def usage():
469    print(USAGE_TEXT)
470    sys.exit(1)
471
472
473def parse(inFileName):
474    doc = minidom.parse(inFileName)
475    rootNode = doc.documentElement
476    rootObj = DoxygenType.factory()
477    rootObj.build(rootNode)
478    # Enable Python to collect the space used by the DOM.
479    doc = None
480    sys.stdout.write('<?xml version="1.0" ?>\n')
481    rootObj.export(sys.stdout, 0, name_="doxygenindex",
482        namespacedef_='')
483    return rootObj
484
485
486def parseString(inString):
487    doc = minidom.parseString(inString)
488    rootNode = doc.documentElement
489    rootObj = DoxygenType.factory()
490    rootObj.build(rootNode)
491    # Enable Python to collect the space used by the DOM.
492    doc = None
493    sys.stdout.write('<?xml version="1.0" ?>\n')
494    rootObj.export(sys.stdout, 0, name_="doxygenindex",
495        namespacedef_='')
496    return rootObj
497
498
499def parseLiteral(inFileName):
500    doc = minidom.parse(inFileName)
501    rootNode = doc.documentElement
502    rootObj = DoxygenType.factory()
503    rootObj.build(rootNode)
504    # Enable Python to collect the space used by the DOM.
505    doc = None
506    sys.stdout.write('from index import *\n\n')
507    sys.stdout.write('rootObj = doxygenindex(\n')
508    rootObj.exportLiteral(sys.stdout, 0, name_="doxygenindex")
509    sys.stdout.write(')\n')
510    return rootObj
511
512
513def main():
514    args = sys.argv[1:]
515    if len(args) == 1:
516        parse(args[0])
517    else:
518        usage()
519
520
521
522
523if __name__ == '__main__':
524    main()
525    #import pdb
526    #pdb.run('main()')
527