core - The basics

The core package contains general purpose modules and building blocks for the other library packages.

abstract - Additions to the abc standard module

Helpers for the standard abc module.

class abstractstatic(function)[source]

Decorator that combines staticmethod and abc.abstractmethod.

Copied from this answer to this StackOverflow question.

async_subprocess - Subprocesses with non-blocking I/O

Allow asynchronous interaction with a subprocess.

This module was taken from this recipe in the ActiveState Code Recipes website, with only minor modifications. This is the original description:

Title:        Module to allow Asynchronous subprocess use on Windows and Posix platforms
Submitter:    Josiah Carlson (other recipes)
Last Updated: 2006/12/01
Version no:   1.9
Category:     System 

On Windows pywin32 is required.

class AsyncPopen(cmd, encoding=None, **kwargs)[source]

An asynchronous variant to subprocess.Popen, which doesn’t block on incomplete I/O operations.

Note that the terms input, output and error refer to the controlled program streams, so we receive from output or error and we send to input.

__init__(cmd, encoding=None, **kwargs)[source]

Execute cmd in a subprocess, using encoding to convert to and from binary data written or read from/to the subprocess’s input, output and error streams.

Additional keyword arguments are as specified by subprocess.Popen.__init__() method.

get_conn_maxsize(which, maxsize)[source]

Return which output pipe (either stdout or stderr) and maxsize constrained to the [1, 1024] interval in a tuple.

recv(maxsize=None)[source]

Receive at most maxsize bytes from the subprocess’s standard output.

recv_err(maxsize=None)[source]

Receive at most maxsize bytes from the subprocess’s standard error.

send(input_)[source]

Send input_ to the subprocess’s standard input.

send_recv(input_='', maxsize=None)[source]

Send input_ to the subprocess’s standard input and then receive at most maxsize bytes from both its standard output and standard error.

recv_some(p, t=0.1, e=1, tr=5, stderr=0)[source]

Try and receive data from AsyncPopen object p‘s stdout in at most tr tries and with a timeout of t. If stderr is True receive from the subprocess’s stderr instead.

send_all(p, data)[source]

Send all of data to AsyncPopen object p‘s stdin.

backup_file - File objects with automated backup

Backup a file or directory to make editing reversible.

Implement the context manager protocol, so as to be suitable to be used with the with statement. When used in this fashion changes are discarded when an exception is thrown.

class BackupDir(dir_, ext='.BAK', mode=1)[source]

Move or copy a directory that needs to be recreated or modified.

__enter__()[source]

When the controlling with statement is entered, create the backup directory.

__exit__(exc_type, exc_val, exc_tb)[source]

When the controlling with statement is exited normally discard the backup directory, otherwise restore it to its original place.

__init__(dir_, ext='.BAK', mode=1)[source]

Prepare to backup the dir_ directory.

The backup will be created in dir_‘s parent directory, which must be writable, with extension ext. If mode is MOVE, the default, the original directory will be moved to the backup destination; if mode is COPY it will be copied there.

commit()[source]

Discard the backup, i.e. keep the supposedly modified file.

rollback()[source]

Replace the original file with the backup copy.

save()[source]

Create a backup copy of the original directory.

class BackupFile(file_, ext='.BAK', dir='.', mode=2)[source]

Implements a read only file object used to automatically back up a file that has to be modified.

__enter__()[source]

When the controlling with statement is entered, create the backup file.

__exit__(exc_type, exc_val, exc_tb)[source]

When the controlling with statement is exited normally discard the backup file, otherwise restore it to its original place.

__init__(file_, ext='.BAK', dir='.', mode=2)[source]

Prepare to backup file_, either a file-like object or a path.

The backup file will be created in directory dir with extension ext. If mode is COPY the original file will be copied to the backup destination; if mode is MOVE it will be moved there.

close()[source]

Close the backup file and release the corresponding reference.

The backup file may not be reopened.

commit()[source]

Discard the backup, i.e. keep the supposedly modified file.

name

The name of the file to be backed up.

open(mode=4)[source]

Open the backup file for reading. mode may be either TEXT or BINARY.

