Beispiel #1
0
def get_init(global_config, settings, init_cls=None) -> Initializer:
    """Get Initializer class instance for WSGI-like app.

    TODO: Deprecated. Use Pyramid's ``bootstrap()`` instead.

    Reads reference to the initializer from settings, resolves it and creates the initializer instance.

    Example 1::

        config_uri = argv[1]
        init = get_init(dict(__file__=config_uri), settings)

    :param global_config: Global config dictionary, having __file__ entry as given by Paster

    :param settings: Settings dictionary

    :param init_cls: Explicitly give the Initializer class to use, otherwise read ``websauna.init`` settings.
    """

    assert "websauna.init" in settings, "You must have websauna.init setting pointing to your Initializer class"

    assert "__file__" in global_config

    if not init_cls:
        init_cls = settings.get("websauna.init")
        if not init_cls:
            raise RuntimeError("INI file lacks websauna.init option")
        resolver = DottedNameResolver()
        init_cls = resolver.resolve(init_cls)
    init = init_cls(global_config, settings)
    return init
def create_dummy_extract():
    date = datetime.datetime.now()
    real_estate = RealEstateRecord(
        u'test', u'BL', u'Laufen', 2770, 1000, MultiPolygon(),
        ViewServiceRecord('test_link', 1, 1.0, {'de': 'test_legend'}))
    plr_office = OfficeRecord({u'en': u'PLR Authority'})
    resolver = DottedNameResolver()
    date_method_string = Config.get('extract').get('base_data').get(
        'methods').get('date')
    date_method = resolver.resolve(date_method_string)
    av_update_date = date_method(real_estate)
    base_data = Config.get_base_data(av_update_date)

    av_provider_method_string = Config.get('extract').get('base_data').get(
        'methods').get('provider')
    av_provider_method = resolver.resolve(av_provider_method_string)
    cadaster_state = date
    theme = ThemeRecord(u'TEST', {u'de': u'TEST TEXT'})
    datasources = [DatasourceRecord(theme, date, plr_office)]
    plr_cadastre_authority = Config.get_plr_cadastre_authority()
    embeddable = EmbeddableRecord(cadaster_state, plr_cadastre_authority,
                                  av_provider_method(real_estate),
                                  av_update_date, datasources)
    record = ExtractRecord(real_estate, ImageRecord('100'.encode('utf-8')),
                           ImageRecord('100'.encode('utf-8')),
                           ImageRecord('100'.encode('utf-8')),
                           ImageRecord('100'.encode('utf-8')), plr_office,
                           base_data, embeddable)
    return record
Beispiel #3
0
def debug(request, registry, settings):
    """Invoke pdb breakpoint from a template.

    Example:

    .. code-block:: html+jinja

        <h1>{{ site_name }}</h1>

        {{ debug() }}

    This will invoke function from :ref:`websauna.template_debugger` setting. The debugger is turned on only on :ref:`development.ini`. If there is no debugger configured, a warning is given.
    """
    def _dummy():
        logger.warn(
            "{{ debug() }} invoked, but websauna.template_debugger not set")
        return ""

    template_debugger = settings.get("websauna.template_debugger")
    if not template_debugger:
        debugger = _dummy
    else:
        r = DottedNameResolver()
        debugger = r.resolve(template_debugger)

    def _inner():
        debugger()
        return ""

    return _inner
Beispiel #4
0
    def configure_mailer(self):
        """Configure outgoing email backend and email test views."""
        from pyramid_mailer import IMailer

        settings = self.settings.copy()

        # Empty values are not handled gracefully, so mutate them here before passing forward to mailer
        if settings.get("mail.username", "x") == "":
            settings["mail.username"] = None

        if settings.get("mail.password", "x") == "":
            settings["mail.password"] = None

        mailer_class = settings.get("websauna.mailer", "")
        if mailer_class in ("mail", ""):
            # TODO: Make mailer_class explicit so we can dynamically load pyramid_mail.Mailer
            # Default
            from pyramid_mailer import mailer_factory_from_settings
            mailer = mailer_factory_from_settings(settings)
            self.config.registry.registerUtility(mailer, IMailer)
        else:
            # debug backend
            resolver = DottedNameResolver()
            mailer_cls = resolver.resolve(mailer_class)
            mailer = mailer_cls()

            self.config.registry.registerUtility(mailer, IMailer)

        if settings.get("websauna.sample_html_email", False):
            from websauna.system.mail import views
            self.config.scan(views)
            self.config.add_jinja2_search_path(
                'websauna.system:mail/templates', name='.html')
def includeme(config):
    """Bind to the db engine specifed in ``config.registry.settings``.
      
      Setup::
      
          >>> from mock import Mock
          >>> import pyramid_basemodel
          >>> _engine_from_config = pyramid_basemodel.engine_from_config
          >>> _bind_engine = pyramid_basemodel.bind_engine
          >>> pyramid_basemodel.engine_from_config = Mock()
          >>> pyramid_basemodel.engine_from_config.return_value = 'engine'
          >>> pyramid_basemodel.bind_engine = Mock()
          >>> mock_config = Mock()
          >>> mock_config.registry.settings = {}
      
      Calls ``bind_engine`` with the configured ``engine``::
      
          >>> includeme(mock_config)
          >>>
          >>> mock_config.action.assert_called_with(None,
          ...         pyramid_basemodel.bind_engine,
          ...         ('engine',),
          ...         {'should_create': False, 'should_drop': False})

      Unless told not to::

          >>> pyramid_basemodel.bind_engine = Mock()
          >>> mock_config = Mock()
          >>> mock_config.registry.settings = {'basemodel.should_bind_engine': False}
          >>> includeme(mock_config)
          >>> mock_config.action.called
          False

      Teardown::
      
          >>> pyramid_basemodel.engine_from_config = _engine_from_config
          >>> pyramid_basemodel.bind_engine = _bind_engine 
      
    """
    
    # Bind the engine.
    settings = config.get_settings()
    engine_kwargs_factory = settings.pop('sqlalchemy.engine_kwargs_factory', None)
    if engine_kwargs_factory:
        kwargs_factory = config.maybe_dotted(engine_kwargs_factory)
        engine_kwargs = kwargs_factory(config.registry)
    else:
        engine_kwargs = {}
    pool_class = settings.pop('sqlalchemy.pool_class', None)
    if pool_class:
        dotted_name = DottedNameResolver()
        engine_kwargs['poolclass'] = dotted_name.resolve(pool_class)
    should_bind = asbool(settings.get('basemodel.should_bind_engine', True))
    should_create = asbool(settings.get('basemodel.should_create_all', False))
    should_drop = asbool(settings.get('basemodel.should_drop_all', False))
    if should_bind:
        engine = engine_from_config(settings, 'sqlalchemy.', **engine_kwargs)
        config.action(None, bind_engine, (engine,), {
            'should_create': should_create,
            'should_drop': should_drop})
Beispiel #6
0
def get_municipality(request):
    """
    Returns the requested municipality logo from database.

    Args:
        request (pyramid.request.Request): The request containing the fosnr as matchdict parameter.

    Returns:
        pyramid.response.Response: The generated response object.
    """
    fosnr = request.matchdict.get('fosnr')
    source_params = Config.get_municipality_config().get('source').get('params')
    session = database_adapter.get_session(source_params.get('db_connection'))
    try:
        model = DottedNameResolver().resolve(source_params.get('model'))
        municipality = session.query(model).filter_by(fosnr=fosnr).first()
        if municipality:
            logo = getattr(municipality, 'logo', None)
            if logo:
                response = request.response
                response.status_int = 200
                response.content_type = 'image/*'
                response.body = base64.b64decode(logo.encode('ascii'))
                return response
        raise HTTPNotFound()
    finally:
        session.close()
Beispiel #7
0
def test_app_no_login_real_policy(request, test_app_no_perm):
    """A configured Assembl fixture with permissions
    and no user logged in"""
    config = testing.setUp(
        registry=test_app_no_perm.app.registry,
        settings=get_config(),
    )

    from ...auth.util import authentication_callback
    from pyramid.authorization import ACLAuthorizationPolicy
    from pyramid.path import DottedNameResolver
    resolver = DottedNameResolver(__package__)
    auth_policy_name = "assembl.auth.util.UpgradingSessionAuthenticationPolicy"
    auth_policy = resolver.resolve(auth_policy_name)(
        callback=authentication_callback)

    config.set_authorization_policy(ACLAuthorizationPolicy())
    config.set_authentication_policy(auth_policy)

    import transaction
    # ensure default roles and permissions at startup
    from ...models import get_session_maker
    with transaction.manager:
        session = get_session_maker()
        from ...lib.migration import bootstrap_db_data
        bootstrap_db_data(session, False)

    return test_app_no_perm
Beispiel #8
0
def get_storage_impl(settings) -> Callable[[Any], Any]:
    """ Get and configure the storage backend wrapper """
    resolver = DottedNameResolver(__name__)
    storage = settings.get("pypi.storage", "file")
    if storage == "azure-blob":
        if not AZURE_BLOB_IS_AVAILABLE:
            raise ValueError(
                "azure-blob storage backend selected but Azure Blob "
                "Storage is not available. "
                "Please install the azure-storage-blob library by "
                "including the `azure-blob` extra in your pip-install step. "
                "For example: `pip install pypicloud[azure-blob]`")

        storage = "pypicloud.storage.AzureBlobStorage"
    elif storage == "s3":
        storage = "pypicloud.storage.S3Storage"
    elif storage == "cloudfront":
        storage = "pypicloud.storage.CloudFrontS3Storage"
    elif storage == "gcs":
        if not GCS_IS_AVAILABLE:
            raise ValueError(
                "gcs backend selected but GCS is not available. "
                "Please install the google-cloud-storage library by "
                "including the `gcs` extra in your pip-install step. "
                "For example: `pip install pypicloud[gcs]`")

        storage = "pypicloud.storage.GoogleCloudStorage"
    elif storage == "file":
        storage = "pypicloud.storage.FileStorage"
    storage_impl = resolver.resolve(storage)
    kwargs = storage_impl.configure(settings)
    return partial(storage_impl, **kwargs)
Beispiel #9
0
def main():  # pragma: no cover
    parser = ArgumentParser('Pubsub listener pushing to websockets.')
    parser.add_argument('config', help='path to the config file')
    args, settings = parser.parse_args(), {}
    load_into_settings(args.config, settings)
    config = settings['config']

    ioloop.install()
    sub_socket = zmq.Context().socket(zmq.SUB)
    sub_socket.connect(config.get('zeromq', 'sub'))
    sub_socket.setsockopt(zmq.SUBSCRIBE, 'PUSH')
    print 'SUB sub_socket on', config.get('zeromq', 'sub')

    loop = ioloop.IOLoop.instance()
    port = config.get('websockets', 'port')
    Push(zmqstream.ZMQStream(sub_socket, loop))
    application.listen(port)
    print 'websockets on :%s' % port

    # Send a status report every 10 seconds.
    cfg = config.get_map('storage')
    storage = DottedNameResolver(None).resolve(cfg.pop('backend'))(**cfg)
    ip = '%s:%s' % (socket.gethostbyname(socket.getfqdn()), port)
    callback = partial(report_status, storage, ip)

    period = config.get('monitor', 'period')
    ioloop.PeriodicCallback(callback, period * 1000).start()
    # Get in the pool right away.
    callback()

    loop.start()
