Generate all the opcodes in a pickle. 'pickle' is a file-like object, or string, containing the pickle. Each opcode in the pickle is generated, from the current pickle position, stopping after a STOP opcode is delivered. A triple is generated for each opcode: opcode, arg,
(pickle)
| 2298 | break |
| 2299 | |
| 2300 | def genops(pickle): |
| 2301 | """Generate all the opcodes in a pickle. |
| 2302 | |
| 2303 | 'pickle' is a file-like object, or string, containing the pickle. |
| 2304 | |
| 2305 | Each opcode in the pickle is generated, from the current pickle position, |
| 2306 | stopping after a STOP opcode is delivered. A triple is generated for |
| 2307 | each opcode: |
| 2308 | |
| 2309 | opcode, arg, pos |
| 2310 | |
| 2311 | opcode is an OpcodeInfo record, describing the current opcode. |
| 2312 | |
| 2313 | If the opcode has an argument embedded in the pickle, arg is its decoded |
| 2314 | value, as a Python object. If the opcode doesn't have an argument, arg |
| 2315 | is None. |
| 2316 | |
| 2317 | If the pickle has a tell() method, pos was the value of pickle.tell() |
| 2318 | before reading the current opcode. If the pickle is a bytes object, |
| 2319 | it's wrapped in a BytesIO object, and the latter's tell() result is |
| 2320 | used. Else (the pickle doesn't have a tell(), and it's not obvious how |
| 2321 | to query its current position) pos is None. |
| 2322 | """ |
| 2323 | return _genops(pickle) |
| 2324 | |
| 2325 | ############################################################################## |
| 2326 | # A pickle optimizer. |