limited python virtual machine
Steven Bethard
steven.bethard at gmail.com
Fri Jan 28 20:37:49 EST 2005
Alex Martelli wrote:
> Steven Bethard <steven.bethard at gmail.com> wrote:
> ...
>
>>If I could see how to go from 'object' (or 'int', 'str', 'file', etc.)
>>to 'eval' or '__import__', that would help out a lot...
>
>
>>>>object.__subclasses__()
>
> [<type 'type'>, <type 'weakref'>, <type 'int'>, <type 'basestring'>,
> <type 'list'>, <type 'NoneType'>, <type 'NotImplementedType'>, <type
> 'module'>, <type 'zipimport.zipimporter'>, <type 'posix.stat_result'>,
> <type 'posix.statvfs_result'>, <type 'dict'>, <type 'function'>, <class
> 'site._Printer'>, <class 'site._Helper'>, <type 'set'>, <type 'file'>]
>
> Traipse through these, find one class that has an unbound method, get
> that unbound method's func_globals, bingo.
Thanks for the help! I'd played around with object.__subclasses__ for
a while, but I hadn't realized that func_globals was what I should be
looking for.
Here's one route to __builtins__:
py> string_Template = object.__subclasses__()[17]
py> builtins = string_Template.substitute.func_globals['__builtins__']
py> builtins['eval']
<built-in function eval>
py> builtins['__import__']
<built-in function __import__>
Steve
More information about the Python-list
mailing list