MCPcopy Index your code
hub / github.com/aws/aws-cli / set_preferred_output_encoding

Function set_preferred_output_encoding

awscli/compat.py:156–181  ·  view source on GitHub ↗

If the user specified AWS_CLI_OUTPUT_ENCODING, use that encoding for the output stream. This lets us move away from the Python-specific environment variables in the long-term, though we support PYTHONUTF8 here as well for backwards compatability.

(stream)

Source from the content-addressed store, hash-verified

154
155
156def set_preferred_output_encoding(stream):
157 """
158 If the user specified AWS_CLI_OUTPUT_ENCODING, use that encoding
159 for the output stream. This lets us move away from the Python-specific
160 environment variables in the long-term, though we support PYTHONUTF8
161 here as well for backwards compatability.
162 """
163 if OUTPUT_ENCODING_ENV_VAR in os.environ:
164 try:
165 stream.reconfigure(encoding=os.environ[OUTPUT_ENCODING_ENV_VAR])
166 except LookupError:
167 # At this point we don't want to raise the exception, since we
168 # could be writing out another error. Callers should call
169 # validate_preferred_output_encoding first.
170 LOG.debug(
171 f'Ignoring invalid codec '
172 f'{os.environ[OUTPUT_ENCODING_ENV_VAR]} '
173 f'specified for {OUTPUT_ENCODING_ENV_VAR}.'
174 )
175 # Fall back to PYTHONUTF8, for users who were setting it
176 # before the PyInstaller 6 upgrade which stopped supporting it
177 elif (
178 PYTHONUTF8_ENV_VAR in os.environ
179 and os.environ[PYTHONUTF8_ENV_VAR] == '1'
180 ):
181 stream.reconfigure(encoding='UTF-8')
182
183
184def getpreferredencoding(*args, **kwargs):

Callers 2

_get_text_writerFunction · 0.85

Calls

no outgoing calls

Tested by 1