1
0
mirror of https://github.com/httpie/cli.git synced 2025-08-10 22:42:05 +02:00

Implemented more robust unicode handling.

* Immediatelly convert all args from `bytes` to `str`.
* Added `Environment.stdin_encoding` and `Environment.stdout_encoding`
* Allow unicode characters in HTTP headers and basic auth credentials
  by encoding them using UTF8 instead of latin1 (#212).
This commit is contained in:
Jakub Roztocil
2014-04-26 15:06:51 +02:00
parent 5c29a4e551
commit 15e62ad26d
14 changed files with 177 additions and 39 deletions

View File

@@ -40,11 +40,27 @@ class Environment(object):
stdout = sys.stdout
stderr = sys.stderr
stdin_encoding = None
stdout_encoding = None
def __init__(self, **kwargs):
assert all(hasattr(type(self), attr)
for attr in kwargs.keys())
self.__dict__.update(**kwargs)
if self.stdin_encoding is None:
self.stdin_encoding = getattr(
self.stdin, 'encoding', None) or 'utf8'
if self.stdout_encoding is None:
actual_stdout = self.stdout
if is_windows:
from colorama import AnsiToWin32
if isinstance(AnsiToWin32, self.stdout):
actual_stdout = self.stdout.wrapped
self.stdout_encoding = getattr(
actual_stdout, 'encoding', None) or 'utf8'
@property
def config(self):
if not hasattr(self, '_config'):