# Path: netl2api/lib/utils.py
# def gen_context_uid():
#     _thr_local.l2api_ctx_uid = str(uuid4())
#     return _thr_local.l2api_ctx_uid
# 
# Path: netl2api/lib/config.py
# def get_netl2server_cfg():
#     return get_cfg("netl2server", check_permission=None)
# 
# def setup_netl2server_logger(cfg):
#     return setup_logger(cfg, "netl2server")


from functools import wraps
from re import _pattern_type
from bottle import request, response, abort
from netl2api.lib.utils import gen_context_uid
from netl2api.lib.config import get_netl2server_cfg, setup_netl2server_logger
    from simplejson import dumps
    from json import dumps

try:
except ImportError:


__all__ = ["reply_json", "context", "validate_input"]


cfg    = get_netl2server_cfg()
logger = setup_netl2server_logger(cfg)


def reply_json(f):
    @wraps(f)
    def json_dumps(*args, **kwargs):
        r = f(*args, **kwargs)
        if r and type(r) in (dict, list, tuple, str, unicode):
            response.content_type = "application/json; charset=UTF-8"
            return dumps(r)
        return r
    return json_dumps


def context(f):
    @wraps(f)
    def inject_ctx(*args, **kwargs):
        truncate = lambda i: i if len(i) <= 40 else "%s..." % i[:40]
        context  = { "CTX-UUID":                 gen_context_uid(),
                     "HTTP.ENV.SERVER_PROTOCOL": request.environ.get("SERVER_PROTOCOL"),
                     "HTTP.ENV.REQUEST_METHOD":  request.environ.get("REQUEST_METHOD"),

# Path: netl2api/lib/utils.py
# def gen_context_uid():
#     _thr_local.l2api_ctx_uid = str(uuid4())
#     return _thr_local.l2api_ctx_uid
# 
# Path: netl2api/lib/config.py
# def get_netl2server_cfg():
#     return get_cfg("netl2server", check_permission=None)
# 
# def setup_netl2server_logger(cfg):
#     return setup_logger(cfg, "netl2server")


# Path: netl2api/server/http_utils.py
from functools import wraps
from re import _pattern_type
from bottle import request, response, abort
from netl2api.lib.utils import gen_context_uid
from netl2api.lib.config import get_netl2server_cfg, setup_netl2server_logger
    from simplejson import dumps
    from json import dumps


try:
except ImportError:


__all__ = ["reply_json", "context", "validate_input"]


cfg    = get_netl2server_cfg()
logger = setup_netl2server_logger(cfg)


def reply_json(f):
    @wraps(f)
    def json_dumps(*args, **kwargs):
        r = f(*args, **kwargs)
        if r and type(r) in (dict, list, tuple, str, unicode):
            response.content_type = "application/json; charset=UTF-8"
            return dumps(r)
        return r
    return json_dumps


def context(f):
    @wraps(f)
    def inject_ctx(*args, **kwargs):
        truncate = lambda i: i if len(i) <= 40 else "%s..." % i[:40]
        context  = { "CTX-UUID":                 gen_context_uid(),
                     "HTTP.ENV.SERVER_PROTOCOL": request.environ.get("SERVER_PROTOCOL"),
                     "HTTP.ENV.REQUEST_METHOD":  request.environ.get("REQUEST_METHOD"),

                     "HTTP.ENV.REMOTE_ADDR":     request.environ.get("REMOTE_ADDR"),