ged4py.detail.io¶
Internal module for I/O related methods.
Functions
|
Determines file codec from from its BOM record. |
|
Guess current line number in a file. |
Classes
|
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.BufferedReaderBinary 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
closeFlush and close the IO object.
detachDisconnect this buffer from its underlying raw stream and return it.
filenoReturns underlying file descriptor if one exists.
flushFlush write buffers, if applicable.
isattyReturn 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.
readableReturn 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.
seekableReturn whether object supports random access.
tellReturn current stream position.
truncate([pos])Truncate file to size bytes.
writable(/)Return whether object was opened for writing.
writeWrite 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'¶