Sorry, I should have emphasized the key difference in the code: def _q_index(self, request): # When called or indexed, we flush the args # after getting a copy of them ---> args = self.args[:] ---> self.args = [] ---> return self.handler(request, args) I think this will give you what you describe, because at the end of each request, the instances .args attribute will get reset. I still maintain that it's probably not too difficult to break :) Does this address your concern, or am I overlooking something else? Jason > -----Original Message----- > From: quixote-users-bounces+jsibre=chironsys.com@mems-exchange.org > [mailto:quixote-users-bounces+jsibre=chironsys.com@mems-exchange.org]On > Behalf Of Daniel Potter (Ars Analytica) > Sent: Friday, March 12, 2004 12:31 PM > To: Quixote-users@mems-exchange.org > Subject: RE: [Quixote-users] _q_exports and class instances > > > > --- "Jason E. Sibre"wrote: > > Daniel, > > > > I'm not sure why you're avoiding the use of > > _q_lookup, because it's just > > about a perfect fit for the job, but I'll assume > > there's something going on > > in your particular situation that I am unaware of > > that makes it unpalatable. > > > > With that in mind, the next idea I come up with a > > bit of an ugly hack, > > but.... > > Ex. > > > > _q_exports = ['tailtest'] > > tailtest = taileater.TailEater(taileater.test, > > 'tailtest'); > > > > class TailEater: > > _q_exports = [] > > > > def __init__(self, handler, first_component): > > self.handler = handler > > self.args = [first_component] > > > > def _q_index(self, request): > > # When called or indexed, we flush the args > > # after getting a copy of them > > args = self.args[:] > > self.args = [] > > return self.handler(request, args) > > > > __call__ = _q_index > > > > def _q_lookup(self, request, component): > > self.args.append(component) > > return self > > > > -------------------------------- > > This really is ugly, but it would work... Most of > > the time anyway. I > > wouldn't be too surprised if someone figured out a > > way to break it. > > Personally? I would just use _q_lookup instead, > > returning a fresh instance > > each time. That's what it's there for. > > > > Jason > > Hi Jason, > Thanks for the reply. > > Your solution matches the one I was trying to get work > (unless there something subtle here I don't see). The > problems is that it only runs the TailEater _init_ > code when the module is loaded (i.e. not every time > the /tailtest/x/x/x path is traversed). This is fine > under straight CGI but bad when using something like > SCGI where things aren't reloaded upon every request. > > > > > -----Original Message----- > > > From: > > > quixote-users-bounces+jsibre=chironsys.com@mems-exchange.org > > > > > > [mailto:quixote-users-bounces+jsibre=chironsys.com@mems-exchange.org]On > > > Behalf Of Daniel Potter (Ars Analytica) > > > Sent: Friday, March 12, 2004 10:00 AM > > > To: Quixote-users@mems-exchange.org > > > Subject: [Quixote-users] _q_exports and class > > instances > > > > > > > > > Hello, > > > I'd like to use a python class instances in > > _q_exports > > > but can't figure out how to do the class _init_ at > > the > > > appropriate times. > > > > > > Basically I want something like > > > > > > _q_exports = ['someclassinstance'] > > > someclassinstance = someclass('foo') > > > > > > But where someclassinstance.__init__(self, 'foo') > > is > > > run each time someclassinstance is accessed. In > > the > > > code fragment above someclass._init('foo') is only > > run > > > once at startup / module import. > > > > > > The common approach seems to be to *not* use > > > _q_exports but rather to use _q_lookup to return a > > > fresh someclass instance. > > > > > > Another approach is to make someclassinstance > > global > > > and put the initialization in _q_access but this > > is a > > > hack because 'someclassinstance' may not be > > accessed - > > > so why go ahead and initialize it. > > > > > > What I am hoping for is some function or class F > > > such that > > > > > > _q_exports = ['someclassinstance'] > > > someclassinstance = F(someclass('foo')) > > > > > > Will ensure someclass.init(self,'foo') gets called > > > every time 'someclassinstance' gets traversed. > > > > > > Below is the actual code I am trying to get > > working. > > > The problem with it is that tailtest.__init__ is > > > called only once when the module is loaded, so > > hitting > > > reload on /tailtest/x keeps appending data to > > > self.args > > > > > > Thanks, > > > Dan > > > > > > > > > # basemodule.py # > > > import taileater > > > > > > _q_exports = ['tailtest'] > > > > > > tailtest = taileater.TailEater(taileater.test, > > > 'tailtest'); > > > > > > > > > > > > # taileater.py # > > > # use: from taileater import tailtest > > > # _q_exports = ['tailtest'] > > > > > > class TailEater: > > > _q_exports = [] > > > > > > def __init__(self, handler, first_component): > > > self.handler = handler > > > self.args = [first_component] > > > print "Init: TailEater" > > > > > > def _q_index(self, request): > > > return self.handler(request, self.args) > > > > > > __call__ = _q_index > > > > > > def _q_lookup(self, request, component): > > > self.args.append(component) > > > return self > > > > > > > > > def test [html] (request,c): > > > c > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > Quixote-users mailing list > > > Quixote-users@mems-exchange.org > > > > > > http://mail.mems-exchange.org/mailman/listinfo/quixote-users > > > > > > > > > > _______________________________________________ > Quixote-users mailing list > Quixote-users@mems-exchange.org > http://mail.mems-exchange.org/mailman/listinfo/quixote-users >