Lines Matching defs:mode

49     (i.e. "locale" or "utf-8" depends on UTF-8 mode).
77 def open(file, mode="r", buffering=-1, encoding=None, errors=None,
88 mode is an optional string that specifies the mode in which the file is
89 opened. It defaults to 'r' which means open for reading in text mode. Other
93 file regardless of the current seek position). In text mode, if encoding is
95 writing raw bytes use binary mode and leave encoding unspecified.) The
105 'b' binary mode
106 't' text mode (default)
110 The default mode is 'rt' (open for reading text). For binary random
111 access, the mode 'w+b' opens and truncates the file to 0 bytes, while
112 'r+b' opens the file without truncation. The 'x' mode implies 'w' and
117 binary mode (appending 'b' to the mode argument) return contents as
118 bytes objects without any decoding. In text mode (the default, or when
119 't' is appended to the mode argument), the contents of the file are
124 Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
125 line buffering (only usable in text mode), and an integer > 1 to indicate
139 file. This should only be used in text mode. The default encoding is
144 be handled---this argument should not be used in binary mode. Pass
152 applies to text mode). It can be None, '', '\n', '\r', and '\r\n'. It works
155 * On input, if newline is None, universal newlines mode is
158 caller. If it is '', universal newline mode is enabled, but line
181 open() returns a file object whose type depends on the mode, and
183 are performed. When open() is used to open a file in a text mode ('w',
185 a file in a binary mode, the returned class varies: in read binary
186 mode, it returns a BufferedReader; in write binary and append binary
187 modes, it returns a BufferedWriter, and in read/write mode, it returns
192 opened in a text mode, and for bytes a BytesIO can be used like a file
193 opened in a binary mode.
199 if not isinstance(mode, str):
200 raise TypeError("invalid mode: %r" % mode)
207 modes = set(mode)
208 if modes - set("axrwb+t") or len(mode) > len(modes):
209 raise ValueError("invalid mode: %r" % mode)
218 raise ValueError("can't have text and binary mode at once")
220 raise ValueError("can't have read/write/append mode at once")
222 raise ValueError("must have exactly one of read/write/append mode")
224 raise ValueError("binary mode doesn't take an encoding argument")
226 raise ValueError("binary mode doesn't take an errors argument")
228 raise ValueError("binary mode doesn't take a newline argument")
232 "mode, the default buffer size will be used",
269 raise ValueError("unknown mode: %r" % mode)
276 text.mode = mode
285 """Opens the provided file with mode ``'rb'``. This function
699 mode and not ready; unlike their raw counterparts, they will never
877 def mode(self):
878 return self.raw.mode
1081 mode. If size is negative, read until EOF or until read() would
1215 # in read1 mode and already got some data
1220 # In readinto1 mode, return as soon as we have some data
1500 def __init__(self, file, mode='r', closefd=True, opener=None):
1501 """Open a file. The mode can be 'r' (default), 'w', 'x' or 'a' for reading,
1506 writing so this mode behaves in a similar way to 'w'. Add a '+' to the mode
1530 if not isinstance(mode, str):
1531 raise TypeError('invalid mode: %s' % (mode,))
1532 if not set(mode) <= set('xrwab+'):
1533 raise ValueError('invalid mode: %s' % (mode,))
1534 if sum(c in 'rwax' for c in mode) != 1 or mode.count('+') > 1:
1536 'mode and at most one plus')
1538 if 'x' in mode:
1542 elif 'r' in mode:
1545 elif 'w' in mode:
1548 elif 'a' in mode:
1553 if '+' in mode:
1639 return ('<%s fd=%d mode=%r closefd=%r>' %
1640 (class_name, self._fd, self.mode, self._closefd))
1642 return ('<%s name=%r mode=%r closefd=%r>' %
1643 (class_name, name, self.mode, self._closefd))
1657 In non-blocking mode, returns None if no data is available.
1672 In non-blocking mode, returns as much as is immediately available,
1716 The number of bytes actually written is returned. In non-blocking mode,
1788 """True if file was opened in a read mode."""
1793 """True if file was opened in a write mode."""
1813 def mode(self):
1814 """String giving the file mode"""
1902 r"""Codec used when reading a file in universal newlines mode. It wraps
2104 mode = self.mode
2108 result += " mode={0!r}".format(mode)