Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60363
| From | Marc Aymerich <glicerinu@gmail.com> |
|---|---|
| Date | 2013-11-24 13:52 +0100 |
| Subject | Implement logic on object.attribute and object.attribute() |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3127.1385297594.18130.python-list@python.org> (permalink) |
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 classes like this:
class HTTPAttribute(object):
def __init__(self, name):
self.name = name
def __call__(self, *args, **kwargs):
url = BASE_URL + self.name
requests.post(url, *args, **kwargs)
class HTTPObject(object):
def __getattr__(self, name):
return HTTPAttribute(name)
But I'm stuck implementing the HTTP GET request when accessing
"object.attribute", Any idea ??
Thanks!!
--
Marc
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Implement logic on object.attribute and object.attribute() Marc Aymerich <glicerinu@gmail.com> - 2013-11-24 13:52 +0100
csiph-web