# Path: src/merveilles/context_processors.py
# @app.app_context_processor
# def db_meta_info():
#     meta = {}
#     db = DB()
#     db_file = current_app.config['DB_FILE']
#     if not db.open("{0}".format(db_file), DB.OREADER):
#         print("Could not open database (meta info).")
#     meta["size"] = db.size()
#     meta["count"] = db.count()
#     db.close()
# 
#     return meta


from .context_processors import db_meta_info
from flask import request, current_app
from functools import wraps
from kyotocabinet import DB
import requests, time, urllib.request, urllib.parse, urllib.error, calendar
            expiration = int(calendar.timegm(time.gmtime())) + 60 #(60 * 60 * 24)
            utf_data = res.encode('utf-8')
            requests.post("http://localhost:8080/{}".format(quoted),
                data=utf_data,
                headers={
                    "Content-Type": "text/html",
                    "X-OlegDB-use-by": expiration})
        else:
            res = resp.raw.read()

        full_time = lambda: "%.2fms" % ((time.time() - start_cache_time) * 1000)
        cache_str = "<!-- Cache time: {} -->".format(full_time())
        appended = res
        try:
            appended = "{}{}".format(res, cache_str)
        except UnicodeEncodeError:
            pass
        return appended
    return decorated_function

def kc_view_cache(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        # Debug
        if not current_app.config['CACHE']:
            return f(*args, **kwargs)

        db = DB()
        db.open("/tmp/page_cache.kch")
        res = None

# Path: src/merveilles/context_processors.py
# @app.app_context_processor
# def db_meta_info():
#     meta = {}
#     db = DB()
#     db_file = current_app.config['DB_FILE']
#     if not db.open("{0}".format(db_file), DB.OREADER):
#         print("Could not open database (meta info).")
#     meta["size"] = db.size()
#     meta["count"] = db.count()
#     db.close()
# 
#     return meta


# Path: src/merveilles/cache.py
from .context_processors import db_meta_info
from flask import request, current_app
from functools import wraps
from kyotocabinet import DB
import requests, time, urllib.request, urllib.parse, urllib.error, calendar

            expiration = int(calendar.timegm(time.gmtime())) + 60 #(60 * 60 * 24)
            utf_data = res.encode('utf-8')
            requests.post("http://localhost:8080/{}".format(quoted),
                data=utf_data,
                headers={
                    "Content-Type": "text/html",
                    "X-OlegDB-use-by": expiration})
        else:
            res = resp.raw.read()

        full_time = lambda: "%.2fms" % ((time.time() - start_cache_time) * 1000)
        cache_str = "<!-- Cache time: {} -->".format(full_time())
        appended = res
        try:
            appended = "{}{}".format(res, cache_str)
        except UnicodeEncodeError:
            pass
        return appended
    return decorated_function

def kc_view_cache(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        # Debug
        if not current_app.config['CACHE']:
            return f(*args, **kwargs)

        db = DB()
        db.open("/tmp/page_cache.kch")
        res = None

        fancy = hash("{}{}{}".format(db_meta_info()['count'], request.url, f.__name__))