Description
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.
>>> 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')
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