def includeme(config):
    """ Let extdirect be included by config.include(). """
    settings = config.registry.settings
    extdirect_config = dict()
    names = ("api_path", "router_path", "namespace", "descriptor",
             "expose_exceptions", "debug_mode", "json_encoder")
    for name in names:
        qname = "pyramid_extdirect.{}".format(name)
        value = settings.get(qname, None)
        if name == "expose_exceptions" or name == "debug_mode":
            value = (value == "true")
        if name == "json_encoder" and value:
            from pyramid.path import DottedNameResolver
            resolver = DottedNameResolver()
            value = resolver.resolve(value)
        if value is not None:
            extdirect_config[name] = value

    extd = Extdirect(**extdirect_config)
    config.registry.registerUtility(extd, IExtdirect)

    api_view_perm = settings.get("pyramid_extdirect.api_view_permission")
    config.add_route('extapi', extd.api_path)
    config.add_view(api_view, route_name='extapi', permission=api_view_perm)

    router_view_perm = settings.get("pyramid_extdirect.router_view_permission")
    config.add_route('extrouter', extd.router_path)
    config.add_view(router_view,
                    route_name='extrouter',
                    permission=router_view_perm)
Beispiel #11
0
def site_factory(request):
    """Application site factory

    On application startup, this factory checks configuration to get application name and
    load it from the ZODB; if the application can't be found, configuration is scanned to
    get application factory, create a new one and create a local site manager.
    """
    conn = get_connection(request)
    root = conn.root()
    application_key = request.registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY,
                                                    PYAMS_APPLICATION_DEFAULT_NAME)
    application = root.get(application_key)
    if application is None:
        factory = request.registry.settings.get(PYAMS_APPLICATION_FACTORY_KEY)
        if factory:
            resolver = DottedNameResolver()
            factory = resolver.maybe_resolve(factory)
        else:
            factory = request.registry.queryUtility(ISiteRootFactory, default=BaseSiteRoot)
        application = root[application_key] = factory()
        if IPossibleSite.providedBy(application):
            lsm = LocalSiteManager(application, default_folder=False)
            application.setSiteManager(lsm)
        try:
            # if some components require a valid and complete registry
            # with all registered utilities, they can subscribe to
            # INewLocalSiteCreatedEvent event interface
            set_local_registry(application.getSiteManager())
            get_current_registry().notify(NewLocalSiteCreatedEvent(application))
        finally:
            set_local_registry(None)
        import transaction  # pylint: disable=import-outside-toplevel
        transaction.commit()
    return application
Beispiel #12
0
def plr_sources(pyramid_oereb_test_config):
    plr_sources = []
    for plr in pyramid_oereb_test_config.get('plrs'):
        plr_source_class = DottedNameResolver().maybe_resolve(
            plr.get('source').get('class'))
        plr_sources.append(plr_source_class(**plr))
    yield plr_sources
Beispiel #13
0
def includeme(config):
    accession_factory = config.registry.settings.get('accession_factory')
    if accession_factory:
        factory = DottedNameResolver().resolve(accession_factory)
    else:
        factory = enc_accession
    config.registry[ACCESSION_FACTORY] = factory
Beispiel #14
0
 def render(resource):
     """TALES extension rendering method"""
     library, resource_name = resource.split(':')
     resolver = DottedNameResolver()
     module = resolver.maybe_resolve(library)
     resource = getattr(module, resource_name)
     return get_resource_path(resource)
Beispiel #15
0
    def run_widgets(self, request):
        theme = request.registry.settings['mokacms.theme']
        db = request.mdb
        self.log.debug("Running widgets for %s, (theme: %s)", self, theme)
        resolver = DottedNameResolver()
        theme = Theme.get(db, theme)
        widgets = []
        result = {}

        for template in theme.templates:
            if template['file'] == self.template:
                widgets = template["widgets"]

        self.log.debug("Found widgets: %s", widgets)
        for widget in widgets:
            callable_ = widget['callable']
            cname = "{}.{}".format(callable_.__module__, callable_.__name__)
            args = {a['name']: a['value'] for a in widget['args']}
            self.log.debug("Excecuting %s with args %s", cname, args)
            try:
                result[cname] = dict(
                    args=widget['args'],
                    result=callable_(request, **args)
                )

            except:
                self.log.exception("Error while running widget %s with args %s",
                                   cname, args)
                raise

        return result
