# 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
except:


def run_pale_doc():
    parser = argparse.ArgumentParser()
    parser.add_argument('path_to_pale_module')
    parser.add_argument('-p', '--pretty',
            help="pretty-print the json output",
            action='store_true')
    parser.add_argument('-n', '--print_newlines',
            help="output json with actual newlines instead of \\n characters",
            action='store_true')
    args = parser.parse_args()
    module_path = initify_module_path(args.path_to_pale_module)
    try:
        pale_module = imp.load_source('loaded_pale_implemntation',
                module_path)
    except Exception as e:
        print e
        return
    json_docs = generate_json_docs(pale_module, args.pretty, user=None)
    if args.print_newlines:
        json_docs = json_docs.replace('\\n', '\n')
    print json_docs


def initify_module_path(path):
    init = '__init__.py'
    if path.endswith(init):
        return path

# 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

except:


def run_pale_doc():
    parser = argparse.ArgumentParser()
    parser.add_argument('path_to_pale_module')
    parser.add_argument('-p', '--pretty',
            help="pretty-print the json output",
            action='store_true')
    parser.add_argument('-n', '--print_newlines',
            help="output json with actual newlines instead of \\n characters",
            action='store_true')
    args = parser.parse_args()
    module_path = initify_module_path(args.path_to_pale_module)
    try:
        pale_module = imp.load_source('loaded_pale_implemntation',
                module_path)
    except Exception as e:
        print e
        return
    json_docs = generate_json_docs(pale_module, args.pretty, user=None)
    if args.print_newlines:
        json_docs = json_docs.replace('\\n', '\n')
    print json_docs


def initify_module_path(path):
    init = '__init__.py'
    if path.endswith(init):
        return path

    if not path.endswith('/'):