[Patches] [ python-Patches-637906 ] Allow any file-like object on dis module

noreply@sourceforge.net noreply@sourceforge.net
Sun, 17 Nov 2002 21:02:15 -0800


Patches item #637906, was opened at 2002-11-14 03:24
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=637906&group_id=5470

Category: Library (Lib)
Group: Python 2.3
>Status: Closed
Resolution: None
Priority: 5
Submitted By: Hye-Shik Chang (perky)
Assigned to: Nobody/Anonymous (nobody)
Summary: Allow any file-like object on dis module

Initial Comment:
This was useful for me to make a restricted environment
by disallowing specific opcodes.


----------------------------------------------------------------------

>Comment By: Hye-Shik Chang (perky)
Date: 2002-11-18 14:02

Message:
Logged In: YES 
user_id=55188

Ah. Thank you for your comments. It looks much better than
parsing dis's output.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-11-15 05:17

Message:
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.

----------------------------------------------------------------------

Comment By: Hye-Shik Chang (perky)
Date: 2002-11-15 03:07

Message:
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.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-11-15 01:56

Message:
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.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-11-14 08:46

Message:
Logged In: YES 
user_id=21627

Can you please elaborate? In what way does is that useful
for a restricted environment?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=637906&group_id=5470