<commit_before># -*- coding: utf-8 -*-
"""
    glashammer.bundles.gae
    ~~~~~~~~~~~~~~~~~~~~~~

    Google Appengine integration

    :copyright: 2007 by Glashammer Developers
    :license: MIT
"""

from wsgiref.handlers import CGIHandler

from google.appengine.api import users
from google.appengine.ext import db

from glashammer.utils import local, get_request, redirect
from glashammer.application import make_app

def get_gae_user():
    return local.gae_user

def gae_local_processor(req):
    user = users.get_current_user()
    local.gae_user = user

def gae_user_only_view(f):
    def wrapped(req, **kw):
        if local.gae_user is None:
            return redirect_gae_login_url()
        else:
            return f(req, **kw)
    return wrapped

def gae_admin_only_view(f):
    def wrapped(req, **kw):
        if not users.is_current_user_admin():
            return redirect_gae_login_url()
        else:
            return f(req, **kw)
    return wrapped

def redirect_gae_login_url():
    req = get_request()
    return redirect(users.create_login_url(req.url))

def setup_gae(app):
    app.connect_event('request-start', gae_local_processor)

def make_gae_app(setup_func):
    app = make_app(setup_func, '.') 
    return app

def make_and_run_gae_app(setup_func):
    app = make_gae_app(setup_func)
    CGIHandler().run(app)

<commit_msg>caching for gae<commit_after># -*- coding: utf-8 -*-
"""
    glashammer.bundles.gae
    ~~~~~~~~~~~~~~~~~~~~~~

    Google Appengine integration

    :copyright: 2007 by Glashammer Developers
    :license: MIT
"""

from wsgiref.handlers import CGIHandler

from werkzeug.contrib.cache import MemcachedCache, BaseCache

from google.appengine.api import users, memcache
from google.appengine.ext import db

from glashammer.utils import local, get_request, redirect
from glashammer.application import make_app


def get_gae_user():
    return local.gae_user


def get_gae_cache():
    return local.gae_cache


def gae_local_processor(req):
    user = users.get_current_user()
    local.gae_user = user
    cache = GaeMemcachedCache()
    local.gae_cache = cache


def gae_user_only_view(f):
    def wrapped(req, **kw):
        if local.gae_user is None:
            return redirect_gae_login_url()
        else:
            return f(req, **kw)
    return wrapped


def gae_admin_only_view(f):
    def wrapped(req, **kw):
        if not users.is_current_user_admin():
            return redirect_gae_login_url()
        else:
            return f(req, **kw)
    return wrapped


def redirect_gae_login_url():
    req = get_request()
    return redirect(users.create_login_url(req.url))


from google.appengine.api import memcache

class GaeMemcachedCache(MemcachedCache):
    """A werkzeug memcached object for GAE"""

    def __init__(self, timeout=300):
        BaseCache.__init__(self, timeout)
        self._client = memcache.Client()


def setup_gae(app, cache_manage_url=None):
    app.connect_event('request-start', gae_local_processor)

    if cache_url


def make_gae_app(setup_func):
    app = make_app(setup_func, '.')
    return app


def make_and_run_gae_app(setup_func):
    app = make_gae_app(setup_func)
    CGIHandler().run(app)


{'fraction_non_alphanumeric': 0.10690840887777431, 'fraction_numerical': 0.004063769928102532, 'mean_word_length': 3.4444444444444446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '207645', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1038, 'n_words': 238}