Return a formatted view of the bytecode operations.
(self)
| 1097 | return _format_code_info(self.codeobj) |
| 1098 | |
| 1099 | def dis(self): |
| 1100 | """Return a formatted view of the bytecode operations.""" |
| 1101 | co = self.codeobj |
| 1102 | if self.current_offset is not None: |
| 1103 | offset = self.current_offset |
| 1104 | else: |
| 1105 | offset = -1 |
| 1106 | with io.StringIO() as output: |
| 1107 | code = _get_code_array(co, self.adaptive) |
| 1108 | offset_width = len(str(max(len(code) - 2, 9999))) if self.show_offsets else 0 |
| 1109 | if self.show_positions: |
| 1110 | lineno_width = _get_positions_width(co) |
| 1111 | else: |
| 1112 | lineno_width = _get_lineno_width(self._linestarts) |
| 1113 | labels_map = _make_labels_map(co.co_code, self.exception_entries) |
| 1114 | label_width = 4 + len(str(len(labels_map))) |
| 1115 | formatter = Formatter(file=output, |
| 1116 | lineno_width=lineno_width, |
| 1117 | offset_width=offset_width, |
| 1118 | label_width=label_width, |
| 1119 | line_offset=self._line_offset, |
| 1120 | show_caches=self.show_caches, |
| 1121 | show_positions=self.show_positions) |
| 1122 | |
| 1123 | arg_resolver = ArgResolver(co_consts=co.co_consts, |
| 1124 | names=co.co_names, |
| 1125 | varname_from_oparg=co._varname_from_oparg, |
| 1126 | labels_map=labels_map) |
| 1127 | _disassemble_bytes(code, |
| 1128 | linestarts=self._linestarts, |
| 1129 | line_offset=self._line_offset, |
| 1130 | lasti=offset, |
| 1131 | exception_entries=self.exception_entries, |
| 1132 | co_positions=co.co_positions(), |
| 1133 | original_code=co.co_code, |
| 1134 | arg_resolver=arg_resolver, |
| 1135 | formatter=formatter) |
| 1136 | return output.getvalue() |
| 1137 | |
| 1138 | |
| 1139 | def main(args=None): |