On 28/10/2006, at 10:01 PM, Dan Eloff wrote:

On 10/28/06, Graham Dumpleton <[EMAIL PROTECTED]> wrote:
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?

Using the test function:

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

<function __auth__ at 0x01159830>

I am curious as to the hasattr(__auth__, 'co_name') section. Is there
any case where this is not true? (and does it make sense to say
found_auth = 1 if it isn't?)

The co_name check is making sure it is a code object as opposed to a
dictionary or some other constant.



for what __auth__ can be.


Reply via email to