Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60365

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

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!feeder2-2.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.022
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'args': 0.07; 'http': 0.09; 'override': 0.09; 'params': 0.09; 'subject:()': 0.09; 'def': 0.12; '24,': 0.16; 'evaluates': 0.16; 'executed.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'get,': 0.16; 'inclined': 0.16; 'wrote:': 0.18; 'work,': 0.20; 'this:': 0.26; 'post': 0.26; 'skip:" 20': 0.27; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; '(maybe': 0.31; 'marc': 0.31; 'request,': 0.31; 'call.': 0.33; 'proceed': 0.33; 'skip:_ 10': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'done': 0.36; 'doing': 0.36; 'method': 0.36; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'then,': 0.60; 'conversion': 0.61; 'simply': 0.61; 'first': 0.61; 'request.': 0.70; 'unusual': 0.74; 'subject:skip:o 10': 0.84; 'difficult,': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=2NcZhbwLoNUIQ42/gitxw1UlnFndr16NVA7WQonNioo=; b=bGq0S9XjIsnbIL1a2gKqfycgzYbRFaqI3iFEm6rSdZmqczlBcQYGf/h0LrnT24680e Otysvd4Ax/HCRQqeYIeOLbC514WvivdVuZ+vXUhLj0iwyRtrS8Ozd89o0lgrC/HAZUbq h139fN7D1OSDIivPmUJCBT5lH66FOdMritLCj2dOHxRNWjfU0B0yYep3u+p9rljhXXar edrH4+lMHvuOohmGx7eiQLfAgWD6zoiXeFifBxfvXLwKckfgQqR21j6cUWfEahnE+GqG plsF4ITd1kOwT4SCOcF0YjfcedRgkcW5YoHUVa7jKkqh7EVnpcwYmlfcoAgygSvZSxOF wsTw==
MIME-Version 1.0
X-Received by 10.66.139.100 with SMTP id qx4mr1002411pab.141.1385298350774; Sun, 24 Nov 2013 05:05:50 -0800 (PST)
In-Reply-To <CA+DCN_uqn5OukuZ5QWWjJCUTksaFw50L03ZU7uqdm4a6ZOn7CA@mail.gmail.com>
References <CA+DCN_uqn5OukuZ5QWWjJCUTksaFw50L03ZU7uqdm4a6ZOn7CA@mail.gmail.com>
Date Mon, 25 Nov 2013 00:05:50 +1100
Subject Re: Implement logic on object.attribute and object.attribute()
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3129.1385298360.18130.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385298360 news.xs4all.nl 15917 [2001:888:2000:d::a6]:50447
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60365

Show key headers only | View raw


On Sun, Nov 24, 2013 at 11:52 PM, Marc Aymerich <glicerinu@gmail.com> 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
evaluates object.attribute, then calls it. The only way you can have
that work, then, is if you have one version (calling it) do the POST
call, and something else (maybe conversion to str?) do the GET call.
But it's not going to be easy. I would recommend having both of them
done with a call; since a POST request will almost always include a
request body and a GET request almost never, I would be inclined to a
model like this:

def __call__(self, METHOD=None, **params):
    METHOD = method or ('POST' if params else 'GET')
    # proceed to use the given method

This way, you simply call it with no args for a GET, or with form
fill-out args for POST, and you can override if you want to (eg for a
PUT request, or doing something unusual like POST without data).

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Implement logic on object.attribute and object.attribute() Chris Angelico <rosuav@gmail.com> - 2013-11-25 00:05 +1100

csiph-web