Do not assume UTF-8.

This commit is contained in:
Jakub Roztočil 2012-02-28 18:06:21 +01:00
parent f90ae113e4
commit 0293ba1799

View File

@ -27,10 +27,9 @@ class KeyValueType(object):
self.separators = separators self.separators = separators
def __call__(self, string): def __call__(self, string):
found = dict( found = dict((string.find(sep), sep)
(string.find(sep), sep) for sep in self.separators for sep in self.separators
if string.find(sep) != -1 if string.find(sep) != -1)
)
if not found: if not found:
raise argparse.ArgumentTypeError( raise argparse.ArgumentTypeError(
@ -155,14 +154,15 @@ def main():
sys.exit(1) sys.exit(1)
# Display the response. # Display the response.
encoding = response.encoding or 'ISO-8859-1'
original = response.raw._original_response original = response.raw._original_response
status_line, headers, body = ( status_line, headers, body = (
u'HTTP/{version} {status} {reason}'.format( u'HTTP/{version} {status} {reason}'.format(
version='.'.join(str(original.version)), version='.'.join(str(original.version)),
status=original.status, reason=original.reason, status=original.status, reason=original.reason,
), ),
str(original.msg).decode('utf-8'), str(original.msg).decode(encoding),
response.content.decode('utf-8') if response.content else u'' response.content.decode(encoding) if response.content else u''
) )
if args.prettify and sys.stdout.isatty(): if args.prettify and sys.stdout.isatty():