'Produce text documentation for a function or method object.'

def docroutine(self, object, name=None, mod=None, cl=None):

    realname = object.__name__
    name = (name or realname)
    note = ''
    skipdocs = 0
    if inspect.ismethod(object):
        imclass = object.im_class
        if cl:
            if (imclass is not cl):
                note = ('    from    ' + classname(imclass, mod))
        elif (object.im_self is not None):
            note = ('    method    of    %s    instance' % classname(object.im_self.__class__, mod))
        else:
            note = ('    unbound    %s    method' % classname(imclass, mod))
        object = object.im_func
    if (name == realname):
        title = self.bold(realname)
    else:
        if (cl and (realname in cl.__dict__) and (cl.__dict__[realname] is object)):
            skipdocs = 1
        title = ((self.bold(name) + '    =    ') + realname)
    if inspect.isfunction(object):
        (args, varargs, varkw, defaults) = inspect.getargspec(object)
        argspec = inspect.formatargspec(args, varargs, varkw, defaults, formatvalue=self.formatvalue)
        if (realname == '<lambda>'):
            title = (self.bold(name) + '    lambda    ')
            argspec = argspec[1:(-1)]
    else:
        argspec = '(...)'
    decl = ((title + argspec) + note)
    if skipdocs:
        return (decl + '\n')
    else:
        doc = (getdoc(object) or '')
        return ((decl + '\n') + (doc and (rstrip(self.indent(doc)) + '\n')))
