
|
If you were logged in you would be able to see more operations.
|
|
|
| Resolution Date: |
05/Nov/06 06:07 AM
|
|
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
|
|
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
|
Show » |
|
>>> def foo(a,b):
d = 5
def __auth__(req):
return True
e = d + 5
>>> fc = foo.func_code
>>> import new
>>> func_globals = globals()
>>> for i, var_name in enumerate(fc.co_varnames):
if var_name == '__auth__':
__auth__ = fc.co_consts[i-fc.co_argcount+1]
if hasattr(__auth__, 'co_name'):
__auth__ = new.function(__auth__, func_globals)
found_auth = 1
break
>>> __auth__
<function __auth__ at 0x01159830>
would appear to work.
In practice need to support old and new versions of Python, so will need to check both co_names and co_varnames.