4.10. foundations.io

io.py

Platform:
Windows, Linux, Mac Os X.
Description:
Provides file input / output objects and resources manipulation objects.

Others:

4.10.1. Module Attributes

foundations.io.LOGGER

4.10.2. Functions

foundations.io.setDirectory(path)[source]
Creates a directory with given path.
The directory creation is delegated to Python os.makedirs() definition so that directories hierarchy is recursively created.
Parameters:path (unicode) – Directory path.
Returns:Definition success.
Return type:bool
foundations.io.copy(source, destination)[source]

Copies given file or directory to destination.

Parameters:
  • source (unicode) – Source to copy from.
  • destination (unicode) – Destination to copy to.
Returns:

Method success.

Return type:

bool

foundations.io.remove(path)[source]

Removes given path.

Parameters:path (unicode) – Path to remove.
Returns:Method success.
Return type:bool
foundations.io.isReadable(path)[source]

Returns if given path is readable.

Parameters:path (unicode) – Path to check access.
Returns:Is path writable.
Return type:bool
foundations.io.isWritable(path)[source]

Returns if given path is writable.

Parameters:path (unicode) – Path to check access.
Returns:Is path writable.
Return type:bool
foundations.io.isBinaryFile(file)[source]

Returns if given file is a binary file.

Parameters:file (unicode) – File path.
Returns:Is file binary.
Return type:bool

4.10.3. Classes

class foundations.io.File(path=None, content=None)[source]

Bases: object

Defines methods to read / write and append to files or retrieve online file content.

Initializes the class.

Usage:

>>> file = File(u"file.txt")
>>> file.content = [u"Some file content ...\n", u"... ready to be saved!\n"]
>>> file.write()
True
>>> file.read()
u'Some file content ...\n... ready to be saved!\n'
Parameters:
  • path (unicode) – File path.
  • content (list) – Content.
path[source]

Property for self.__path attribute.

Returns:self.__path.
Return type:unicode
content[source]

Property for self.__content attribute.

Returns:self.__content.
Return type:list
cache(mode=u'r', encoding='utf-8', errors='ignore')[source]

Reads given file content and stores it in the content cache.

Parameters:
  • mode (unicode) – File read mode.
  • encoding (unicode) – File encoding codec.
  • errors (unicode) – File encoding errors handling.
Returns:

Method success.

Return type:

bool

uncache()[source]

Uncaches the cached content.

Returns:Method success.
Return type:bool
read()[source]

Returns defined file content.

Returns:File content.
Return type:unicode
write(mode=u'w', encoding='utf-8', errors='ignore')[source]

Writes content to defined file.

Parameters:
  • mode (unicode) – File write mode.
  • encoding (unicode) – File encoding codec.
  • errors (unicode) – File encoding errors handling.
Returns:

Method success.

Return type:

bool

append(mode=u'a', encoding='utf-8', errors='ignore')[source]

Appends content to defined file.

Parameters:
  • mode (unicode) – File write mode.
  • encoding (unicode) – File encoding codec.
  • errors (unicode) – File encoding errors handling.
Returns:

Method success.

Return type:

bool

clear(encoding='utf-8')[source]

Clears the defined file content.

Parameters:encoding (unicode) – File encoding codec.
Returns:Method success.
Return type:bool