# Path: nudge/renderer.py
# class Json(object):
#     ''' Default Nudge HTTP Content Type. Encodes the entire endpoint
#         result as json, and returns.
# 
#         Note this renderer will not allow you to pass back a top level
#         list or tuple (javascript array) because it is insecure, and could
#         allow a CSRF attack. See here:
#         http://flask.pocoo.org/docs/security/#json-security
#     '''
#     def __call__(self, result):
#         if result == None:
#             raise HTTPException(404)
#         if isinstance(result, (types.ListType, types.TupleType)):
#             raise SecurityException(
#                 'Results that encode as json arrays are not '+\
#                 'allowed for security concerns'
#             )
#         return Result(
#             content=json_encode(result),
#             content_type='application/json; charset=UTF-8',
#             http_status=200,
#         )
# 
# class RequestAwareRenderer(object):
# 
#     def __call__(self, req, result):
#         pass
# 
# Path: nudge/json.py
# class Dictomatic(dict):
# 
#     @classmethod
#     def wrap(cls, data, decode=True, start=True):
#         return wrap(data, cls, decode, start)
# 
#     def __getattr__(self, name, default=None):
#         '''
#         Makes a dictionary behave like an object with magic dehumping action.
#         '''
# 
#         # try it normally
#         try:
#             return self[name]
#         except KeyError:
#             if name.startswith('__'):
#                 raise AttributeError()
#             # try it humped, so camel_case_is_awesome => camelCaseIsAwesome
#             try:
#                 return self[skyline_case.sub(hump, name)]
#             # it's really not here, let them know
#             except KeyError:
#                 try:
#                     return self[camel_case.sub(dehump, name)]
#                 # it's really not here, let them know
#                 except KeyError:
#                     return default
# 
#     def __setattr__(self, name, value):
#         self[name] = value
# 
# Path: nudge/error.py
# DEFAULT_ERROR_CODE = 500
# DEFAULT_ERROR_CONTENT_TYPE = "application/json; charset=UTF-8"
# DEFAULT_ERROR_CONTENT = '{"message": "%s", "code": %i}' % (
#     "Internal Server Error",
#     DEFAULT_ERROR_CODE,
# )
# class JsonErrorHandler(object):
# class HTTPError(Exception):
# class SecurityException(Exception):
#     def __call__(self, exp, req=None, log_assert=True):
# def handle_exception(exp, exp_handlers, default_handler=None):
#     def __init__(self, status_code, message=None):


import cgi
import logging
import re
import sys
import time
import types
import urllib
import warnings
    import cStringIO as StringIO
    import StringIO
import nudge.json
import nudge.log
        import paste.httpserver
        import eventlet.wsgi
from functools import partial
from nudge.renderer import Json, RequestAwareRenderer
from nudge.json import Dictomatic
from nudge.error import handle_exception, HTTPException, JsonErrorHandler,\
    DEFAULT_ERROR_CODE, DEFAULT_ERROR_CONTENT_TYPE, DEFAULT_ERROR_CONTENT, responses
    from optparse import OptionParser
        from google.appengine.ext.webapp.util import run_wsgi_app
        final_headers.append(('Content-Type', content_type))
        if headers:
            for k, v in headers.items():
                assert isinstance(k, str), \
                    "Headers keys and values must be a byte string"
                final_headers.append((k,v))

    except (Exception), e:
        _log.exception(e)
        final_headers = [('Content-Type', DEFAULT_ERROR_CONTENT_TYPE)]
        content = DEFAULT_ERROR_CONTENT
        code = DEFAULT_ERROR_CODE

    start_response(
        str(code) + ' ' + responses[code],
        final_headers
    )
    return content

def _gen_trace_str(f, args, kwargs, res):
    argsstr = ''.join(map(lambda v: "%s, " % v, args))
    kwargsstr = str(kwargs)[1:-1] # remove leading '{' and trailing '}'
    if isinstance(res, unicode):
        return u"%s(%s%s): %s" % (f.__name__, argsstr, kwargsstr, res)
    else:
        return "%s(%s%s): %s" % (f.__name__, argsstr, kwargsstr, res)

def _generate_headers(version, status_code, content_length, headers={}):
    """generates status line + headers"""
    lines = [version + " " + str(status_code) + " " +

# Path: nudge/renderer.py
# class Json(object):
#     ''' Default Nudge HTTP Content Type. Encodes the entire endpoint
#         result as json, and returns.
# 
#         Note this renderer will not allow you to pass back a top level
#         list or tuple (javascript array) because it is insecure, and could
#         allow a CSRF attack. See here:
#         http://flask.pocoo.org/docs/security/#json-security
#     '''
#     def __call__(self, result):
#         if result == None:
#             raise HTTPException(404)
#         if isinstance(result, (types.ListType, types.TupleType)):
#             raise SecurityException(
#                 'Results that encode as json arrays are not '+\
#                 'allowed for security concerns'
#             )
#         return Result(
#             content=json_encode(result),
#             content_type='application/json; charset=UTF-8',
#             http_status=200,
#         )
# 
# class RequestAwareRenderer(object):
# 
#     def __call__(self, req, result):
#         pass
# 
# Path: nudge/json.py
# class Dictomatic(dict):
# 
#     @classmethod
#     def wrap(cls, data, decode=True, start=True):
#         return wrap(data, cls, decode, start)
# 
#     def __getattr__(self, name, default=None):
#         '''
#         Makes a dictionary behave like an object with magic dehumping action.
#         '''
# 
#         # try it normally
#         try:
#             return self[name]
#         except KeyError:
#             if name.startswith('__'):
#                 raise AttributeError()
#             # try it humped, so camel_case_is_awesome => camelCaseIsAwesome
#             try:
#                 return self[skyline_case.sub(hump, name)]
#             # it's really not here, let them know
#             except KeyError:
#                 try:
#                     return self[camel_case.sub(dehump, name)]
#                 # it's really not here, let them know
#                 except KeyError:
#                     return default
# 
#     def __setattr__(self, name, value):
#         self[name] = value
# 
# Path: nudge/error.py
# DEFAULT_ERROR_CODE = 500
# DEFAULT_ERROR_CONTENT_TYPE = "application/json; charset=UTF-8"
# DEFAULT_ERROR_CONTENT = '{"message": "%s", "code": %i}' % (
#     "Internal Server Error",
#     DEFAULT_ERROR_CODE,
# )
# class JsonErrorHandler(object):
# class HTTPError(Exception):
# class SecurityException(Exception):
#     def __call__(self, exp, req=None, log_assert=True):
# def handle_exception(exp, exp_handlers, default_handler=None):
#     def __init__(self, status_code, message=None):


# Path: nudge/publisher.py
import cgi
import logging
import re
import sys
import time
import types
import urllib
import warnings
    import cStringIO as StringIO
    import StringIO
import nudge.json
import nudge.log
        import paste.httpserver
        import eventlet.wsgi
from functools import partial
from nudge.renderer import Json, RequestAwareRenderer
from nudge.json import Dictomatic
from nudge.error import handle_exception, HTTPException, JsonErrorHandler,\
    DEFAULT_ERROR_CODE, DEFAULT_ERROR_CONTENT_TYPE, DEFAULT_ERROR_CONTENT, responses
    from optparse import OptionParser
        from google.appengine.ext.webapp.util import run_wsgi_app

        final_headers.append(('Content-Type', content_type))
        if headers:
            for k, v in headers.items():
                assert isinstance(k, str), \
                    "Headers keys and values must be a byte string"
                final_headers.append((k,v))

    except (Exception), e:
        _log.exception(e)
        final_headers = [('Content-Type', DEFAULT_ERROR_CONTENT_TYPE)]
        content = DEFAULT_ERROR_CONTENT
        code = DEFAULT_ERROR_CODE

    start_response(
        str(code) + ' ' + responses[code],
        final_headers
    )
    return content

def _gen_trace_str(f, args, kwargs, res):
    argsstr = ''.join(map(lambda v: "%s, " % v, args))
    kwargsstr = str(kwargs)[1:-1] # remove leading '{' and trailing '}'
    if isinstance(res, unicode):
        return u"%s(%s%s): %s" % (f.__name__, argsstr, kwargsstr, res)
    else:
        return "%s(%s%s): %s" % (f.__name__, argsstr, kwargsstr, res)

def _generate_headers(version, status_code, content_length, headers={}):
    """generates status line + headers"""
    lines = [version + " " + str(status_code) + " " +

                responses[status_code]]