Lines Matching defs:encoding
43 def text_encoding(encoding, stacklevel=2):
45 A helper function to choose the text encoding.
47 When encoding is not None, this function returns it.
48 Otherwise, this function returns the default text encoding
51 This function emits an EncodingWarning if *encoding* is None and
54 This can be used in APIs with an encoding=None parameter
56 However, please consider using encoding="utf-8" for new APIs.
58 if encoding is None:
60 encoding = "utf-8"
62 encoding = "locale"
65 warnings.warn("'encoding' argument not specified.",
67 return encoding
77 def open(file, mode="r", buffering=-1, encoding=None, errors=None,
93 file regardless of the current seek position). In text mode, if encoding is
94 not specified the encoding used is platform dependent. (For reading and
95 writing raw bytes use binary mode and leave encoding unspecified.) The
121 platform-dependent encoding or using the specified encoding if given.
138 encoding is the str name of the encoding used to decode or encode the
139 file. This should only be used in text mode. The default encoding is
140 platform dependent, but any encoding supported by Python can be
143 errors is an optional string that specifies how encoding errors are to
145 'strict' to raise a ValueError exception if there is an encoding error
147 errors. (Note that ignoring encoding errors can lead to data loss.)
149 encoding error strings.
203 if encoding is not None and not isinstance(encoding, str):
204 raise TypeError("invalid encoding: %r" % encoding)
223 if binary and encoding is not None:
224 raise ValueError("binary mode doesn't take an encoding argument")
273 encoding = text_encoding(encoding)
274 text = TextIOWrapper(buffer, encoding, errors, newline, line_buffering)
1877 def encoding(self):
1990 encoding gives the name of the encoding that the stream will be
1993 errors determines the strictness of encoding and decoding (see the
2019 def __init__(self, buffer, encoding=None, errors=None, newline=None,
2022 encoding = text_encoding(encoding)
2024 if encoding == "locale":
2025 encoding = self._get_locale_encoding()
2027 if not isinstance(encoding, str):
2028 raise ValueError("invalid encoding: %r" % encoding)
2030 if not codecs.lookup(encoding)._is_text_encoding:
2031 msg = ("%r is not a text encoding; "
2033 raise LookupError(msg % encoding)
2049 self._configure(encoding, errors, newline,
2058 def _configure(self, encoding=None, errors=None, newline=None,
2060 self._encoding = encoding
2109 return result + " encoding={0!r}>".format(self.encoding)
2112 def encoding(self):
2132 encoding=None, errors=None, newline=Ellipsis,
2139 and (encoding is not None or errors is not None
2142 "It is not possible to set the encoding or newline of stream "
2146 if encoding is None:
2153 if encoding is None:
2154 encoding = self._encoding
2156 if not isinstance(encoding, str):
2157 raise TypeError("invalid encoding: %r" % encoding)
2158 if encoding == "locale":
2159 encoding = self._get_locale_encoding()
2171 self._configure(encoding, errors, newline,
2670 encoding="utf-8",
2695 # TextIOWrapper tells the encoding in its repr. In StringIO,
2704 def encoding(self):