Message from discussion
view-callable class - request arg receives context object
Received: by 10.236.126.243 with SMTP id b79mr25022336yhi.35.1351705170853;
Wed, 31 Oct 2012 10:39:30 -0700 (PDT)
X-BeenThere: pylons-discuss@googlegroups.com
Received: by 10.236.92.236 with SMTP id j72ls2765649yhf.1.gmail; Wed, 31 Oct
2012 10:39:26 -0700 (PDT)
Received: by 10.236.149.33 with SMTP id w21mr27428640yhj.33.1351705166739;
Wed, 31 Oct 2012 10:39:26 -0700 (PDT)
Received: by 10.236.149.33 with SMTP id w21mr27428639yhj.33.1351705166725;
Wed, 31 Oct 2012 10:39:26 -0700 (PDT)
Return-Path: <simonya...@me.com>
Received: from st11p02mm-asmtp003.mac.com (st11p02mm-asmtp003.mac.com. [17.172.220.238])
by gmr-mx.google.com with ESMTP id h50si303056yhi.3.2012.10.31.10.39.26;
Wed, 31 Oct 2012 10:39:26 -0700 (PDT)
Received-SPF: pass (google.com: domain of simonya...@me.com designates 17.172.220.238 as permitted sender) client-ip=17.172.220.238;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of simonya...@me.com designates 17.172.220.238 as permitted sender) smtp.mail=simonya...@me.com
MIME-version: 1.0
Content-transfer-encoding: 7BIT
Content-type: text/plain; CHARSET=US-ASCII
Received: from [192.168.0.5] ([82.9.150.152]) by st11p02mm-asmtp003.mac.com
(Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Jan
3 2012)) with ESMTPSA id <0MCR00MW0QD7P...@st11p02mm-asmtp003.mac.com> for
pylons-discuss@googlegroups.com; Wed, 31 Oct 2012 17:39:10 +0000 (GMT)
X-Proofpoint-Virus-Version: vendor=fsecure
engine=2.50.10432:5.7.7855,1.0.431,0.0.0000
definitions=2012-10-31_03:2012-10-31,2012-10-31,1970-01-01 signatures=0
X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0
ipscore=0 suspectscore=4 phishscore=0 bulkscore=0 adultscore=0 classifier=spam
adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001
definitions=main-1210310178
Subject: Re: view-callable class - request arg receives context object
From: Simon Yarde <simonya...@me.com>
In-reply-to: <CAKdhhwH1WQW7sL+WX8rgppN1BXDY=RzYbMpV0UiJ+X9_97t+Hw@mail.gmail.com>
Date: Wed, 31 Oct 2012 17:26:34 +0000
Message-id: <D6752DAC-C23D-40E3-A8DB-7B75F06C1...@me.com>
References: <149A7788-B848-48A5-A95A-E920F7CC6...@me.com>
<CAKdhhwF+_thmF_A4cOY656hch3juqhR1ku2UucdZe2d1wxa...@mail.gmail.com>
<7225d81c-08ba-43e9-b125-3021ca2e1100@googlegroups.com>
<CAKdhhwH1WQW7sL+WX8rgppN1BXDY=RzYbMpV0UiJ+X9_97t...@mail.gmail.com>
To: pylons-discuss@googlegroups.com
X-Mailer: Apple Mail (2.1283)
Understood - thanks for clarifying. Best, S
On 31 Oct 2012, at 17:12, Michael Merickel wrote:
> No, it's correct. As I said it uses introspection to see what args are
> there. If your function takes 1 arg, it will be the request. If it
> takes 2 or more args the first two will be context and request in that
> order. You need to be aware of this if you try to do (request, *args)
> because the first arg will be context and args[0] will be request.
>
> On Wed, Oct 31, 2012 at 12:07 PM, Simon <simonya...@me.com> wrote:
>> Thanks Michael
>>
>> Is the example below given in #defining-a-view-callable-as-a-class
>> incorrect?
>>
>> I.e. ``request`` is a context-object because it is the first-position arg.
>>
>>
>> from pyramid.response import Response
>>
>> class MyView(object):
>> def __init__(self, request):
>> self.request = request
>>
>> def __call__(self):
>> return Response('hello')
>>
>>
>>
>> On Wednesday, October 31, 2012 4:07:42 PM UTC, Michael Merickel wrote:
>>>
>>> They are called positionally via introspection and not by name. The
>>> calling convention is here:
>>>
>>>
>>> http://pyramid.readthedocs.org/en/latest/narr/views.html#alternate-view-callable-argument-calling-conventions
>>>
>>> On Wed, Oct 31, 2012 at 11:02 AM, Simon Yarde <simon...@me.com> wrote:
>>>>
>>>> Docs say you should expect to handle a request argument in a
>>>> view-callable class.
>>>>
>>>>
>>>> http://pyramid.readthedocs.org/en/latest/narr/views.html#defining-a-view-callable-as-a-class
>>>>
>>>> But I found I was getting a context object for the request arg.
>>>>
>>>> Does this mean context and request are being passed (in that order) as
>>>> positional args, rather can keywords?
>>>>
>>>> I know I can just reverse the order so context is first - just asking if
>>>> there is anything wrong with below code that would cause this, or this is
>>>> view-callables are called this way for any reason?
>>>>
>>>>
>>>> class SomeView():
>>>> """
>>>> """
>>>> def __init__(self,
>>>> request, # called positionally?
>>>> context, # ..
>>>> *args,
>>>> **kwargs
>>>> ):
>>>> print('"request" is {0}'.format(request.__class__))
>>>> print('"context" is {0}'.format(context.__class__))
>>>>
>>>>
>>>> "request" is <class 'pyramid.traversal.DefaultRootFactory'>
>>>> "context" is <class 'pyramid.util.Request'>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "pylons-discuss" group.
>>>> To post to this group, send email to pylons-...@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> pylons-discus...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/pylons-discuss?hl=en.
>>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pylons-discuss" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/pylons-discuss/-/XfRjxah4XjcJ.
>>
>> To post to this group, send email to pylons-discuss@googlegroups.com.
>> To unsubscribe from this group, send email to
>> pylons-discuss+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/pylons-discuss?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
>