From 3e1b85ead189a33dc20c190bfe6428c991a8ee04 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 30 May 2007 02:07:00 +0000 Subject: [PATCH] Add a helper to display the various flags and components of code objects (everything besides the actual code disassembly). --- Lib/dis.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Lib/dis.py b/Lib/dis.py index 90544f43005..f274606075b 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -55,6 +55,62 @@ def distb(tb=None): while tb.tb_next: tb = tb.tb_next disassemble(tb.tb_frame.f_code, tb.tb_lasti) +# XXX This duplicates information from code.h, also duplicated in inspect.py. +# XXX Maybe this ought to be put in a central location, like opcode.py? +flag2name = { + 1: "OPTIMIZED", + 2: "NEWLOCALS", + 4: "VARARGS", + 8: "VARKEYWORDS", + 16: "NESTED", + 32: "GENERATOR", + 64: "NOFREE", +} + +def pretty_flags(flags): + """Return pretty representation of code flags.""" + names = [] + for i in range(32): + flag = 1<