def test_CacheWithPrefix(self): s = Storage({'application': 'admin', 'folder': 'applications/admin'}) cache = Cache(s) prefix = cache.with_prefix(cache.ram, 'prefix') self.assertEqual(prefix('a', lambda: 1, 0), 1) self.assertEqual(prefix('a', lambda: 2, 100), 1) self.assertEqual(cache.ram('prefixa', lambda: 2, 100), 1)
def __init__(self, db, query, orderby, current=None, display_count=4, cache=None, r=None, res=None): self.db = db self.query = query self.orderby = orderby if not current: if not r.vars.p: current = 0 else: current = int(r.vars.p) elif not isinstance(current, int): current = int(current) self.current = current self.display_count = display_count self.r = r self.res = res if not cache: self.cache = (Cache(r).ram, 1500) else: self.cache = cache
def test_DALcache(self): s = Storage({'application': 'admin', 'folder': 'applications/admin'}) cache = Cache(s) db = DAL(check_reserved=['all']) db.define_table('t_a', Field('f_a')) db.t_a.insert(f_a='test') db.commit() a = db(db.t_a.id > 0).select(cache=(cache.ram, 60), cacheable=True) b = db(db.t_a.id > 0).select(cache=(cache.ram, 60), cacheable=True) self.assertEqual(a.as_csv(), b.as_csv()) c = db(db.t_a.id > 0).select(cache=(cache.disk, 60), cacheable=True) d = db(db.t_a.id > 0).select(cache=(cache.disk, 60), cacheable=True) self.assertEqual(c.as_csv(), d.as_csv()) self.assertEqual(a.as_csv(), c.as_csv()) self.assertEqual(b.as_csv(), d.as_csv()) e = db(db.t_a.id > 0).select(cache=(cache.disk, 60)) f = db(db.t_a.id > 0).select(cache=(cache.disk, 60)) self.assertEqual(e.as_csv(), f.as_csv()) self.assertEqual(a.as_csv(), f.as_csv()) g = db(db.t_a.id > 0).select(cache=(cache.ram, 60)) h = db(db.t_a.id > 0).select(cache=(cache.ram, 60)) self.assertEqual(g.as_csv(), h.as_csv()) self.assertEqual(a.as_csv(), h.as_csv()) db.t_a.drop() db.close()
def initVars(): global current, request, response, session, cache, T current.request = request = Request() current.response = response = Response() current.session = session = Session() current.cache = cache = Cache(request) current.T = T = m__T__
def __init__(self): super(Application, self).__init__() # copy current context self.db = current.db self.T = current.T self.auth = current.auth self.request = current.request self.response = current.response self.session = current.session self.mail = current.mail self.conf = current.conf self.registry = Storage() self.cache = Cache(self.request)
def build_environment(request, response, session, store_current=True): """ Build the environment dictionary into which web2py files are executed. """ #h,v = html,validators environment = dict(_base_environment_) if not request.env: request.env = Storage() # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and # /[controller]/[function]/*.py) response.models_to_run = [ r'^\w+\.py$', r'^%s/\w+\.py$' % request.controller, r'^%s/%s/\w+\.py$' % (request.controller, request.function) ] t = environment['T'] = translator( os.path.join(request.folder, 'languages'), request.env.http_accept_language) c = environment['cache'] = Cache(request) if store_current: current.globalenv = environment current.request = request current.response = response current.session = session current.T = t current.cache = c global __builtins__ if is_jython: # jython hack __builtins__ = mybuiltin() elif is_pypy: # apply the same hack to pypy too __builtins__ = mybuiltin() else: __builtins__['__import__'] = __builtin__.__import__ # WHY? environment['request'] = request environment['response'] = response environment['session'] = session environment['local_import'] = \ lambda name, reload=False, app=request.application:\ local_import_aux(name, reload, app) BaseAdapter.set_folder(pjoin(request.folder, 'databases')) response._view_environment = copy.copy(environment) custom_import_install() return environment
def build_environment(request, response, session, store_current=True): """ Build the environment dictionary into which web2py files are executed. """ # h,v = html,validators environment = dict(_base_environment_) if not request.env: request.env = Storage() # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and # /[controller]/[function]/*.py) response.models_to_run = [ r'^\w+\.py$', r'^%s/\w+\.py$' % request.controller, r'^%s/%s/\w+\.py$' % (request.controller, request.function) ] T = environment['T'] = TranslatorFactory( os.path.join(request.folder, 'languages'), request.env.http_accept_language) c = environment['cache'] = Cache(request) # configure the validator to use the t translator Validator.translator = staticmethod(lambda text: None if text is None else str(T(text))) if store_current: current.globalenv = environment current.request = request current.response = response current.session = session current.T = T current.cache = c if is_jython: # jython hack global __builtins__ __builtins__ = mybuiltin() environment['request'] = request environment['response'] = response environment['session'] = session environment['local_import'] = \ lambda name, reload=False, app=request.application:\ local_import_aux(name, reload, app) BaseAdapter.set_folder(pjoin(request.folder, 'databases')) custom_import_install() return environment
def build_environment(request, response, session, store_current=True): """ Build the environment dictionary into which web2py files are executed. """ # h,v = html,validators environment = dict(_base_environment_) if not request.env: request.env = Storage() # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and # /[controller]/[function]/*.py) response.models_to_run = [ r'^\w+\.py$', r'^%s/\w+\.py$' % request.controller, r'^%s/%s/\w+\.py$' % (request.controller, request.function) ] T = environment['T'] = TranslatorFactory( pjoin(request.folder, 'languages'), request.env.http_accept_language) c = environment['cache'] = Cache(request) # configure the validator to use the t translator Validator.translator = staticmethod(lambda text: None if text is None else str(T(text))) if store_current: current.globalenv = environment current.request = request current.response = response current.session = session current.T = T current.cache = c if global_settings.is_jython: # jython hack class mybuiltin(object): """ NOTE could simple use a dict and populate it, NOTE not sure if this changes things though if monkey patching import..... """ # __builtins__ def __getitem__(self, key): try: return getattr(builtin, key) except AttributeError: raise KeyError(key) def __setitem__(self, key, value): setattr(self, key, value) global __builtins__ __builtins__ = mybuiltin() environment['request'] = request environment['response'] = response environment['session'] = session environment['local_import'] = \ lambda name, reload=False, app=request.application:\ local_import_aux(name, reload, app) BaseAdapter.set_folder(pjoin(request.folder, 'databases')) custom_import_install() return environment
# $Id: chimitheque_ide_autocomplete.py 194 2015-02-23 16:27:16Z tbellemb $ # -*- coding: utf-8 -*- if False: # # never imported - just for IDE autocompletion # from gluon import DAL db = DAL() from gluon import settings from gluon.cache import Cache from gluon.dal import Field from gluon.globals import Request request = Request() from gluon.globals import Response response = Response() from gluon.globals import Session session = Session() from gluon.html import * from gluon.http import HTTP from gluon.http import redirect from gluon.languages import translator T = translator(request) from gluon.sqlhtml import SQLFORM from gluon.tools import Auth auth = Auth() from gluon.tools import Crud, Mail from gluon.validators import * import sys mail = Mail() cache = Cache() crud = Crud(globals(), db)
if 0: from gluon.html import * from gluon.validators import * from gluon.http import redirect, HTTP from gluon.sqlhtml import SQLFORM, SQLTABLE from gluon.compileapp import LOAD from gluon.globals import Request, Response, Session, current from gluon.cache import Cache from gluon.languages import translator from gluon.tools import Auth, Crud, Mail, Service, PluginManager from gluon.dal import DAL, Field from chimitheque_multiple_widget import CHIMITHEQUE_MULTIPLE_widget # API objects request = Request() response = Response() session = Session() cache = Cache(request) T = translator(request, 'fr') # Objects commonly defined in application model files # (names are conventions only -- not part of API) db = DAL() auth = Auth(db) crud = Crud(db) mail = Mail() service = Service() plugins = PluginManager() settings = {}