# 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
# Copyright (c) 2011,2013 Turbulenz Limited





# pylint: disable=C0103
_json_encoder = JSONEncoder(encoding='utf-8', separators=(',',':'))
_json_decoder = JSONDecoder(encoding='utf-8')
# pylint: enable=C0103

@decorator
def postonly(func, *args, **kwargs):
    try:
        _postonly()
        return func(*args, **kwargs)
    except PostOnlyException as e:
        return e


def _postonly():
    if request.method != 'POST':
        headers = response.headers
        headers['Content-Type'] = 'application/json; charset=utf-8'
        headers['Cache-Control'] = 'no-store, no-cache, max-age=0'
        headers['Allow'] = 'POST'
        response.status_int = 405

# 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

# Copyright (c) 2011,2013 Turbulenz Limited





# pylint: disable=C0103
_json_encoder = JSONEncoder(encoding='utf-8', separators=(',',':'))
_json_decoder = JSONDecoder(encoding='utf-8')
# pylint: enable=C0103

@decorator
def postonly(func, *args, **kwargs):
    try:
        _postonly()
        return func(*args, **kwargs)
    except PostOnlyException as e:
        return e


def _postonly():
    if request.method != 'POST':
        headers = response.headers
        headers['Content-Type'] = 'application/json; charset=utf-8'
        headers['Cache-Control'] = 'no-store, no-cache, max-age=0'
        headers['Allow'] = 'POST'
        response.status_int = 405

        raise PostOnlyException('{"ok":false,"msg":"Post Only!"}')