def docformat(docstring, docdict=None):
if not docstring:<EOL><INDENT>return docstring<EOL><DEDENT>if docdict is None:<EOL><INDENT>docdict = {}<EOL><DEDENT>if not docdict:<EOL><INDENT>return docstring<EOL><DEDENT>lines = docstring.expandtabs().splitlines()<EOL>if len(lines) < <NUM_LIT:2>:<EOL><INDENT>icount = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>icount = indentcount_lines(lines[<NUM_LIT:1>:])<EOL><DEDENT>indent = '<STR_LIT:U+0020>' * icount<EOL>indented = {}<EOL>for name, dstr in docdict.items():<EOL><INDENT>lines = dstr.expandtabs().splitlines()<EOL>try:<EOL><INDENT>newlines = [lines[<NUM_LIT:0>]]<EOL>for line in lines[<NUM_LIT:1>:]:<EOL><INDENT>newlines.append(indent+line)<EOL><DEDENT>indented[name] = '<STR_LIT:\n>'.join(newlines)<EOL><DEDENT>except IndexError:<EOL><INDENT>indented[name] = dstr<EOL><DEDENT><DEDENT>return docstring % indented<EOL>
Fill a function docstring from variables in dictionary

    Adapt the indent of the inserted docs

    Parameters
    ----------
    docstring : string
        docstring from function, possibly with dict formatting strings
    docdict : dict
        dictionary with keys that match the dict formatting strings
        and values that are docstring fragments to be inserted.  The
        indentation of the inserted docstrings is set to match the
        minimum indentation of the ``docstring`` by adding this
        indentation to all lines of the inserted string, except the
        first

    Returns
    -------
    outstring : string
        string with requested ``docdict`` strings inserted

    Examples
    --------
    >>> docformat(' Test string with %(value)s', {'value':'inserted value'})
    ' Test string with inserted value'
    >>> docstring = 'First line\\n    Second line\\n    %(value)s'
    >>> inserted_string = "indented\\nstring"
    >>> docdict = {'value': inserted_string}
    >>> docformat(docstring, docdict)
    'First line\\n    Second line\\n    indented\\n    string'