def generate_docstr(element, indent='', wrap=None):
    """
    Generate a Python docstr for a given element in the AMQP
    XML spec file.  The element could be a class or method

    The 'wrap' parameter is an optional chunk of text that's
    added to the beginning and end of the resulting docstring.

    """
    result = []

    txt = element.text and element.text.rstrip()
    if txt:
        result.append(_reindent(txt, indent))
        result.append(indent)

    for d in element.findall('doc') + element.findall('rule'):
        docval = ''.join(d.textlist()).rstrip()
        if not docval:
            continue
        reformat = True
        if 'name' in d.attrib:
            result.append(indent + d.attrib['name'].upper() + ':')
            result.append(indent)
            extra_indent = '    '
            if d.attrib['name'] == 'grammar':
                reformat = False # Don't want re-indenting to mess this up
        elif d.tag == 'rule':
            result.append(indent + 'RULE:')
            result.append(indent)
            extra_indent = '    '
        else:
            extra_indent = ''
        result.append(_reindent(docval, indent + extra_indent, reformat))
        result.append(indent)

    fields = element.findall('field')
    if fields:
        result.append(indent + 'PARAMETERS:')
        for f in fields:
            result.append(indent + '    ' + _fixup_field_name(f) + ': ' + _field_type(f))
            field_docs = generate_docstr(f, indent + '        ')
            if field_docs:
                result.append(indent)
                result.append(field_docs)
            result.append(indent)

    if not result:
        return None

    if wrap is not None:
        result = [wrap] + result + [wrap]

    return '\n'.join(x.rstrip() for x in result) + '\n'
def generate_docstr ( element , indent = '' , wrap = None ) : result = [ ] txt = element . text and element . text . rstrip ( ) if txt : result . append ( _reindent ( txt , indent ) ) result . append ( indent ) for d in element . findall ( 'doc' ) + element . findall ( 'rule' ) : docval = '' . join ( d . textlist ( ) ) . rstrip ( ) if not docval : continue reformat = True if 'name' in d . attrib : result . append ( indent + d . attrib [ 'name' ] . upper ( ) + ':' ) result . append ( indent ) extra_indent = '    ' if d . attrib [ 'name' ] == 'grammar' : reformat = False elif d . tag == 'rule' : result . append ( indent + 'RULE:' ) result . append ( indent ) extra_indent = '    ' else : extra_indent = '' result . append ( _reindent ( docval , indent + extra_indent , reformat ) ) result . append ( indent ) fields = element . findall ( 'field' ) if fields : result . append ( indent + 'PARAMETERS:' ) for f in fields : result . append ( indent + '    ' + _fixup_field_name ( f ) + ': ' + _field_type ( f ) ) field_docs = generate_docstr ( f , indent + '        ' ) if field_docs : result . append ( indent ) result . append ( field_docs ) result . append ( indent ) if not result : return None if wrap is not None : result = [ wrap ] + result + [ wrap ] return '\n' . join ( x . rstrip ( ) for x in result ) + '\n'
Generate a Python docstr for a given element in the AMQP
    XML spec file.  The element could be a class or method

    The 'wrap' parameter is an optional chunk of text that's
    added to the beginning and end of the resulting docstring.