pysys.utils.pycompat¶
Compatibility utilities for older Python versions.
This module is now deprecated as all functionality can be provided by the Python standard library.
Instead of quotestring
use pysys.utils.misc.quoteString
.
isstring¶
openfile¶
- pysys.utils.pycompat.openfile(path, mode='r', encoding=None, errors=None, **kwargs)[source]¶
Opens the specified file, following the default “open()” semantics for this Python version unless an encoding is explicitly specified, in which case a file stream yielding (unicode) character strings is always returned.
This method returns a file stream yielding character strings unless a binary mode was specified in which case a stream yielding bytes is returned.
Deprecated - use
io.open(pysys.utils.fileutils.toLongPathSafe(path), ...)
instead.- Parameters
path – The path to open; must be an absolute path. Even on Windows this path can be long (e.g. more than the usual 256 character Windows limit).
mode – The file mode, e.g. ‘r’ for reading, ‘wb’ for binary writing.
encoding – The encoding to use to translate between the bytes of the file and the characters used in the returned stream. If an encoding is specified then the returned stream is always a unicode character stream. This must be None if the mode specifies binary.
errors – Optional string that specifies how encoding/decoding errors are handled, such as ‘strict’, ‘ignore’, ‘replace’; see documentation of io module for more details.
kwargs – Any additional args to be passed to open() or io.open().
- Returns
A file stream, either using unicode characters or binary bytes. This stream should be closed when no longer required.