tbm-utils¶
tbm-utils is a commonly-used set of utilities used by me (thebigmunch).
Getting Started¶
===============
Install tbm-utils with pip <https://pip.pypa.io/en/stable/>
_.
$ pip install -U tbm-utils
API Reference¶
CLI¶
Config¶
Constants¶
Datetime¶
Decorators¶
Humanize¶
IO¶
-
class
tbm_utils.io.
DataReader
(data, buffer_size=8192)[source]¶ A buffered reader wrapper.
It includes support for filepaths, file-like objects, and bytes-like objects.
- Parameters
data (DataReader, BufferedIOBase, os.PathLike, str, bytes, bytearray, memoryview) – The object to provide the
BufferedReader
interface for.buffer_size (int) – The size of the internal buffer. (Default: io.DEFAULT_BUFFER_SIZE)
-
read
(size=- 1)[source]¶ Read and return up to n bytes.
If the argument is omitted, None, or negative, reads and returns all data until EOF.
If the argument is positive, and the underlying raw stream is not ‘interactive’, multiple raw reads may be issued to satisfy the byte count (unless EOF is reached first). But for interactive raw streams (as well as sockets and pipes), at most one raw read will be issued, and a short result does not imply that EOF is imminent.
Returns an empty bytes object on EOF.
Returns None if the underlying raw stream was open in non-blocking mode and no data is available at the moment.
-
class
tbm_utils.io.
DataWriter
(data, buffer_size=8192)[source]¶ A buffered writer wrapper.
It includes support for filepaths, file-like objects, and bytes-like objects.
- Parameters
data (DataReader, BufferedIOBase, os.PathLike, str, bytes, bytearray, memoryview) – The object to provide the
BufferedWriter
interface for.buffer_size (int) – The size of the internal buffer. (Default: io.DEFAULT_BUFFER_SIZE)
Misc¶
Path¶
-
tbm_utils.path.
UNIX_PATH_RE
= re.compile('(/(cygdrive/)?)(.*)')¶ Regex pattern matching UNIX-style filepaths.
-
tbm_utils.path.
convert_unix_path
(filepath)[source]¶ Convert Unix filepath string from Unix to Windows format.
- Parameters
filepath (str, os.PathLike, Path) – A filepath string.
- Returns
A Windows path object.
- Return type
Path
- Raises