rollback()[source]

Replace the original file with the backup copy.

save()[source]

Create a backup copy of the original file.

Throw SaveError if it wasn’t possible.

exception MissingBackupError[source]

raised when a backup file or directory isn’t found.

exception NotSavedError[source]

Raised when commit or rollback is called on an inactive BackUpFile or BackUpDirectory.

exception RemovalError[source]

Raised to signal errors in the removal of backup files or directories.

exception SaveError[source]

Raised when a backup file or directory could not be created.

error - nxpy‘s exception hierarchy

Exception classes.

exception ArgumentError[source]

Raised when a function receives an invalid argument

file_object - Stubs for read-only and modifiable file-like objects

Helper classes for the implementation of read-only and writable file objects that forward calls to an actual file object variable.

class ReadOnlyFileObject(file_=None)[source]

Implement the non modifying portion of the file object protocol by delegating to another file object.

Subclass and override as needed.

__init__(file_=None)[source]

Set the delegate file object.

setFile(file_)[source]

Set the delegate file object.

class WritableFileObject(file_=None)[source]

Implement the file object protocol by delegating to another file object.

Subclass and override as needed.

__init__(file_=None)[source]

file - File related utilities

File related utilities.

compare(file1, file2, ignore_eof=True, encoding=None)[source]

Compare two text files for equality. If ignore_eof is True, end of line characters are not considered. If not None encoding is used to open the files. On Python 2.x encoding is ignored.

open_(*args, **kwargs)[source]

Open a file removing invalid arguments on Python 2.x.

memo - Memoize objects according to a given key

Memoize class instances according to a given key.

By default the key only assumes the True value, thus implementing a singleton.

class Memo[source]

Base class for classes that require memoization.

Subclasses should override the _key(*args, **kwargs) method to compute a key on the constructor’s arguments.

Care should be taken to avoid calling __init__() again for entities already constructed.

static __new__(*args, **kwargs)[source]

Return the instance corresponding to the given key, creating it if it doesn’t exist.

past - Python version support enforcement

Identification and enforcement of supported Python releases.

class Version(version)[source]

Identifies a Python release in a way that is convenient for comparison and printing.

at_least()[source]

Return True if the current Python version is equal or higher than self.

at_most()[source]

Return True if the current Python version is equal or lower than self.

enforce_at_least(version)[source]

Assert that the current Python version is equal or higher than version.

enforce_at_most(version)[source]

Assert that the current Python version is equal or lower than version.

path - File system related utilities

filesystem related utilities.

class CurrentDirectory(path)[source]

A context manager that allows changing the current directory temporarily.

__init__(path)[source]

Set the current directory to path.

current

Return the current directory.

blasttree(dir_)[source]

Remove a directory more stubbornly than shutil.rmtree().

Required on filesystems that do not allow removal of non-writable files

sequence - Sequence related utilities

Utility functions that deal with non-string sequences.

make_tuple(arg)[source]

An alternate way of creating tuples from a single argument.

A single string argument is turned into a single element tuple and a dictionary argument is turned into a tuple of its items. Otherwise it works like the standard tuple constructor.

sort - Sorting functions

Sort functions.

topological_sort(pairs)[source]

Provide a topological ordering of the supplied pair elements.

pairs is a sequence of two element sequences, in which the first element comes before the second according to the desired ordering criterium.

temp_file - Temporary files that support the context protocol

Temporary files and directories.

Requires at least Python 2.6

class TempDir(*args, **kwargs)[source]

A temporary directory that implements the context manager protocol.

The directory is removed when the context is exited from. Uses tempfile.mkdtemp() to create the actual directory.

__init__(*args, **kwargs)[source]

Create a temporary directory with the given arguments.

name

Return the directory name.

class TempFile(*args, **kwargs)[source]

A temporary file that implements the context manager protocol.

Wrap a tempfile.NamedTemporaryFile() generated file-like object, to ensure it is not deleted on close, but rather when the underlying context is closed.

__init__(*args, **kwargs)[source]

Create a temporary file with the given arguments.

name

Return the actual file name.