# Path: politicos_api/cache.py
# class RedisCacheBackend(CacheBackend):
# 
#     def __init__(self, redis_connection, **options):
#         self.options = dict(timeout=86400)
#         self.options.update(options)
#         self.redis = redis_connection
# 
#     async def get(self, key):
#         if await self.exists(key):
#             return await self.redis.get(key)
#         return None
# 
#     async def set(self, key, value, timeout=None):
#         await self.redis.set(key, value)
#         if timeout:
#             await self.redis.expire(key, timeout)
#         else:
#             await self.redis.expire(key, self.options['timeout'])
# 
#     async def delitem(self, key):
#         await self.redis.delete(key)
# 
#     async def exists(self, key):
#         return bool(await self.redis.exists(key))
# 
# Path: politicos_api/urls.py

# 
# Path: politicos_api/handlers/base.py
# class ErrorHandler(BaseErrorHandler):
#     def write_error(self, status_code, **kwargs):
#         loader = Loader('politicos_api/templates')
#         if status_code == 404:
#             self.write(loader.load('404.html').generate())
#         else:
#             self.write(loader.load('error.html').generate())


import aioredis
import tornado.web
from elasticsearch_async import AsyncElasticsearch
from tornado.options import options
from politicos_api.cache import RedisCacheBackend
from politicos_api.urls import handlers_api, handlers_website
from politicos_api.handlers.base import ErrorHandler
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018, Marcelo Jorge Vieira <metal@alucinados.com>
#
#  This program is free software: you can redistribute it and/or modify it
#  under the terms of the GNU Affero General Public License as published by the
#  Free Software Foundation, either version 3 of the License, or (at your
#  option) any later version.
#
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
#  for more details.
#
#  You should have received a copy of the GNU Affero General Public License
#  along with this program. If not, see <http://www.gnu.org/licenses/>.




class Application(tornado.web.Application):

    def __init__(self):
        settings = dict(
            debug=options.debug,
            default_handler_class=ErrorHandler,
            default_handler_args=dict(status_code=404),
        )
        self.handlers_website = handlers_website
        self.handlers_api = handlers_api

# Path: politicos_api/cache.py
# class RedisCacheBackend(CacheBackend):
# 
#     def __init__(self, redis_connection, **options):
#         self.options = dict(timeout=86400)
#         self.options.update(options)
#         self.redis = redis_connection
# 
#     async def get(self, key):
#         if await self.exists(key):
#             return await self.redis.get(key)
#         return None
# 
#     async def set(self, key, value, timeout=None):
#         await self.redis.set(key, value)
#         if timeout:
#             await self.redis.expire(key, timeout)
#         else:
#             await self.redis.expire(key, self.options['timeout'])
# 
#     async def delitem(self, key):
#         await self.redis.delete(key)
# 
#     async def exists(self, key):
#         return bool(await self.redis.exists(key))
# 
# Path: politicos_api/urls.py

# 
# Path: politicos_api/handlers/base.py
# class ErrorHandler(BaseErrorHandler):
#     def write_error(self, status_code, **kwargs):
#         loader = Loader('politicos_api/templates')
#         if status_code == 404:
#             self.write(loader.load('404.html').generate())
#         else:
#             self.write(loader.load('error.html').generate())


# Path: politicos_api/application.py
import aioredis
import tornado.web
from elasticsearch_async import AsyncElasticsearch
from tornado.options import options
from politicos_api.cache import RedisCacheBackend
from politicos_api.urls import handlers_api, handlers_website
from politicos_api.handlers.base import ErrorHandler

# -*- coding: utf-8 -*-
#
# Copyright (c) 2018, Marcelo Jorge Vieira <metal@alucinados.com>
#
#  This program is free software: you can redistribute it and/or modify it
#  under the terms of the GNU Affero General Public License as published by the
#  Free Software Foundation, either version 3 of the License, or (at your
#  option) any later version.
#
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
#  for more details.
#
#  You should have received a copy of the GNU Affero General Public License
#  along with this program. If not, see <http://www.gnu.org/licenses/>.




class Application(tornado.web.Application):

    def __init__(self):
        settings = dict(
            debug=options.debug,
            default_handler_class=ErrorHandler,
            default_handler_args=dict(status_code=404),
        )
        self.handlers_website = handlers_website
        self.handlers_api = handlers_api

        self.handlers = self.handlers_api + self.handlers_website