On Tue, Oct 30, 2012 at 1:17 PM, Jonathan Vanasco <
jona...@findmeon.com> wrote:
> With that, combined with the best-practice of passing the Request
> object around during the request lifecycle, I wanted to suggest
> creating a 'project' and 'plugin' namespace under request , so that
> (moving forward) as people develop plugins or write app specific
> request attributes there is no issue for collision against each other
> or future Pyramid releases.
>
> - i fear namespace collision.
No doubt this is a concern. Fortunately request properties do fall
under Pyramid's conflict resolution mechanism. A good convention is
already possible by creating an object on request that exposes your
methods.
class RequestExtensions(object):
def __init__(self, request):
self.request = request
@reify
def some_cached_property(self):
return 'foo'
def some_method(self, **kw):
return 'bar'
config.add_request_method(RequestExtensions, 'myplugin', reify=True)
will allow
request.myplugin.some_api
request.myplugin.some_method()
I'm not sure Pyramid needs any sugar over top of this pattern.