# Path: yithlibraryserver/db.py
# def get_db(request):
#     return request.registry.settings['mongodb'].get_database()
# 
# Path: yithlibraryserver/locale.py
# class DatesFormatter(object):
# 
#     def __init__(self, locale_name):
#         self.locale_name = locale_name
# 
#     def date(self, date_value):
#         if HAS_BABEL:
#             return format_date(date_value, locale=self.locale_name)
#         else:
#             return date_value.strftime('%c')
# 
#     def datetime(self, datetime_value):
#         if HAS_BABEL:
#             return format_datetime(datetime_value, locale=self.locale_name)
#         else:
#             return datetime_value.strftime('%c')


from pyramid.events import BeforeRender, NewRequest
from pyramid.i18n import get_locale_name
from pyramid.renderers import get_renderer
from yithlibraryserver.db import get_db
from yithlibraryserver.locale import DatesFormatter
# 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.
#
# Yith Library Server 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 General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.




def add_cors_headers_response(event):
    cors_manager = event.request.registry.settings['cors_manager']

    def cors_headers_callback(request, response):
        return cors_manager.add_cors_header(request, response)

    event.request.add_response_callback(cors_headers_callback)


def add_compress_response_callback(event):

    def gzip_response(request, response):
        response.encode_content('gzip')
        return response


# Path: yithlibraryserver/db.py
# def get_db(request):
#     return request.registry.settings['mongodb'].get_database()
# 
# Path: yithlibraryserver/locale.py
# class DatesFormatter(object):
# 
#     def __init__(self, locale_name):
#         self.locale_name = locale_name
# 
#     def date(self, date_value):
#         if HAS_BABEL:
#             return format_date(date_value, locale=self.locale_name)
#         else:
#             return date_value.strftime('%c')
# 
#     def datetime(self, datetime_value):
#         if HAS_BABEL:
#             return format_datetime(datetime_value, locale=self.locale_name)
#         else:
#             return datetime_value.strftime('%c')


# Path: yithlibraryserver/subscribers.py
from pyramid.events import BeforeRender, NewRequest
from pyramid.i18n import get_locale_name
from pyramid.renderers import get_renderer
from yithlibraryserver.db import get_db
from yithlibraryserver.locale import DatesFormatter

# 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.
#
# Yith Library Server 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 General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.




def add_cors_headers_response(event):
    cors_manager = event.request.registry.settings['cors_manager']

    def cors_headers_callback(request, response):
        return cors_manager.add_cors_header(request, response)

    event.request.add_response_callback(cors_headers_callback)


def add_compress_response_callback(event):

    def gzip_response(request, response):
        response.encode_content('gzip')
        return response


    accepted = event.request.accept_encoding.best_match(('identity', 'gzip'))