Пример #1
0
 def url_for(self, endpoint, **kwargs):
     try:
         return self.env['urls'].build(endpoint, kwargs)
     except BuildError:
         if isinstance(endpoint, basestring):
             # we store callable endpoints, so try importing
             endpoint = import_whatever(endpoint)
         return self.env['urls'].build(endpoint, kwargs)
Пример #2
0
    def make_env(self, **settings):
        if 'secret' not in settings:
            # TODO: add tool.conf.ConfigurationError excepton class
            raise KeyError('Plugin {0} requires setting "secret"'.format(__name__))

        db_label = settings.pop('database', None)
        database = storages.get(db_label) or default_storage()

        if settings.get('config'):
            conf = import_whatever(settings['config'])
            mw_conf = conf(**settings) if hasattr(conf, '__call__') else conf
        else:
            preset = settings.get('preset', 'basic')
            f = KNOWN_PRESETS[preset]
            mw_conf = f(**settings)

        return {
            'middleware_config': mw_conf,
            'database': database,
        }