readline0 module

Split up a file and yield its pieces based on some line terminator.

Usage looks like:

$ /usr/local/cpython-3.6/bin/python3 Python 3.6.0 (default, Apr 22 2017, 09:17:19) [GCC 5.4.0 20160609] on linux Type “help”, “copyright”, “credits” or “license” for more information. >>> import readline0 >>> file_ = open(‘/etc/shells’, ‘r’) >>> for line in readline0.readline0(file_=file_, separator=b’n’): … print(line) … b’# /etc/shells: valid login shells’ b’/bin/sh’ b’/bin/dash’ b’/bin/bash’ b’/bin/rbash’ >>>

Of course separator need not be a newline; it defaults to a null byte.

class readline0.Readline0(file_: Union[TextIO, int], separator: bytes, blocksize: int)[source]

Bases: object

Yield a series of blocks, separated by separator.

get_fields() None[source]

Read a block, chop it up into fields - taking into account any leftover partial field.

classmethod handle_field_pairs(field_pairs)[source]

Pick apart the pairs from our regex split and return the correct values.

sequence() Iterator[bytes][source]

Generate each field (line) in turn.

readline0.readline0(file_: Union[TextIO, int] = <_io.TextIOWrapper name='<stdin>' mode='r' encoding='ANSI_X3.4-1968'>, separator: bytes = b'\x00', blocksize: int = 65536)[source]

Instantiate Readline0 class and yield what we get back.

file_ defaults to sys.stdin, separator defaults to a null, and blocksize defaults to 64K.