From f73aaa844f760e171a68e21d7796a62e7ae51c20 Mon Sep 17 00:00:00 2001 From: Alen Mujezinovic Date: Tue, 28 Feb 2012 10:48:29 +0000 Subject: [PATCH 1/4] Syntax error fix --- httpie/httpie.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/httpie/httpie.py b/httpie/httpie.py index 1c8a5aa9..49c35aab 100755 --- a/httpie/httpie.py +++ b/httpie/httpie.py @@ -34,10 +34,11 @@ class KeyValueType(object): self.separators = separators def __call__(self, string): + found = dict([ + (string.find(sep), sep) for sep in self.separators + if string.find(sep) != -1 + ]) - found = {string.find(sep): sep - for sep in self.separators - if string.find(sep) != -1} if not found: raise argparse.ArgumentTypeError( '"%s" is not a valid value' % string) @@ -148,8 +149,8 @@ def main(): verify=True if args.verify == 'yes' else args.verify, timeout=args.timeout, auth=(args.auth.key, args.auth.value) if args.auth else None, - proxies={proxy.key: proxy.value for proxy in args.proxy}, - files={os.path.basename(f.name): f for f in args.file} + proxies=dict([(p.key, p.value) for p in args.proxy]), + files=dict([(os.path.basename(f.name), f) for f in args.file]), ) except (KeyboardInterrupt, SystemExit) as e: sys.stderr.write('\n') From b567104267c4de7b16af1498906cd7fe61d33579 Mon Sep 17 00:00:00 2001 From: Alen Mujezinovic Date: Tue, 28 Feb 2012 13:33:33 +0000 Subject: [PATCH 2/4] Removed the lists in favour of generators --- httpie/httpie.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/httpie/httpie.py b/httpie/httpie.py index 49c35aab..2588c8a1 100755 --- a/httpie/httpie.py +++ b/httpie/httpie.py @@ -34,10 +34,10 @@ class KeyValueType(object): self.separators = separators def __call__(self, string): - found = dict([ + found = dict( (string.find(sep), sep) for sep in self.separators if string.find(sep) != -1 - ]) + ) if not found: raise argparse.ArgumentTypeError( @@ -149,8 +149,8 @@ def main(): verify=True if args.verify == 'yes' else args.verify, timeout=args.timeout, auth=(args.auth.key, args.auth.value) if args.auth else None, - proxies=dict([(p.key, p.value) for p in args.proxy]), - files=dict([(os.path.basename(f.name), f) for f in args.file]), + proxies=dict((p.key, p.value) for p in args.proxy), + files=dict((os.path.basename(f.name), f) for f in args.file), ) except (KeyboardInterrupt, SystemExit) as e: sys.stderr.write('\n') From 2f569b901dcd5852d16a88084af19883ee847f3e Mon Sep 17 00:00:00 2001 From: Alen Mujezinovic Date: Tue, 28 Feb 2012 14:01:01 +0000 Subject: [PATCH 3/4] Not all web servers return UTF-8 and will crash httpie when decoding the response --- httpie/httpie.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/httpie/httpie.py b/httpie/httpie.py index 2588c8a1..55ef83c1 100755 --- a/httpie/httpie.py +++ b/httpie/httpie.py @@ -163,13 +163,22 @@ def main(): # Display the response. original = response.raw._original_response + + try: + decode_from = [ + bit.split('=')[1] for bit in response.headers['content-type'].split(';') + if 'charset' in bit + ][0] + except IndexError: + decode_from = 'utf-8' + status_line, headers, body = ( u'HTTP/{version} {status} {reason}'.format( version='.'.join(str(original.version)), status=original.status, reason=original.reason, ), - str(original.msg).decode('utf-8'), - response.content.decode('utf-8') if response.content else u'' + str(original.msg).decode(decode_from), + response.content.decode(decode_from) if response.content else u'' ) if args.prettify and sys.stdout.isatty(): From 6f9ad9e4e10df653e5d8cd9f70626b809dec71eb Mon Sep 17 00:00:00 2001 From: Alen Mujezinovic Date: Tue, 28 Feb 2012 16:49:53 +0000 Subject: [PATCH 4/4] Revert "Not all web servers return UTF-8 and will crash httpie when decoding the response" This reverts commit 2f569b901dcd5852d16a88084af19883ee847f3e. --- httpie/httpie.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/httpie/httpie.py b/httpie/httpie.py index 55ef83c1..2588c8a1 100755 --- a/httpie/httpie.py +++ b/httpie/httpie.py @@ -163,22 +163,13 @@ def main(): # Display the response. original = response.raw._original_response - - try: - decode_from = [ - bit.split('=')[1] for bit in response.headers['content-type'].split(';') - if 'charset' in bit - ][0] - except IndexError: - decode_from = 'utf-8' - status_line, headers, body = ( u'HTTP/{version} {status} {reason}'.format( version='.'.join(str(original.version)), status=original.status, reason=original.reason, ), - str(original.msg).decode(decode_from), - response.content.decode(decode_from) if response.content else u'' + str(original.msg).decode('utf-8'), + response.content.decode('utf-8') if response.content else u'' ) if args.prettify and sys.stdout.isatty():