Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Steven D'Aprano
On Mon, 25 Nov 2013 01:37:12 +1100, Chris Angelico wrote: > class Magic_HTTP_Thing: > @property > def attribute(self): > result = CallableString(self.do_get()) > result.function = lambda: self.do_put() > return result > def do_get(self): > # Do a HTTP GE

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Chris Angelico
On Mon, Nov 25, 2013 at 1:48 AM, Marc Aymerich wrote: > But still I'll reconsider an interface with less magic :P Yeah, I would definitely recommend that :) Magic can be fun sometimes, but it's often not worth the hassle. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Marc Aymerich
On Sun, Nov 24, 2013 at 3:37 PM, Chris Angelico wrote: > On Mon, Nov 25, 2013 at 1:16 AM, Marc Aymerich wrote: >> ... def do_get(self): >> ... # Do a HTTP GET request. >> ... return "Get stuff" >> ... def do_put(self): >> ... # Do a HTTP PUT request. >> ...

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Marc Aymerich
On Sun, Nov 24, 2013 at 3:13 PM, Chris Angelico wrote: > On Mon, Nov 25, 2013 at 12:45 AM, Steven D'Aprano > wrote: >> Not quite impossible. All you need is an object that behaves like a >> string, except it has a __call__ method. Here's a sketch of a solution, >> completely untested. >> >> class

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Chris Angelico
On Mon, Nov 25, 2013 at 1:16 AM, Marc Aymerich wrote: > ... def do_get(self): > ... # Do a HTTP GET request. > ... return "Get stuff" > ... def do_put(self): > ... # Do a HTTP PUT request. > ... return "Put stuff" To make this a bit more realistic, try this

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Chris Angelico
On Mon, Nov 25, 2013 at 1:21 AM, Roy Smith wrote: > If the REST interface is designed properly, all the GETs are > nullipotent, so modulo efficiency, it should all work. Yes, but "modulo efficiency" is not something you want to do when you're talking network traffic. If this were just allocating

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Roy Smith
In article , Chris Angelico wrote: > On Mon, Nov 25, 2013 at 12:45 AM, Steven D'Aprano > wrote: > > Not quite impossible. All you need is an object that behaves like a > > string, except it has a __call__ method. Here's a sketch of a solution, > > completely untested. > > > > class Magic_HTTP_T

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Marc Aymerich
On Sun, Nov 24, 2013 at 2:45 PM, Steven D'Aprano wrote: > On Sun, 24 Nov 2013 05:04:16 -0800, Devin Jeanpierre wrote: > >> On Sun, Nov 24, 2013 at 4:52 AM, Marc Aymerich >> wrote: >>> Hi, >>> I'm playing with python internals to make objects behave like this: >>> >>> if I access to "object.attrib

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Chris Angelico
On Mon, Nov 25, 2013 at 1:04 AM, Devin Jeanpierre wrote: > and also "impossible" is often a nice shorthand for "the > possibility is extraordinarily awful". +1 QOTW! ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Chris Angelico
On Mon, Nov 25, 2013 at 12:45 AM, Steven D'Aprano wrote: > Not quite impossible. All you need is an object that behaves like a > string, except it has a __call__ method. Here's a sketch of a solution, > completely untested. > > class Magic_HTTP_Thing: > @property > def attribute(self): >

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Devin Jeanpierre
On Sun, Nov 24, 2013 at 5:45 AM, Steven D'Aprano wrote: > On Sun, 24 Nov 2013 05:04:16 -0800, Devin Jeanpierre wrote: >> Uh oh. What you want is impossible. You cannot call an attribute without >> first accessing it. :( > > Not quite impossible. All you need is an object that behaves like a > stri

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Steven D'Aprano
On Sun, 24 Nov 2013 05:04:16 -0800, Devin Jeanpierre wrote: > On Sun, Nov 24, 2013 at 4:52 AM, Marc Aymerich > wrote: >> Hi, >> I'm playing with python internals to make objects behave like this: >> >> if I access to "object.attribute" I want to return the result of an >> HTTP GET request. Howeve

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Chris Angelico
On Sun, Nov 24, 2013 at 11:52 PM, Marc Aymerich wrote: > if I access to "object.attribute" I want to return the result of an > HTTP GET request. However if i call "object.attribute()" I want an > HTTP POST request to be executed. That's fundamentally difficult, because object.attribute() first ev

Re: Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Devin Jeanpierre
On Sun, Nov 24, 2013 at 4:52 AM, Marc Aymerich wrote: > Hi, > I'm playing with python internals to make objects behave like this: > > if I access to "object.attribute" I want to return the result of an > HTTP GET request. However if i call "object.attribute()" I want an > HTTP POST request to be e

Implement logic on object.attribute and object.attribute()

2013-11-24 Thread Marc Aymerich
Hi, I'm playing with python internals to make objects behave like this: if I access to "object.attribute" I want to return the result of an HTTP GET request. However if i call "object.attribute()" I want an HTTP POST request to be executed. So far I have been able to do the POST part, using two c