Logged In: YES user_id=31435 I'm also missing the connection to restricted environments. If you want to capture dis output (or output from anything else that uses print), the usual way to do it is to assign a StringIO instance (or other file-like object) to sys.stdout before invoking dis.
Logged In: YES user_id=55188 Yes. To disallow BINARY_POWER and INPLACE_POWER, I'm hooking sys.stdout now. But, because it isn't thread-safe way, I needed to lock threads whenever I print something to stdout. To make a cheaper solution, I like this patch.
Logged In: YES user_id=21627 So you want to find out whether BINARY_POWER is in the byte code? If so, I suggest that usage of dis.disassemble is inadequate. Instead, you should just copy the essential part of the disassemble loop, and look for an opcode for which dis.opname[opcode] is 'BINARY_POWER'. This will be much faster, and thread-safe.