def _trim(docstring):
    """Return a trimmed docstring.

    Code taken from 'PEP 257 -- Docstring Conventions' article.
    """
    if not docstring:
        return ''
    lines = docstring.expandtabs().splitlines()
    for line in lines[1:]:
        stripped = line.lstrip()
        if stripped:
            indent = len(line) - len(stripped)
    trimmed = [lines[0].strip()]
    for line in lines[1:]:
        trimmed.append(line[indent:].rstrip())
    while trimmed and not trimmed[-1]:
        trimmed.pop()
    while trimmed and not trimmed[0]:
        trimmed.pop(0)
    return '\n'.join(trimmed)
