# Path: pale/utils.py
# def py_doc_trim(docstring):
#     """Trim a python doc string.
# 
#     This example is nipped from https://www.python.org/dev/peps/pep-0257/,
#     which describes how to conventionally format and trim docstrings.
# 
#     It has been modified to replace single newlines with a space, but leave
#     multiple consecutive newlines in tact.
#     """
#     if not docstring:
#         return ''
#     # Convert tabs to spaces (following the normal Python rules)
#     # and split into a list of lines:
#     lines = docstring.expandtabs().splitlines()
#     # Determine minimum indentation (first line doesn't count):
#     indent = sys.maxint
#     for line in lines[1:]:
#         stripped = line.lstrip()
#         if stripped:
#             indent = min(indent, len(line) - len(stripped))
#     # Remove indentation (first line is special):
#     trimmed = [lines[0].strip()]
#     if indent < sys.maxint:
#         for line in lines[1:]:
#             trimmed.append(line[indent:].rstrip())
#     # Strip off trailing and leading blank lines:
#     while trimmed and not trimmed[-1]:
#         trimmed.pop()
#     while trimmed and not trimmed[0]:
#         trimmed.pop(0)
#     # The single string returned by the original function
#     joined = '\n'.join(trimmed)
#     # Return a version that replaces single newlines with spaces
#     return newline_substitution_regex.sub(" ", joined)


import argparse
import imp
import json
import re
import inspect
from collections import OrderedDict
    from cStringIO import StringIO
    from StringIO import StringIO
from pale.utils import py_doc_trim
    from pale import extract_endpoints, extract_resources, is_pale_module
    from pale import extract_endpoints, extract_resources, is_pale_module
    from pale import extract_endpoints, extract_resources, is_pale_module
        'arguments': extract_endpoint_arguments(endpoint),
        'returns': format_endpoint_returns_doc(endpoint),
    }
    if hasattr(endpoint, "_success"):
        docs["success"] = endpoint._success
    if hasattr(endpoint, "_requires_permission"):
        docs["requires_permission"] = endpoint._requires_permission
    return docs


def extract_endpoint_arguments(endpoint):
    """Extract the argument documentation from the endpoint."""

    ep_args = endpoint._arguments
    if ep_args is None:
        return None

    arg_docs = { k: format_endpoint_argument_doc(a) \
            for k, a in ep_args.iteritems() }
    return arg_docs


def format_endpoint_argument_doc(argument):
    """Return documentation about the argument that an endpoint accepts."""
    doc = argument.doc_dict()

    # Trim the strings a bit
    doc['description'] = clean_description(py_doc_trim(doc['description']))
    details = doc.get('detailed_description', None)
    if details is not None:

# Path: pale/utils.py
# def py_doc_trim(docstring):
#     """Trim a python doc string.
# 
#     This example is nipped from https://www.python.org/dev/peps/pep-0257/,
#     which describes how to conventionally format and trim docstrings.
# 
#     It has been modified to replace single newlines with a space, but leave
#     multiple consecutive newlines in tact.
#     """
#     if not docstring:
#         return ''
#     # Convert tabs to spaces (following the normal Python rules)
#     # and split into a list of lines:
#     lines = docstring.expandtabs().splitlines()
#     # Determine minimum indentation (first line doesn't count):
#     indent = sys.maxint
#     for line in lines[1:]:
#         stripped = line.lstrip()
#         if stripped:
#             indent = min(indent, len(line) - len(stripped))
#     # Remove indentation (first line is special):
#     trimmed = [lines[0].strip()]
#     if indent < sys.maxint:
#         for line in lines[1:]:
#             trimmed.append(line[indent:].rstrip())
#     # Strip off trailing and leading blank lines:
#     while trimmed and not trimmed[-1]:
#         trimmed.pop()
#     while trimmed and not trimmed[0]:
#         trimmed.pop(0)
#     # The single string returned by the original function
#     joined = '\n'.join(trimmed)
#     # Return a version that replaces single newlines with spaces
#     return newline_substitution_regex.sub(" ", joined)


# Path: pale/doc.py
import argparse
import imp
import json
import re
import inspect
from collections import OrderedDict
    from cStringIO import StringIO
    from StringIO import StringIO
from pale.utils import py_doc_trim
    from pale import extract_endpoints, extract_resources, is_pale_module
    from pale import extract_endpoints, extract_resources, is_pale_module
    from pale import extract_endpoints, extract_resources, is_pale_module

        'arguments': extract_endpoint_arguments(endpoint),
        'returns': format_endpoint_returns_doc(endpoint),
    }
    if hasattr(endpoint, "_success"):
        docs["success"] = endpoint._success
    if hasattr(endpoint, "_requires_permission"):
        docs["requires_permission"] = endpoint._requires_permission
    return docs


def extract_endpoint_arguments(endpoint):
    """Extract the argument documentation from the endpoint."""

    ep_args = endpoint._arguments
    if ep_args is None:
        return None

    arg_docs = { k: format_endpoint_argument_doc(a) \
            for k, a in ep_args.iteritems() }
    return arg_docs


def format_endpoint_argument_doc(argument):
    """Return documentation about the argument that an endpoint accepts."""
    doc = argument.doc_dict()

    # Trim the strings a bit
    doc['description'] = clean_description(py_doc_trim(doc['description']))
    details = doc.get('detailed_description', None)
    if details is not None:

        doc['detailed_description'] = clean_description(py_doc_trim(details))