Overview

Path PyPoE/poe/file/shared/__init__.py
Version 1.0.0a0
Revision $Id: 3ce5c6fbd0c1571ff1128c461f032bd3fbdafa60 $
Author Omega_K2

Description

Shared classes & functions for the file API. Used for exposing the same basic API.

All file classes inherit the base classes defined here or in the other shared file modules.

Warning

None of the abstract classes found here should be instantiated directly.

See also:

Agreement

See PyPoE/LICENSE

Todo

The abstract classes should probably actually be using python abc api.

Documentation

Abstract Classes

class PyPoE.poe.file.shared.AbstractFileReadOnly[source]

Bases: PyPoE.shared.mixins.ReprMixin

Abstract Base Class for reading.

It provides common methods as well as methods that implementing classes should override.

__init__

Initialize self. See help(type(self)) for accurate signature.

get_read_buffer(file_path_or_raw, function, *args, **kwargs)[source]

Will attempt to open the given file_path_or_raw in read mode and pass the buffer to the specified function. The function must accept at least one keyword argument called ‘buffer’.

Parameters:
  • file_path_or_raw (BytesIO | bytes | str) – file path, bytes or buffer to read from
  • args – Additional positional arguments to pass to the specified function
  • kwargs – Additional keyword arguments to pass to the specified function
Returns:

Result of the function

Return type:

object

Raises:

TypeError – if file_path_or_raw has an invalid type

read(file_path_or_raw, *args, **kwargs)[source]

Reads the file contents into the specified path or buffer. This will also reset any existing contents of the file.

If a buffer or bytes was given, the data will be read from the buffer or bytes object.

If a file path was given, the resulting data will be read from the specified file.

Parameters:
  • file_path_or_raw (BytesIO | bytes | str) – file path, bytes or buffer to read from
  • args – Additional positional arguments
  • kwargs – Additional keyword arguments
Returns:

result of the read operation, if any

Return type:

object

Raises:

TypeError – if file_path_or_raw has an invalid type

class PyPoE.poe.file.shared.AbstractFile[source]

Bases: PyPoE.poe.file.shared.AbstractFileReadOnly

Abstract Base Class for reading and writing files.

It provides common methods as well as methods that implementing classes should override.

__init__

Initialize self. See help(type(self)) for accurate signature.

get_read_buffer(file_path_or_raw, function, *args, **kwargs)

Will attempt to open the given file_path_or_raw in read mode and pass the buffer to the specified function. The function must accept at least one keyword argument called ‘buffer’.

Parameters:
  • file_path_or_raw (BytesIO | bytes | str) – file path, bytes or buffer to read from
  • args – Additional positional arguments to pass to the specified function
  • kwargs – Additional keyword arguments to pass to the specified function
Returns:

Result of the function

Return type:

object

Raises:

TypeError – if file_path_or_raw has an invalid type

get_write_buffer(file_path_or_raw, function, *args, **kwargs)[source]

Will attempt to open the given file_path_or_raw in write mode and pass the buffer to the specified function. The function must accept at least one keyword argument called ‘buffer’.

Parameters:
  • file_path_or_raw (BytesIO | bytes | str) – file path, bytes or buffer to write to
  • args – Additional positional arguments to pass to the specified function
  • kwargs – Additional keyword arguments to pass to the specified function
Returns:

Result of the function

Return type:

object

Raises:

TypeError – if file_path_or_raw has an invalid type

read(file_path_or_raw, *args, **kwargs)

Reads the file contents into the specified path or buffer. This will also reset any existing contents of the file.

If a buffer or bytes was given, the data will be read from the buffer or bytes object.

If a file path was given, the resulting data will be read from the specified file.

Parameters:
  • file_path_or_raw (BytesIO | bytes | str) – file path, bytes or buffer to read from
  • args – Additional positional arguments
  • kwargs – Additional keyword arguments
Returns:

result of the read operation, if any

Return type:

object

Raises:

TypeError – if file_path_or_raw has an invalid type

write(file_path_or_raw, *args, **kwargs)[source]

Write the contents of file to the specified path or buffer.

If a buffer or bytes was given, a buffer object with the new data should be returned.

If a file path was given, the resulting data should be written to the specified file.

Parameters:
  • file_path_or_raw (BytesIO | bytes | str) – file path, bytes or buffer to write to
  • args – Additional positional arguments
  • kwargs – Additional keyword arguments
Returns:

result of the write operation, if any

Return type:

object

Raises:

TypeError – if file_path_or_raw has an invalid type

Exceptions & Warnings

class PyPoE.poe.file.shared.ParserError[source]

Bases: Exception

This exception or subclasses of this exception are raised when general errors related to the parsing of files occur, such as malformed files.

__init__

Initialize self. See help(type(self)) for accurate signature.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class PyPoE.poe.file.shared.ParserWarning[source]

Bases: UserWarning

This warning or subclasses of this warning are emitted when during the parsing process there are cases where issues are not severe enough to entirely fail the passing, but could pose serious problems.

__init__

Initialize self. See help(type(self)) for accurate signature.

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.