Debian Codegraph @

pypy/module/_io/app_io.py

raw symbols SCIP
1 import _io
2 import sys
3
4 def text_encoding(encoding, stacklevel=2):
5 """
6 A helper function to choose the text encoding.
7
8 When encoding is not None, just return it.
9 Otherwise, return the default text encoding (i.e. "locale").
10
11 This function emits an EncodingWarning if *encoding* is None and
12 sys.flags.warn_default_encoding is non-zero.
13
14 This can be used in APIs with an encoding=None parameter
15 that pass it to TextIOWrapper or open.
16 However, please consider using encoding="utf-8" for new APIs.
17 """
18 if encoding is None:
19 encoding = "locale"
20 if sys.flags.warn_default_encoding != 0:
21 import warnings
22 warnings.warn("'encoding' argument not specified.",
23 EncodingWarning, stacklevel + 1)
24 return encoding