ged4py.detail.io

Internal module for I/O related methods.

Functions

check_bom(file)

Determines file codec from from its BOM record.

guess_lineno(file)

Guess current line number in a file.

Classes

BinaryFileCR(raw)

Binary file with support of CR line terminators.

ged4py.detail.io.check_bom(file)[source]

Determines file codec from from its BOM record.

If file starts with BOM record encoded with UTF-8 or UTF-16(BE/LE) then corresponding encoding name is returned, otherwise None is returned. In both cases file current position is set to after-BOM bytes. The file must be open in binary mode and positioned at offset 0.

ged4py.detail.io.guess_lineno(file)[source]

Guess current line number in a file.

Guessing is done in a very crude way - scanning file from beginning until current offset and counting newlines. Only meant to be used in exceptional cases - generating line number for error message.

class ged4py.detail.io.BinaryFileCR(raw)[source]

Bases: _io.BufferedReader

Binary file with support of CR line terminators.

I need a binary file object with readline() method which supports all possible line terminators (LF, CR-LF, CR). Standard binary files have readline that only stops at LF (and hence CR-LF). This class adds a workaround for readline method to understand CR-delimited files.

Attributes
closed
mode
name
raw

Methods

close

Flush and close the IO object.

detach

Disconnect this buffer from its underlying raw stream and return it.

fileno

Returns underlying file descriptor if one exists.

flush

Flush write buffers, if applicable.

isatty

Return whether this is an ‘interactive’ stream.

read([size])

Read and return up to n bytes.

read1([size])

Read and return up to n bytes, with at most one read() call to the underlying raw stream.

readable

Return whether object was opened for reading.

readline([limit])

Read and return a line from the stream.

readlines([hint])

Return a list of lines from the stream.

seek(target[, whence])

Change stream position.

seekable

Return whether object supports random access.

tell

Return current stream position.

truncate([pos])

Truncate file to size bytes.

writable(/)

Return whether object was opened for writing.

write

Write the given buffer to the IO stream.

writelines(lines, /)

Write a list of lines to stream.

peek

readinto

readinto1

CR = b'\r'
LF = b'\n'
readline(limit=- 1)[source]

Read and return a line from the stream.

If size is specified, at most size bytes will be read.

The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.