fs.mode¶
Abstract I/O mode container.
Mode strings are used in in open
and
openbin
.
-
class
fs.mode.
Mode
(mode)¶ An abstraction for I/O modes.
A mode object provides properties that can be used to interrogate the mode strings used when opening files.
Parameters: mode (str) – A mode string, as used by io.open
.Raises: ValueError
– If the mode string is invalid.Example
>>> mode = Mode('rb') >>> mode.reading True >>> mode.writing False >>> mode.binary True >>> mode.text False
-
to_platform
()¶ Get a mode string for the current platform.
Currently, this just removes the ‘x’ on PY2 because PY2 doesn’t support exclusive mode.
-
to_platform_bin
()¶ Get a binary mode string for the current platform.
Currently, this just removes the ‘x’ on PY2 because PY2 doesn’t support exclusive mode.
-
validate
(_valid_chars=frozenset([u'a', u'b', u'+', u'r', u't', u'w', u'x']))¶ Validate the mode string.
Raises: ValueError
– if the mode contains invalid chars.
-
validate_bin
()¶ Validate a mode for opening a binary file.
Raises: ValueError
– if the mode contains invalid chars.
-
-
fs.mode.
check_readable
(mode)¶ Check a mode string allows reading.
Parameters: mode (str) – A mode string, e.g. "rt"
Returns: True
if the mode allows reading.Return type: bool
-
fs.mode.
check_writable
(mode)¶ Check a mode string allows writing.
Parameters: mode (str) – A mode string, e.g. "wt"
Returns: True
if the mode allows writing.Return type: bool
-
fs.mode.
validate_open_mode
(mode)¶ Check
mode
parameter ofopen
is valid.Parameters: mode (str) – Mode parameter. Raises: ValueError
if mode is not valid.
-
fs.mode.
validate_openbin_mode
(mode, _valid_chars=frozenset([u'a', u'b', u'+', u'r', u'w', u'x']))¶ Check
mode
parameter ofopenbin
is valid.Parameters: mode (str) – Mode parameter. Raises: ValueError
if mode is not valid.