configuration and registries

40 views
Skip to first unread message

Chris Withers

unread,
Mar 30, 2012, 4:09:28 AM3/30/12
to pylons-...@googlegroups.com
Hi All,

So, when setting up a Pyramid app we instantiate a Configurator.
One we're handling requests, we have a registry.

If I have some arbitrary config read from a file at the same time as I'm
instantiating the Configurator, where should I put it?
(thinks of these as application globals, etc)

Is the configurator instance available when handling requests? If so,
what's the correct API?

Can the registry be used for simple key value pairs or is it only for
component registrations?

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

Chris McDonough

unread,
Mar 30, 2012, 5:28:35 AM3/30/12
to pylons-...@googlegroups.com
On Fri, 2012-03-30 at 09:09 +0100, Chris Withers wrote:
> Hi All,
>
> So, when setting up a Pyramid app we instantiate a Configurator.
> One we're handling requests, we have a registry.
>
> If I have some arbitrary config read from a file at the same time as I'm
> instantiating the Configurator, where should I put it?
> (thinks of these as application globals, etc)
>
> Is the configurator instance available when handling requests? If so,
> what's the correct API?

The configurator is a mostly-stateless wrapper for the registry. You
can recreate *a* configurator via:

config = Configurator(registry=request.registry)

But it's not really possible to store data on "the" configurator because
it's thrown out after startup-time configuration.

You'll want to store state on (or in) the registry instead.

> Can the registry be used for simple key value pairs or is it only for
> component registrations?

pyramid.registry.Registry (the default registry type) indeed supports
registry['foo'] = 'bar'. You can also just do registry.foo = 'bar'.
We're all adults here ;)

- C


Wyatt Baldwin

unread,
Mar 30, 2012, 10:11:00 AM3/30/12
to pylons-...@googlegroups.com
So, is it *better* to store application globals (e.g., a database session factory) in the registry or in registry.settings? Using the registry directly makes more sense to me, but I don't think I've seen this recommended anywhere.

Chris McDonough

unread,
Mar 30, 2012, 12:50:50 PM3/30/12
to pylons-...@googlegroups.com

Really doesn't matter. If you ever intend to use a "bare" ZCA registry
(e.g. you want to share a registry with like Zope or something), it
doesn't have __getitem__ or __setitem__, but if you never intend to use
one, it's fine to use these.

- C


>
>
> --
> You received this message because you are subscribed to the Google
> Groups "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/lYZ6TaMXlIMJ.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discuss
> +unsub...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.


Reply all
Reply to author
Forward
0 new messages