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