# Path: turbulenz_local/lib/exceptions.py
# class PostOnlyException(BaseException):
#     def __init__(self, value):
#         super(PostOnlyException, self).__init__()
#         self.value = value
# 
#     def __str__(self):
#         return self.value
# 
# class GetOnlyException(BaseException):
#     def __init__(self, value):
#         super(GetOnlyException, self).__init__()
#         self.value = value
# 
#     def __str__(self):
#         return self.value


from warnings import warn
from decorator import decorator
from simplejson import JSONEncoder, JSONDecoder
from pylons import request, response
from urlparse import urlparse
from turbulenz_local.lib.exceptions import PostOnlyException, GetOnlyException
def jsonify(func, *args, **kwargs):
    return _jsonify(func(*args, **kwargs))

def _jsonify(data):
    # Sometimes we get back a string and we don't want to double-encode
    # Checking for basestring instance catches both unicode and str.
    if not isinstance(data, basestring):

        if isinstance(data, (list, tuple)):
            msg = "JSON responses with Array envelopes are susceptible to " \
                  "cross-site data leak attacks, see " \
                  "http://pylonshq.com/warnings/JSONArray"
            warn(msg, Warning, 2)

        data = _json_encoder.encode(data)

    if 'callback' in request.params:
        response.headers['Content-Type'] = 'text/javascript; charset=utf-8'
        cbname = str(request.params['callback'])
        data = '%s(%s);' % (cbname, data)
    else:
        response.headers['Content-Type'] = 'application/json; charset=utf-8'

    return data

@decorator
def secure_get(func, *args, **kwargs):
    try:
        _getonly()
        return _secure(request.GET, func, *args, **kwargs)

# Path: turbulenz_local/lib/exceptions.py
# class PostOnlyException(BaseException):
#     def __init__(self, value):
#         super(PostOnlyException, self).__init__()
#         self.value = value
# 
#     def __str__(self):
#         return self.value
# 
# class GetOnlyException(BaseException):
#     def __init__(self, value):
#         super(GetOnlyException, self).__init__()
#         self.value = value
# 
#     def __str__(self):
#         return self.value


# Path: turbulenz_local/decorators.py
from warnings import warn
from decorator import decorator
from simplejson import JSONEncoder, JSONDecoder
from pylons import request, response
from urlparse import urlparse
from turbulenz_local.lib.exceptions import PostOnlyException, GetOnlyException

def jsonify(func, *args, **kwargs):
    return _jsonify(func(*args, **kwargs))

def _jsonify(data):
    # Sometimes we get back a string and we don't want to double-encode
    # Checking for basestring instance catches both unicode and str.
    if not isinstance(data, basestring):

        if isinstance(data, (list, tuple)):
            msg = "JSON responses with Array envelopes are susceptible to " \
                  "cross-site data leak attacks, see " \
                  "http://pylonshq.com/warnings/JSONArray"
            warn(msg, Warning, 2)

        data = _json_encoder.encode(data)

    if 'callback' in request.params:
        response.headers['Content-Type'] = 'text/javascript; charset=utf-8'
        cbname = str(request.params['callback'])
        data = '%s(%s);' % (cbname, data)
    else:
        response.headers['Content-Type'] = 'application/json; charset=utf-8'

    return data

@decorator
def secure_get(func, *args, **kwargs):
    try:
        _getonly()
        return _secure(request.GET, func, *args, **kwargs)

    except GetOnlyException as e: