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)
| 154 | |
| 155 | |
| 156 | def 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 | |
| 184 | def getpreferredencoding(*args, **kwargs): |
no outgoing calls