Beispiel #16
0
    def __init__(self, **kwargs):
        """

        Keyword Args:
            db_connection (str): A rfc1738 conform database connection string in the form of:
                ``<driver_name>://<username>:<password>@<database_host>:<port>/<database_name>``
            model (str): A valid dotted name string which leads to an importable representation of
                sqlalchemy.ext.declarative.DeclarativeMeta or the real class itself.
        """
        from pyramid_oereb import database_adapter

        if database_adapter:
            self._adapter_ = database_adapter
        else:
            raise ConfigurationError(
                'Adapter for database must be defined if you use database sources.'
            )
        if kwargs.get('db_connection'):
            self._key_ = kwargs.get('db_connection')
        else:
            raise ConfigurationError(
                '"db_connection" for source has to be defined in used yaml '
                'configuration file')
        if kwargs.get('model'):
            self._model_ = DottedNameResolver().maybe_resolve(
                kwargs.get('model'))
        else:
            raise ConfigurationError(
                '"model" for source has to be defined in used yaml configuration file'
            )
Beispiel #17
0
def debug(request, registry, settings):
    """Invoke pdb breakpoint from a template.

    Example:

    .. code-block:: html+jinja

        <h1>{{ site_name }}</h1>

        {{ debug() }}

    This will invoke function from :ref:`websauna.template_debugger` setting. The debugger is turned on only on :ref:`development.ini`. If there is no debugger configured, nothing happens.
    """

    def _dummy():
        return ""

    template_debugger = settings.get("websauna.template_debugger")
    if not template_debugger:
        return _dummy()

    r = DottedNameResolver()
    debugger = r.resolve(template_debugger)

    assert debugger, "Could not find debugger in websauna.template_debugger setting: {}".format(template_debugger)

    def _inner():
        debugger()
        return ""

    return _inner
Beispiel #18
0
 def command(self):
     ini_file = self.args[-1]  # pylint: disable=E1101
     # TheLMA setup.
     config = self.__setup_thelma(ini_file)
     # Initialize the tool and run it.
     rsv = DottedNameResolver(None)
     tool_cls = rsv.resolve(self.__target_class.tool)
     arg_names = [od[1] for od in self.__target_class.option_defs]
     # Initializing lazy options. We pass the target class and the
     # options so the callback has access to them.
     opts = self.options  # pylint: disable=E1101
     for arg_name in arg_names:
         arg_value = getattr(opts, arg_name)
         if isinstance(arg_value, LazyOptionCallback):
             arg_value = arg_value.initialize(self.__target_class, opts)
             setattr(opts, arg_name, arg_value)
     # We only now do a final loop over the options so that lazy option
     # callbacks get a chance to set dependent option values.
     kw = {}
     for arg_name in arg_names:
         kw[arg_name] = getattr(opts, arg_name)
     # Remove options that are for command use only.
     for opt in self.parser.option_list:
         if opt.dest in kw and opt.pass_to_tool is False:
             del kw[opt.dest]
     tool = tool_cls(**kw)
     try:
         tool.run()
     except:
         transaction.abort()
         raise
     else:
         if tool.has_errors():
             err_msgs = tool.get_messages()
             msg = 'Errors occurred during the tool run. Error messages:\n'
             raise RuntimeError(msg + os.linesep.join(err_msgs))
         warn_msgs = tool.get_messages(logging_level=logging.WARNING)
         if warn_msgs \
            and not self.options.ignore_warnings: # pylint: disable=E1101
             msg = 'Warnings occurred during the tool run. You can ' \
                   'repeat the run with the --ignore-warnings switch ' \
                   'to force changes to be committed. Warning messages:\n'
             raise RuntimeError(msg + os.linesep.join(warn_msgs))
         try:
             # This gives the tool command a chance to perform actions after
             # the tool has run.
             self.__target_class.finalize(tool, opts)
         except:
             transaction.abort()
             raise
         else:
             # Create a report of the run.
             self.__run_report(tool)
             # All good - check if we should commit.
             if not self.options.simulate:  # pylint: disable=E1101
                 transaction.commit()
             else:
                 transaction.abort()
     config.end()
