Transform tokens back into Python source code. It returns a bytes object, encoded using the ENCODING token, which is the first token sequence output by tokenize. Each element returned by the iterable must be a token sequence with at least two elements, a token number and token value
(iterable)
| 324 | |
| 325 | |
| 326 | def untokenize(iterable): |
| 327 | """Transform tokens back into Python source code. |
| 328 | It returns a bytes object, encoded using the ENCODING |
| 329 | token, which is the first token sequence output by tokenize. |
| 330 | |
| 331 | Each element returned by the iterable must be a token sequence |
| 332 | with at least two elements, a token number and token value. If |
| 333 | only two tokens are passed, the resulting output is poor. |
| 334 | |
| 335 | The result is guaranteed to tokenize back to match the input so |
| 336 | that the conversion is lossless and round-trips are assured. |
| 337 | The guarantee applies only to the token type and token string as |
| 338 | the spacing between tokens (column positions) may change. |
| 339 | """ |
| 340 | ut = Untokenizer() |
| 341 | out = ut.untokenize(iterable) |
| 342 | if ut.encoding is not None: |
| 343 | out = out.encode(ut.encoding) |
| 344 | return out |
| 345 | |
| 346 | |
| 347 | def _get_normal_name(orig_enc): |
nothing calls this directly
no test coverage detected
searching dependent graphs…