[IronPython] Callstack inspection

Dino Viehland dinov at exchange.microsoft.com
Wed Aug 16 00:58:27 CEST 2006


It's most likely that inspect won't work.  But we certainly don't implement sys._getframe which will be necessary to crawl the stack.  In the future we're going to look at both what we can do from our side and what could be done from the CLR side to make it easier to implement this feature - in other words this may be one of those features it takes us a while to get to.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Gary Stephenson
Sent: Tuesday, August 15, 2006 3:51 PM
To: Discussion of IronPython
Subject: [IronPython] Callstack inspection

I would like to adapt the following code to IronPython, but there appears to be no inspect module available.

Any clues on how I might proceed?

many tias,

gary

# code begins
# a hack to support something like dynamically scoped variables

import inspect

class _gsDynamicVars( object ):

    def __init__( self ):
        self._publics = {}

    def setPublic( self, nm, x = None ):
        self._publics[nm] = x

    def __getattribute__( self, nm ):
        for f in inspect.stack():
            if f[0].f_locals.has_key( '_privates' ):
                if f[0].f_locals[ '_privates' ].has_key( nm ):
                    return f[0].f_locals['_privates'][nm]
        return self._publics.get(nm)

    def __setattr__( self, nm, x = None ):
        for f in inspect.stack():
            if f[0].f_locals.has_key( '_privates' ) :
                if f[0].f_locals[ '_privates' ].has_key( nm ) :
                    f[0].f_locals['_privates'][nm] = x
                    return x
        if self._publics.has_key( nm ) :
            self._publics[nm] = x
        raise NameError


_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list