fs.mode¶
Abstract I/O mode container.
Mode strings are used in in open and
openbin.
-
class
fs.mode.Mode(mode)[source]¶ 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
-
appending¶ bool–Trueif the mode permits appending.
-
binary¶ bool–Trueif a mode specifies binary.
-
create¶ bool–Trueif the mode would create a file.
-
exclusive¶ bool–Trueif the mode require exclusive creation.
-
reading¶ bool–Trueif the mode permits reading.
-
text¶ bool–Trueif a mode specifies text.
-
to_platform()[source]¶ 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()[source]¶ Get a binary mode string for the current platform.
Currently, this just removes the ‘x’ on PY2 because PY2 doesn’t support exclusive mode.
-
truncate¶ bool–Trueif the mode would truncate an existing file.
-
updating¶ bool–Trueif the mode permits both reading and writing.
-
validate(_valid_chars=frozenset([u'a', u'b', u'+', u'r', u't', u'w', u'x']))[source]¶ Validate the mode string.
Raises: ValueError– if the mode contains invalid chars.
-
validate_bin()[source]¶ Validate a mode for opening a binary file.
Raises: ValueError– if the mode contains invalid chars.
-
writing¶ bool–Trueif the mode permits writing.
-
-
fs.mode.check_readable(mode)[source]¶ Check a mode string allows reading.
Parameters: mode (str) – A mode string, e.g. "rt"Returns: Trueif the mode allows reading.Return type: bool