Beispiel #19
0
def add_logging(config, log_key, log_func=None):
    resolver = DottedNameResolver()
    if log_func is None:
        log_func = operator.attrgetter(log_key)
    log_func = resolver.maybe_resolve(log_func)

    config.registry[get_key("registered_loggers")][log_key] = log_func
    config.registry[get_key("order")].append(log_key)
Beispiel #20
0
 def deserialize(self, node, value):
     """Deserialize path to object."""
     if value in (colander.null, ''):
         return value
     try:
         return DottedNameResolver().resolve(value)
     except Exception as err:
         raise colander.Invalid(node, msg=str(err), value=value)
def includeme(config):
    from pyramid.path import DottedNameResolver
    accession_factory = config.registry.settings.get('accession_factory')
    if accession_factory:
        factory = DottedNameResolver().resolve(accession_factory)
    else:
        factory = prod_accession
    config.registry[ACCESSION_FACTORY] = factory
Beispiel #22
0
def get_processor_factory(settings):
    """Get processor factory from settings and return

    """
    resolver = DottedNameResolver()
    processor_factory = settings['billy.processor_factory']
    processor_factory = resolver.maybe_resolve(processor_factory)
    return processor_factory
Beispiel #23
0
def get_region(name, **settings):
    region = regions.get(name)
    if not region:
        settings_ = dict(default_settings)
        settings_.update(settings)
        region = regions[name] = build_dogpile_region_from_dict(
            DottedNameResolver().maybe_resolve, name, settings_)
    return region
Beispiel #24
0
 def colander_schema(self):
     if not self._colander_schema_runtime:
         schema = self._colander_schema
         schema = DottedNameResolver(__name__).maybe_resolve(schema)
         if callable(schema):
             schema = schema()
         self._colander_schema_runtime = schema
     return self._colander_schema_runtime
Beispiel #25
0
 def __new__(cls, namespace, base, *args, **kw):
     # Dotted name support makes it easy to configure with pyramid_multiauth
     name_resolver = DottedNameResolver(caller_package())
     base = name_resolver.maybe_resolve(base)
     # Dynamically create a subclass
     name = 'Namespaced_%s_%s' % (namespace, base.__name__)
     klass = type(name, (cls, base), {'_namespace_prefix': namespace + '.'})
     return super(NamespacedAuthenticationPolicy, klass).__new__(klass)
Beispiel #26
0
def _load_module(config, package, module):
    try:
        resolver = DottedNameResolver()
        # log.debug('{0}.{1}'.format(package, module))
        prefix = resolver.resolve('{0}.{1}:ROUTE_PREFIX'.format(
            package, module))

    except ImportError, e:
        prefix = None
def create_processor():
    """
    Creates and returns a processor based on the application configuration.
    You should use one (and only one) processor per request. Otherwise some results can be mixed or
    missing.

    Returns:
        pyramid_oereb.lib.processor.Processor: A processor.
    """

    real_estate_config = Config.get_real_estate_config()
    municipality_config = Config.get_municipality_config()
    exclusion_of_liability_config = Config.get_exclusion_of_liability_config()
    glossary_config = Config.get_glossary_config()
    extract = Config.get_extract_config()
    certification = extract.get('certification')
    certification_at_web = extract.get('certification_at_web')

    plr_cadastre_authority = Config.get_plr_cadastre_authority()

    real_estate_reader = RealEstateReader(
        real_estate_config.get('source').get('class'),
        **real_estate_config.get('source').get('params'))

    municipality_reader = MunicipalityReader(
        municipality_config.get('source').get('class'),
        **municipality_config.get('source').get('params'))

    exclusion_of_liability_reader = ExclusionOfLiabilityReader(
        exclusion_of_liability_config.get('source').get('class'),
        **exclusion_of_liability_config.get('source').get('params'))

    glossary_reader = GlossaryReader(
        glossary_config.get('source').get('class'),
        **glossary_config.get('source').get('params'))

    plr_sources = []
    for plr in Config.get('plrs'):
        plr_source_class = DottedNameResolver().maybe_resolve(
            plr.get('source').get('class'))
        plr_sources.append(plr_source_class(**plr))

    extract_reader = ExtractReader(
        plr_sources,
        plr_cadastre_authority,
        certification,
        certification_at_web,
    )

    return Processor(
        real_estate_reader=real_estate_reader,
        municipality_reader=municipality_reader,
        exclusion_of_liability_reader=exclusion_of_liability_reader,
        glossary_reader=glossary_reader,
        plr_sources=plr_sources,
        extract_reader=extract_reader,
    )
