quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Graham Dumpleton <grah...@dscpl.com.au>
Subject Re: Python 2.5 nested auth functions in publisher.
Date Sat, 28 Oct 2006 07:47:38 GMT

On 27/10/2006, at 11:03 PM, Dan Eloff wrote:

> On 10/27/06, Graham Dumpleton <grahamd@dscpl.com.au> wrote:
>> Unless they have really screwed things around, co_varnames is
>> specifically
>> for function argument names and is unlikely to contained nested  
>> constant
>> names. If it did, then I would expect a lot of the publisher code to
>> break in
>> other ways as it uses co_varnames for the very specific purpose of
>> matching
>> form parameters against function arguments.
>
> I'd look into that code then.
>
>>>> fc.co_names
> ()
>>>> fc.co_varnames
> ('__auth__', '__access__')
>
>>>> def foo(a,b):
> 	d = 5
> 	def bar(c):
> 		return c
>
>>>> fc.co_names
> ()
>>>> fc.co_varnames
> ('a', 'b', 'd', 'bar')
>
> To get just args, try:
>
>>>> fc.co_varnames[:fc.co_argcount]
> ('a', 'b')
>
> And for just local vars:
>
>>>> fc.co_varnames[fc.co_argcount:]
> ('d', 'bar')

Dan, the code that needs to be updated is:

         if "__auth__" in func_code.co_names:
             i = list(func_code.co_names).index("__auth__")
             __auth__ = func_code.co_consts[i+1]
             if hasattr(__auth__, "co_name"):
                 __auth__ = new.function(__auth__, func_globals)
             found_auth = 1

Note how it accesses code objects for functions from co_consts. Do  
they still appear
to be there in Python 2.5? Are you able to work out some code that  
does the same
thing as this?

Graham

Mime
View raw message