-class entryElement(simpleElement):
- """<entry>text</entry>"""
- def __init__(self, text = None):
- simpleElement.__init__(self, 'entry', text)
-
-class rowElement(Element):
- """
- <row>
- <entry>entries[0]</entry>
- <entry>entries[1]</entry>
- ...
- </row>
- """
-
- def __init__(self, entries = None):
- Element.__init__(self, 'row')
- if entries:
- for entry in entries:
- if isinstance(entry, entryElement):
- self.appendChild(entry)
- else:
- self.appendChild(entryElement(entry))
-
-class informaltableElement(Element):
- """
- <informaltable>
- <tgroup>
- <thead>
- <row>
- <entry>label1</entry>
- <entry>label2</entry>
- ...
- </row>
- </thead>
- <tbody>
- <row>
- <entry>row1value1</entry>
- <entry>row1value2</entry>
- ...
- </row>
- ...
- </tbody>
- </tgroup>
- </informaltable>
- """
-
- def __init__(self, head = None, rows = None):
- Element.__init__(self, 'informaltable')
- tgroup = Element('tgroup')
- self.appendChild(tgroup)
- if head:
- thead = Element('thead')
- tgroup.appendChild(thead)
- if isinstance(head, rowElement):
- thead.appendChild(head)
- else:
- thead.appendChild(rowElement(head))
- if rows:
- tbody = Element('tbody')
- tgroup.appendChild(tbody)
- for row in rows:
- if isinstance(row, rowElement):
- tbody.appendChild(row)
- else:
- tobdy.appendChild(rowElement(row))
- cols = len(thead.childNodes[0].childNodes)
- tgroup.setAttribute('cols', str(cols))
-
-def parameters(param, name, optional, doc, indent, step):
- """Format a parameter into parameter row(s)."""
-
- rows = []
-
- row = rowElement()
- rows.append(row)
-
- # Parameter name
- entry = entryElement()
- entry.appendChild(simpleElement('literallayout', indent + name))
- row.appendChild(entry)
-
- # Parameter type
- param_type = python_type(param)
- row.appendChild(entryElement(xmlrpc_type(param_type)))
-
- # Whether parameter is optional
- if optional is not None:
- row.appendChild(entryElement(str(bool(optional))))
+def param_type(param):
+ """Return the XML-RPC type of a parameter."""
+ if isinstance(param, Mixed) and len(param):
+ subtypes = [param_type(subparam) for subparam in param]
+ return " or ".join(subtypes)
+ elif isinstance(param, (list, tuple, set)) and len(param):
+ return "array of " + " or ".join([param_type(subparam) for subparam in param])