Beispiel #28
0
 def callback(self, config, target):
     view = DottedNameResolver().maybe_resolve(target)
     route_name = self.state.route_name
     # self.state.add_method(self.request_method, view)
     config.add_view(view,
                     route_name=route_name,
                     request_method=self.request_method,
                     context=self.state,
                     **self.view_arguments)
Beispiel #29
0
def ResolveName(name, base=None, raiseExcp=True):
    """
    Lookup python object by dotted python name.
    Wraps pyramid.DottedNameResolver.
    
    returns object or None
    """
    if not name:
        return None
    if not isinstance(name, basestring):
        return name
    if not base:
        base = caller_package()
    if not raiseExcp:
        d = DottedNameResolver(base)
        return d.maybe_resolve(name)
    d = DottedNameResolver(base)
    return d.resolve(name)
Beispiel #30
0
def includeme(config):
    """ Set up and configure the pypicloud app """
    config.set_root_factory(Root)
    config.include('pyramid_tm')
    config.include('pyramid_beaker')
    config.include('pyramid_duh')
    config.include('pyramid_duh.auth')
    config.include('pypicloud.auth')
    config.include('pypicloud.access')
    settings = config.get_settings()

    config.add_renderer('json', json_renderer)
    # Jinja2 configuration
    settings['jinja2.filters'] = {
        'static_url': 'pyramid_jinja2.filters:static_url_filter',
        'tojson': to_json,
    }
    settings['jinja2.directories'] = ['pypicloud:templates']
    config.include('pyramid_jinja2')

    # BEAKER CONFIGURATION
    settings.setdefault('session.type', 'cookie')
    settings.setdefault('session.httponly', 'true')
    config.set_session_factory(session_factory_from_settings(settings))

    # PYPICLOUD SETTINGS
    config.registry.fallback_url = settings.get('pypi.fallback_url',
                                                'http://pypi.python.org/simple')
    config.registry.use_fallback = asbool(settings.get('pypi.use_fallback',
                                                       True))
    realm = settings.get('pypi.realm', 'pypi')
    config.registry.realm = realm

    # CACHING DATABASE SETTINGS
    resolver = DottedNameResolver(__name__)
    dotted_cache = settings.get('pypi.db', 'sql')
    if dotted_cache == 'sql':
        dotted_cache = 'pypicloud.cache.SQLCache'
    elif dotted_cache == 'redis':
        dotted_cache = 'pypicloud.cache.RedisCache'
    cache_impl = resolver.resolve(dotted_cache)

    cache_impl.configure(config)
    cache_impl.reload_if_needed()

    config.add_request_method(cache_impl, name='db', reify=True)

    # Special request methods
    config.add_request_method(_app_url, name='app_url')
    config.add_request_method(lambda x: __version__, name='pypicloud_version',
                              reify=True)

    cache_max_age = int(settings.get('pyramid.cache_max_age', 3600))
    config.add_static_view(name='static/%s' % __version__,
                           path='pypicloud:static',
                           cache_max_age=cache_max_age)