Apache Mod-Python - Resolved: (MODPYTHON-198) Python 2.5 nested auth functions

This is Interesting: Free IT Magazines  
Home > Archive > Apache Mod-Python > November 2006 > Resolved: (MODPYTHON-198) Python 2.5 nested auth functions





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Resolved: (MODPYTHON-198) Python 2.5 nested auth functions
Graham Dumpleton (JIRA)

2006-11-05, 1:12 am

[ http://issues.apache.org/jira/brows...ON-198?page=all ]

Graham Dumpleton resolved MODPYTHON-198.
----------------------------------------

Resolution: Fixed

Looks like JIRA is not showing subversion commits or has not recorded some from when they were doing their infrastructure update. Is fixed though. Ended up using:

func_code = func_object.func_code
func_globals = func_object.func_globals

def lookup(name):
i = None
if name in func_code.co_names:
i = list(func_code.co_names).index(name)
elif func_code.co_argcount < len(func_code.co_varnames):
names = func_code.co_varnames[func_code.co_argcount:]
if name in names:
i = list(names).index(name)
if i is not None:
return (1, func_code.co_consts[i+1])
return (0, None)

(found_auth, __auth__) = lookup('__auth__')
if found_auth and type(__auth__) == types.CodeType:
__auth__ = new.function(__auth__, func_globals)

(found_access, __access__) = lookup('__access__')
if found_access and type(__access__) == types.CodeType:
__access__ = new.function(__access__, func_globals)

(found_realm, __auth_realm__) = lookup('__auth_realm__')
if found_realm:
realm = __auth_realm__

Ie., look in co_names first as co_varnames wasn't ordered correctly for older versions of Python.

> Python 2.5 nested auth functions in publisher.
> ----------------------------------------------
>
> Key: MODPYTHON-198
> URL: http://issues.apache.org/jira/browse/MODPYTHON-198
> Project: mod_python
> Issue Type: Bug
> Components: publisher
> Affects Versions: 3.2.10
> Reporter: Graham Dumpleton
> Assigned To: Graham Dumpleton
> Fix For: 3.3
>
>
> Jim Gallacher wrote:
> With Python 2.5 I get 2 failures:
> test_publisher_auth_nested
> test_publisher_auth_method_nested
> It looks like something has changed in Python 2.5 introspection that is
> messing up publisher.
> Test script testme.py
> ---------------------
> def testfunc():
> print 'stuff'
> def __auth__():
> print '__auth__ called'
> def __access__():
> print '__access__ called'
> def main():
> func_obj = testfunc
> func_code = func_obj.func_code
> print func_code.co_names
> if __name__ == '__main__':
> main()
> Results
> -------
> $ python2.3 testme.py
> ('__auth__', '__access__')
> $ python2.4 testme.py
> ('__auth__', '__access__')
> $ python2.5 testme.py
> ()
> Dan Eloff points out that information is now in co_varnames.
> ()
> ('__auth__', '__access__')
> d = 5
> def bar(c):
> return c
> ()
> ('a', 'b', 'd', 'bar')
> To get just args, try:
> ('a', 'b')
> And for just local vars:
> ('d', 'bar')
> Still need to work out if actual code objects for the functions are available in co_consts or not. Ie., need to replace:
> 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


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com