core - The basics
The core package contains general purpose modules and building blocks for the other library
packages.
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
-
class AsyncPopen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)[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.
-
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
A file with automatic backup.
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 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[source]
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.
-
exception MissingBackupError[source]
raised when a backup file isn’t found.
-
exception NotSavedError[source]
Raised when commit or rollback is called on an inactive BackUpFile.
-
exception RemovalError[source]
Raised to signal errors in the removal of backup files.
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.
These smell a lot of statically typed languages and are likely to be removed or changed a lot in a
future release.
-
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.
-
__iter__()[source]
-
close()[source]
-
closed[source]
-
encoding[source]
-
flush()[source]
-
mode[source]
-
name[source]
-
newlines[source]
-
next()[source]
-
read(size=-1)[source]
-
readline(size=-1)[source]
-
readlines(sizehint=None)[source]
-
seek(offset, whence=0)[source]
-
setFile(file_)[source]
Set the delegate file object.
-
softspace[source]
-
tell()[source]
-
xreadlines()[source]
-
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]
-
truncate(size=None)[source]
-
write(str_)[source]
-
writelines(sequence)[source]
file - File related utilities
File related utilities.
-
compare(file1, file2, ignore_eof=True)[source]
Compare two text files for equality.
If ignore_eof is True, end of line characters are not considered.
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.
-
blasttree(dir_)[source]
Removes 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[source]
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[source]
Return the actual file name.