

def docformat(docstring, docdict=None):
    ' Fill a function docstring from variables in dictionary\n\n    Adapt the indent of the inserted docs\n\n    Parameters\n    ----------\n    docstring : string\n        docstring from function, possibly with dict formatting strings\n    docdict : dict, optional\n        dictionary with keys that match the dict formatting strings\n        and values that are docstring fragments to be inserted.  The\n        indentation of the inserted docstrings is set to match the\n        minimum indentation of the ``docstring`` by adding this\n        indentation to all lines of the inserted string, except the\n        first\n\n    Returns\n    -------\n    outstring : string\n        string with requested ``docdict`` strings inserted\n\n    Examples\n    --------\n    >>> docformat(\' Test string with %(value)s\', {\'value\':\'inserted value\'})\n    \' Test string with inserted value\'\n    >>> docstring = \'First line\\n    Second line\\n    %(value)s\'\n    >>> inserted_string = "indented\\nstring"\n    >>> docdict = {\'value\': inserted_string}\n    >>> docformat(docstring, docdict)\n    \'First line\\n    Second line\\n    indented\\n    string\'\n    '
    if (not docstring):
        return docstring
    if (docdict is None):
        docdict = {
            
        }
    if (not docdict):
        return docstring
    lines = docstring.expandtabs().splitlines()
    if (len(lines) < 2):
        icount = 0
    else:
        icount = indentcount_lines(lines[1:])
    indent = (' ' * icount)
    indented = {
        
    }
    for (name, dstr) in docdict.items():
        lines = dstr.expandtabs().splitlines()
        try:
            newlines = [lines[0]]
            for line in lines[1:]:
                newlines.append((indent + line))
            indented[name] = '\n'.join(newlines)
        except IndexError:
            indented[name] = dstr
    return (docstring % indented)

dataset/ETHPy150Open scipy/scipy/scipy/misc/doccer.py docformat/original