コード例 #1
0
ファイル: _init.py プロジェクト: score-framework/py.geoip
def init(confdict, kvcache=None):
    """
    Initializes this module acoording to :ref:`our module initialization
    guidelines <module_initialization>` with the following configuration keys:

    :confkey:`backend` :confdefault:`score.geoip.backend.IpApi()`
        The backend object configuration that will be passed to
        :func:`score.init.parse_object`. Will use the `ip-api`_ backend by
        default, which is free for non-commercial projects.

        .. _ip-api: http://ip-api.com/
    """
    conf = defaults.copy()
    conf.update(confdict)
    backend = parse_object(conf, "backend")
    cache_container = None
    if kvcache is not None:
        kvcache.register_generator("score.geoip", backend.__getitem__)
        cache_container = kvcache["score.geoip"]
    return ConfiguredGeoipModule(backend, cache_container)
コード例 #2
0
ファイル: _init.py プロジェクト: score-framework/py.webassets
def init(confdict, http=None, netfs=None):
    """
    Initializes this module acoording to :ref:`our module initialization
    guidelines <module_initialization>` with the following configuration keys:

    :confkey:`cachedir` :default:`None`
        A writable folder that will be used to cache intermediate values. This
        value is mostly unused in this module, but the initialized value can be
        used by other modules. The :mod:`css module <score.css>`, for example,
        will create a sub-folder beneath this folder, if it was initialized
        without an explicit `cachedir` of its own.

    :confkey:`versionmanager` :default:`score.webassets.versioning.Dummy`
        The :class:`VersionManager <score.webassets.versioning.VersionManager>`
        to use. This value will be converted to an object using
        :func:`score.init.parse_object`.

        See the :mod:`package description <score.webassets.versioning>` for
        available implementations.

    :confkey:`netfs` :default:`True`
        The initializer will upload all webassets to a :mod:`score.netfs`
        server, if one was configured. You can disable this feature by passing a
        `False` value here
    """
    conf = dict(defaults.items())
    conf.update(confdict)
    if conf['cachedir']:
        init_cache_folder(conf, 'cachedir', autopurge=True)
    versionmanager = parse_object(conf, 'versionmanager')
    if netfs and parse_bool(conf['netfs']):
        versionmanager = NetfsVersionManager(versionmanager, netfs)

    def assetnotfound(ctx, exception):
        raise HTTPNotFound()
    if http:
        http.exception_handlers[AssetNotFound] = assetnotfound
    return ConfiguredWebassetsModule(conf['cachedir'], versionmanager)
コード例 #3
0
ファイル: _init.py プロジェクト: score-framework/py.kvcache
def init(confdict):
    """
    Initializes this module according to :ref:`our module initialization
    guidelines <module_initialization>` with the following configuration keys:

    :confkey:`container`
        The cache container configuration. A container defines a name,
        a backend and optionally a generator and an expire. The configuration
        key for a container starts with ``container`` followed by the name
        and the configuration keys for the container.

        For example, the following configuration::

            container.greeter.backend = score.kvcache.backend.FileCache
            container.greeter.backend.path = /tmp/greeter.sqlite3
            container.greeter.generator = dotted.path.to.greeting_generator
            container.greeter.expire = 1m

        The Backend config will be passed to
        :func:`score.init.init_object`. Have a look at the configurable
        backend's constructor parameters for further information about
        the backend's configurable keys.

        To make life easier for a huge set of container configurations, we serve
        the possibility to configure backend aliases that will replace the
        container's backend config if the name matches.

        For example::

            backend.example_filecache = score.kvcache.backend.FileCache
            backend.example_filecache.path = /tmp/filecache.sqlite3
            container.greeter.backend = example_filecache
            container.greeter.generator = dotted.path.to.greeting_generator
            container.greeter.expire = 1m
            container.counter.backend = example_filecache
            container.counter.generator = dotted.path.to.counting_generator
            container.counter.expire = 30 seconds

    """
    containers = {}
    for container_conf in extract_conf(confdict, 'container.'):
        if not container_conf.endswith('.backend'):
            continue
        backend_key = 'container.%s' % container_conf
        backend_val = confdict[backend_key]
        if backend_val in extract_conf(confdict, 'backend.'):
            alias_conf = extract_conf(confdict, 'backend.%s' % backend_val)
            for k, v in alias_conf.items():
                confdict.update({'%s%s' % (backend_key, k): v})
        container_name = container_conf[:-len('.backend')]
        backend = parse_object(confdict, backend_key)
        generator_key = 'container.%s.generator' % container_name
        generator = None
        if generator_key in confdict:
            generator = parse_dotted_path(confdict[generator_key])
        expire_key = 'container.%s.expire' % container_name
        expire = None
        if expire_key in confdict:
            expire = parse_time_interval(confdict[expire_key])
        containers[container_name] = CacheContainer(container_name, backend,
                                                    generator=generator,
                                                    expire=expire)
    return ConfiguredKvCacheModule(containers)