def get_engine(cls, name=None, context=None): ''' ''' if context: _CONTEXT = True _context_cfg = config.Config().get(context, {}).get('sessions', {}) else: _CONTEXT = False _context_cfg = {} # try looking in config if no engine is specified if not name: name = _context_cfg.get('engine', 'cookies') # look for an explicit engine by name if requested if name in cls.__engines__: _engine, _engine_config = cls.__engines__[name] # build config, allowing overrides _config = {} if _CONTEXT: _config.update(config.Config().get('SessionAPI', {})) _config.update(_context_cfg) _config.update(_engine_config) return _engine(name, _config, cls) raise RuntimeError('No such session runtime: "%s".' % name)
def spawn(app, dev, config=None, root=None): ''' ''' # canteen core & util from canteen.core import runtime from canteen.util import config as cfg if not config: config = cfg.Config() return runtime.Runtime.spawn(app).configure(config)
def config(cls): ''' ''' return config.Config().get('http', {'debug': True})
def assets(self): ''' ''' return config.Config().assets.get('assets', {})
def config(self): ''' ''' return config.Config().assets.get('config', {'debug': True})
def path(self): ''' ''' return config.Config().app.get('paths', {}).get( 'assets', os.path.join(os.getcwd(), 'assets'))
def config(self): # pragma: no cover ''' Cached config shortcut. :returns: Configuration ``dict``, if any. Defaults to ``{'debug': True}``. ''' return config.Config().get(self.__class__.__name__, {'debug': True})
def config(cls): ''' ''' return config.Config().get('SessionAPI', {'debug': True})
config = cfg.Config( app={ 'name': 'rpc-sample', # Main app settings 'debug': __debug__, # Dev tools 'dev': { 'profiler': { 'enable': False } }, # Runtime config 'runtime': 'werkzeug', # App paths 'paths': { 'assets': os.path.join(app, 'assets'), 'favicon': os.path.join(app, 'assets', 'img', 'favicon.ico'), 'templates': { 'source': os.path.join(app, 'templates') } } }, config={ ##### ===== General Settings ===== ##### # Gevent Config 'gevent': { 'engine': 'wsgi' # `pywsgi`, `wsgi`, or `stream` }, # HTTP semantics 'http': { # HTTP session settings 'sessions': { 'engine': 'cookies', 'cookies': { 'key': 'canteen', 'domain': None, 'path': '/', 'secure': False, # only secure in production 'http_only': True, 'max_age': 3600, 'mode': 'json' } }, # Default headers to add 'headers': { 'X-DNS-Prefetch-Control': 'on' } }, ##### ===== Framework APIs ===== ##### ### == Cache API == ### 'CacheAPI': { 'debug': __debug__, }, ### === Model API === ### 'ModelAPI': { 'debug': __debug__, }, ### === Session API === ### 'SessionAPI': { 'enable': True, 'debug': __debug__, 'always_establish': True, 'salt': 'vcklckxvnliNP@J!@)U@!)&)@(Udoijpoj2-19', 'secret': 'jvn80Y)!*U)@(U@)(Jdij029jlcknv083y1f', 'algorithm': hashlib.sha1 }, ### === Template API === ### 'TemplateAPI': { 'debug': __debug__, 'force_compiled': False, 'haml': { 'debug': __debug__, 'mode': 'compact' }, 'syntax': { 'variable': ('{{', '}}'), 'block': ('{%', '%}'), 'comment': ('{#', '#}') }, 'jinja2': { 'autoescape': True, 'extensions': [ 'jinja2.ext.autoescape', 'jinja2.ext.with_', ], } }, ##### ===== Database APIs ===== ##### 'RedisAdapter': { 'debug': True, 'servers': { 'default': 'local', # Redis Instances 'local': { 'host': '127.0.0.1', 'port': 6379 } } }, }, assets={ ##### ===== Assets ===== ##### # Asset API config 'config': { # main settings 'minified': False, 'cdn_prefix': ['//'], 'serving_mode': 'cdn' if not __debug__ else 'local', }, # Asset registry 'assets': { 'style': { 'sample': { # sample app CSS 'app': { 'version': 'v1', 'minified': False } } }, 'scripts': {}, 'fonts': {} } })