summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChang-Hung Liang <eliang.cs@gmail.com>2017-03-28 17:21:50 +0800
committerChang-Hung Liang <eliang.cs@gmail.com>2017-03-28 17:21:50 +0800
commitaceabbdaa5242b33b6a3176eb41d7e83b2d3a9e1 (patch)
tree7de8b2efc44db5f701e20f0502cf891161f82fd2
parent91417ed8df3c72cac7aa6f2935e42c3b6dd24115 (diff)
Fix urlopen in Python 2
-rw-r--r--http_prompt/cli.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/http_prompt/cli.py b/http_prompt/cli.py
index 7f67786..c4cc6f2 100644
--- a/http_prompt/cli.py
+++ b/http_prompt/cli.py
@@ -104,14 +104,17 @@ def cli(spec, url, http_options):
os.environ['LESS'] = '-RXF'
if spec:
- with urlopen(spec) as f:
- content = f.read().decode('utf-8')
+ f = urlopen(spec)
try:
- spec = json.loads(content)
- except json.JSONDecodeError:
- click.secho("Warning: Specification file '%s' is not JSON" %
- spec, err=True, fg='red')
- spec = None
+ content = f.read().decode('utf-8')
+ try:
+ spec = json.loads(content)
+ except json.JSONDecodeError:
+ click.secho("Warning: Specification file '%s' is not JSON" %
+ spec, err=True, fg='red')
+ spec = None
+ finally:
+ f.close()
url = fix_incomplete_url(url)
context = Context(url, spec=spec)