uriinputstream package

This package allows to read files in a cross-platform way. It has been tested on Android and Windows, but should also work on Linux and macOS. It is used by UriFile.open() when mode is “rb” or “rt”

UriInputStream class

class tatogalib.uri_io.uriinputstream.UriInputStream(uristring, fnLog=None)

Creates a UriInputStream which wraps a RawIOBase stream. This class supports the context manager protocol.

Parameters:
  • uristring (str) – The URI-string of the stream

  • fnLog (callable) – The callable which is called from the log method It expects a string parameter

close()

Closes the stream

property closed

Checks if the stream is closed

Returns:

True when closed, False otherwise

flush()

This method is doing nothing on this stream

isatty()

This method always returns False

Returns:

False

log(message)

Logs a message to the user code if fnLog was passed to the constructor

Parameters:

message (str) – The message to be logged

read(maxsize=-1)

Reads maxsize bytes from the stream. If less than maxbytes are returned, we reached the end of the stream

Parameters:

maxsize (int) – the amount of bytes to read. When -1, all available bytes are read

Returns:

the read bytes

Return type:

bytes

readable()

Checks if the stream is readable

Returns:

True when readable, False otherwise

readall()

Reads all available bytes

Returns:

the read bytes

Return type:

bytes

readinto(bytesobj)

Read bytes into the byte-like object

Parameters:

bytesobj (bytes) – The byte-like object to read into

Returns:

the number of bytes read or None when no more bytes available

Return type:

int or None

seek(offset, whence=0)

Change the stream position to the given byte offset

Parameters:
  • offset (int) – byte offset

  • whence (int) – see os.SEEK_* constants

Returns:

True when seekable, False otherwise

seekable()

Checks if the stream is seekable

Returns:

True when seekable, False otherwise

tell()

Returns the current stream position

Returns:

The current stream position

truncate(size=None)

This method will raise an OS error when it is called

writable()

This method always returns False

write(bytesobj)

This method will raise an OS error when it is called

UriTextInputStream class

class tatogalib.uri_io.uriinputstream.UriTextInputStream(uristring, encoding, fnLog=None)

Creates a UriTextInputStream which wraps a TextIOWrapper. Valid line endings are \n, \r or \n\r. They are all translated to \n. This class supports the context manager protocol.

Parameters:
  • uristring (str) – The URI-string of the stream

  • encoding (str) – The encoding of the text, e.g. “utf-8-sig”

  • fnLog (callable) – The callable which is called from the log method It expects a string parameter

close()

Closes the stream

property closed

Checks if the stream is closed

Returns:

True when closed, False otherwise

flush()

This method is doing nothing on this stream

isatty()

This method always returns False

Returns:

False

log(message)

Logs a message to the user code if fnLog was passed to the constructor

Parameters:

message (str) – The message to be logged

read(maxsize=-1)

Reads maxsize characters from the stream.

Parameters:

maxsize (int) – The maximum amount of characters to read. When -1, all available characters are read

Returns:

The read chatacters

Return type:

str

readable()

Checks if the stream is readable

Returns:

True when readable, False otherwise

readall()

Reads all available bytes

Returns:

the read bytes

Return type:

bytes

readline(maxsize=-1)

Read until newline or EOF and return a single str. If the stream is already at EOF, an empty string is returned.

Parameters:

maxsize (int) – The maximum amount of characters to read

Returns:

A single string

Return type:

str

seekable()

Checks if the stream is seekable

Returns:

True when seekable, False otherwise

truncate(size=None)

This method will raise an OS error when it is called

writable()

This method always returns False

write(string)

This method will raise an OS error when it is called