The tokenize() generator requires one argument, readline, which must be a callable object which provides the same interface as the readline() method of built-in file objects. Each call to the function should return one line of input as bytes. Alternatively, readline can b
(readline)
| 406 | |
| 407 | |
| 408 | def tokenize(readline): |
| 409 | """ |
| 410 | The tokenize() generator requires one argument, readline, which |
| 411 | must be a callable object which provides the same interface as the |
| 412 | readline() method of built-in file objects. Each call to the function |
| 413 | should return one line of input as bytes. Alternatively, readline |
| 414 | can be a callable function terminating with StopIteration: |
| 415 | readline = open(myfile, 'rb').__next__ # Example of alternate readline |
| 416 | |
| 417 | The generator produces 5-tuples with these members: the token type; the |
| 418 | token string; a 2-tuple (srow, scol) of ints specifying the row and |
| 419 | column where the token begins in the source; a 2-tuple (erow, ecol) of |
| 420 | ints specifying the row and column where the token ends in the source; |
| 421 | and the line on which the token was found. The line passed is the |
| 422 | physical line. |
| 423 | |
| 424 | The first token sequence will always be an ENCODING token |
| 425 | which tells you which encoding was used to decode the bytes stream. |
| 426 | """ |
| 427 | encoding, consumed = detect_encoding(readline) |
| 428 | empty = _itertools.repeat(b"") |
| 429 | rl_gen = _itertools.chain(consumed, iter(readline, b""), empty) |
| 430 | return _tokenize(rl_gen.__next__, encoding) |
| 431 | |
| 432 | |
| 433 | def _tokenize(readline, encoding): |
no test coverage detected