# Path: freezer_api/api/common/resource.py
# class BaseResource(object):
#     def json_body(req):
# 
# Path: freezer_api/common/exceptions.py
# class FreezerAPIException(falcon.HTTPError):
# class BadDataFormat(FreezerAPIException):
# class DocumentExists(FreezerAPIException):
# class StorageEngineError(FreezerAPIException):
# class DocumentNotFound(FreezerAPIException):
# class AccessForbidden(FreezerAPIException):
# class MethodNotImplemented(FreezerAPIException):
#     def __init__(self, message=''):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
# 
# Path: freezer_api/policy.py
# DEFAULT_POLICY_FILE = 'policy.yaml'
# ENFORCER = None
#         ENFORCER = policy.Enforcer(conf)
# def setup_policy(conf):
# def enforce(rule):
#     def decorator(func):
#         def handler(*args, **kwargs):


import time
import falcon
from freezer_api.api.common import resource
from freezer_api.common import exceptions as freezer_api_exc
from freezer_api import policy

    @policy.enforce('sessions:delete')
    def on_delete(self, req, resp, project_id, session_id):
        # DELETE /v2/{project_id}/sessions/{session_id}
        # Deletes the specified session
        user_id = req.get_header('X-User-ID')
        self.db.delete_session(project_id=project_id,
                               user_id=user_id, session_id=session_id)
        resp.body = {'session_id': session_id}
        resp.status = falcon.HTTP_204

    @policy.enforce('sessions:update')
    def on_patch(self, req, resp, project_id, session_id):
        # PATCH /v2/{project_id}/sessions/{session_id}
        # Updates the specified session
        user_id = req.get_header('X-User-ID') or ''
        doc = self.json_body(req)
        new_version = self.db.update_session(project_id=project_id,
                                             user_id=user_id,
                                             session_id=session_id,
                                             patch_doc=doc)
        resp.body = {'session_id': session_id, 'version': new_version}

    @policy.enforce('sessions:replace')
    def on_post(self, req, resp, project_id, session_id):
        # PUT /v2/{project_id}/sessions/{session_id}
        # Creates/Replaces the specified session
        user_id = req.get_header('X-User-ID') or ''
        doc = self.json_body(req)
        if not doc:

# Path: freezer_api/api/common/resource.py
# class BaseResource(object):
#     def json_body(req):
# 
# Path: freezer_api/common/exceptions.py
# class FreezerAPIException(falcon.HTTPError):
# class BadDataFormat(FreezerAPIException):
# class DocumentExists(FreezerAPIException):
# class StorageEngineError(FreezerAPIException):
# class DocumentNotFound(FreezerAPIException):
# class AccessForbidden(FreezerAPIException):
# class MethodNotImplemented(FreezerAPIException):
#     def __init__(self, message=''):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
# 
# Path: freezer_api/policy.py
# DEFAULT_POLICY_FILE = 'policy.yaml'
# ENFORCER = None
#         ENFORCER = policy.Enforcer(conf)
# def setup_policy(conf):
# def enforce(rule):
#     def decorator(func):
#         def handler(*args, **kwargs):


# Path: freezer_api/api/v2/sessions.py
import time
import falcon
from freezer_api.api.common import resource
from freezer_api.common import exceptions as freezer_api_exc
from freezer_api import policy


    @policy.enforce('sessions:delete')
    def on_delete(self, req, resp, project_id, session_id):
        # DELETE /v2/{project_id}/sessions/{session_id}
        # Deletes the specified session
        user_id = req.get_header('X-User-ID')
        self.db.delete_session(project_id=project_id,
                               user_id=user_id, session_id=session_id)
        resp.body = {'session_id': session_id}
        resp.status = falcon.HTTP_204

    @policy.enforce('sessions:update')
    def on_patch(self, req, resp, project_id, session_id):
        # PATCH /v2/{project_id}/sessions/{session_id}
        # Updates the specified session
        user_id = req.get_header('X-User-ID') or ''
        doc = self.json_body(req)
        new_version = self.db.update_session(project_id=project_id,
                                             user_id=user_id,
                                             session_id=session_id,
                                             patch_doc=doc)
        resp.body = {'session_id': session_id, 'version': new_version}

    @policy.enforce('sessions:replace')
    def on_post(self, req, resp, project_id, session_id):
        # PUT /v2/{project_id}/sessions/{session_id}
        # Creates/Replaces the specified session
        user_id = req.get_header('X-User-ID') or ''
        doc = self.json_body(req)
        if not doc:

            raise freezer_api_exc.BadDataFormat(