Re: decorator to fetch arguments from global objects

2013-06-19 Thread Terry Reedy
On 6/19/2013 4:03 AM, Wolfgang Maier wrote: Wolfgang Maier biologie.uni-freiburg.de> writes: andrea crotti gmail.com> writes: 2013/6/18 Terry Reedy udel.edu> Decorators are only worthwhile if used repeatedly. What you specified can easily be written, for instance, as def save_doc(db=No

Re: decorator to fetch arguments from global objects

2013-06-19 Thread Wolfgang Maier
Wolfgang Maier biologie.uni-freiburg.de> writes: > > andrea crotti gmail.com> writes: > > > 2013/6/18 Terry Reedy udel.edu> > > > > Decorators are only worthwhile if used repeatedly. What you specified can > easily be written, for instance, as > > def save_doc(db=None): > >   if db is None:

Re: decorator to fetch arguments from global objects

2013-06-19 Thread Wolfgang Maier
andrea crotti gmail.com> writes: > > 2013/6/18 Terry Reedy udel.edu> > On 6/18/2013 5:47 AM, andrea crotti wrote: > Using a CouchDB server we have a different database object potentially > for every request. > We already set that db in the request object to make it easy to pass it > around for

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Steven D'Aprano
On Tue, 18 Jun 2013 10:47:57 +0100, andrea crotti wrote: > Using a CouchDB server we have a different database object potentially > for every request. > > We already set that db in the request object to make it easy to pass it > around form our django app, however it would be nice if I could set

Re: decorator to fetch arguments from global objects

2013-06-18 Thread andrea crotti
2013/6/18 Terry Reedy > On 6/18/2013 5:47 AM, andrea crotti wrote: > >> Using a CouchDB server we have a different database object potentially >> for every request. >> >> We already set that db in the request object to make it easy to pass it >> around form our django app, however it would be nic

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Terry Reedy
On 6/18/2013 5:47 AM, andrea crotti wrote: Using a CouchDB server we have a different database object potentially for every request. We already set that db in the request object to make it easy to pass it around form our django app, however it would be nice if I could set it once in the API and

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Wolfgang Maier
andrea crotti gmail.com> writes: > > 2013/6/18 Wolfgang Maier biologie.uni-freiburg.de> > > > andrea crotti gmail.com> writes: > > > > > > Using a CouchDB server we have a different database object potentially for > every request. > > > > We already set that db in the request object to make

Re: decorator to fetch arguments from global objects

2013-06-18 Thread andrea crotti
2013/6/18 Wolfgang Maier > andrea crotti gmail.com> writes: > > > > > > > Using a CouchDB server we have a different database object potentially > for > every request. > > > > We already set that db in the request object to make it easy to pass it > around form our django app, however it would b

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Wolfgang Maier
andrea crotti gmail.com> writes: > > > Using a CouchDB server we have a different database object potentially for every request. > > We already set that db in the request object to make it easy to pass it around form our django app, however it would be nice if I could set it once in the API an

Re: decorator to fetch arguments from global objects

2013-06-18 Thread Fábio Santos
On Tue, Jun 18, 2013 at 10:47 AM, andrea crotti wrote: > def with_optional_db(func): > """Decorator that sets the database to the global current one if > not passed in or if passed in and None > """ > @wraps(func) > def _with_optional_db(*args, **kwargs): > func_args = func.func_code.co_varnames >

decorator to fetch arguments from global objects

2013-06-18 Thread andrea crotti
Using a CouchDB server we have a different database object potentially for every request. We already set that db in the request object to make it easy to pass it around form our django app, however it would be nice if I could set it once in the API and automatically fetch it from there. Basically