# Path: zoe_api/rest_api/request_handler.py
# class ZoeAPIRequestHandler(ZoeRequestHandler):
#     """RequestHandler class for Zoe Web interface."""
# 
#     def set_default_headers(self):
#         """Set up the headers for enabling CORS."""
#         self._manage_cors_headers()
# 
#     def _manage_cors_headers(self):
#         """Set up the headers for enabling CORS."""
#         if self.request.headers.get('Origin') is None:
#             self.set_header("Access-Control-Allow-Origin", "*")
#         else:
#             self.set_header("Access-Control-Allow-Origin", self.request.headers.get('Origin'))
#         self.set_header("Access-Control-Allow-Credentials", "true")
#         self.set_header("Access-Control-Allow-Headers", "x-requested-with, Content-Type, origin, authorization, accept, client-security-token")
#         self.set_header("Access-Control-Allow-Methods", "OPTIONS, GET, DELETE")
#         self.set_header("Access-Control-Max-Age", "1000")
# 
#     def options(self):
#         """Needed for CORS."""
#         self.set_status(204)
#         self.finish()
# 
#     def get_current_user(self):
#         """In case auth fails, redirect to login page."""
#         try:
#             user = super().get_current_user()
#         except ZoeException as e:
#             self.set_status(e.status_code, "Unauthorized access: {}".format(e))
#             return None
#         return user
# 
# Path: zoe_api/exceptions.py
# class ZoeException(Exception):
#     """
#     A generic exception.
#     """
#     def __init__(self, message='Something happened'):
#         super().__init__()
#         self.message = message
#         self.status_code = 500
# 
#     def __str__(self):
#         return '{}: {}'.format(self.status_code, self.message)


import tornado.escape
from zoe_api.rest_api.request_handler import ZoeAPIRequestHandler
from zoe_api.exceptions import ZoeException
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""The Execution API endpoints."""




class ExecutionAPI(ZoeAPIRequestHandler):
    """The Execution API endpoint."""

    def get(self, execution_id):
        """GET a single execution by its ID."""
        if self.current_user is None:
            return

        try:
            execution_id = int(execution_id)
        except ValueError:
            self.set_status(400, "Parameter must be an integer")

        try:
            e = self.api_endpoint.execution_by_id(self.current_user, execution_id)

# Path: zoe_api/rest_api/request_handler.py
# class ZoeAPIRequestHandler(ZoeRequestHandler):
#     """RequestHandler class for Zoe Web interface."""
# 
#     def set_default_headers(self):
#         """Set up the headers for enabling CORS."""
#         self._manage_cors_headers()
# 
#     def _manage_cors_headers(self):
#         """Set up the headers for enabling CORS."""
#         if self.request.headers.get('Origin') is None:
#             self.set_header("Access-Control-Allow-Origin", "*")
#         else:
#             self.set_header("Access-Control-Allow-Origin", self.request.headers.get('Origin'))
#         self.set_header("Access-Control-Allow-Credentials", "true")
#         self.set_header("Access-Control-Allow-Headers", "x-requested-with, Content-Type, origin, authorization, accept, client-security-token")
#         self.set_header("Access-Control-Allow-Methods", "OPTIONS, GET, DELETE")
#         self.set_header("Access-Control-Max-Age", "1000")
# 
#     def options(self):
#         """Needed for CORS."""
#         self.set_status(204)
#         self.finish()
# 
#     def get_current_user(self):
#         """In case auth fails, redirect to login page."""
#         try:
#             user = super().get_current_user()
#         except ZoeException as e:
#             self.set_status(e.status_code, "Unauthorized access: {}".format(e))
#             return None
#         return user
# 
# Path: zoe_api/exceptions.py
# class ZoeException(Exception):
#     """
#     A generic exception.
#     """
#     def __init__(self, message='Something happened'):
#         super().__init__()
#         self.message = message
#         self.status_code = 500
# 
#     def __str__(self):
#         return '{}: {}'.format(self.status_code, self.message)


# Path: zoe_api/rest_api/execution.py
import tornado.escape
from zoe_api.rest_api.request_handler import ZoeAPIRequestHandler
from zoe_api.exceptions import ZoeException

#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""The Execution API endpoints."""




class ExecutionAPI(ZoeAPIRequestHandler):
    """The Execution API endpoint."""

    def get(self, execution_id):
        """GET a single execution by its ID."""
        if self.current_user is None:
            return

        try:
            execution_id = int(execution_id)
        except ValueError:
            self.set_status(400, "Parameter must be an integer")

        try:
            e = self.api_endpoint.execution_by_id(self.current_user, execution_id)

        except ZoeException as e: