summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickaël Schoentgen <contact@tiger-222.fr>2021-08-05 18:13:22 +0200
committerMickaël Schoentgen <contact@tiger-222.fr>2021-08-05 18:30:21 +0200
commit8922a77156a7dc96bac9e3e94fe900bb17f976c2 (patch)
treef9f8c8ddf84e97b1b4f1f7caf3d752e621cc7d0e
parent3dbb1522d93f24f744cd6665494ce54a04a4a7b8 (diff)
Continue Python 2 removal clean-up
-rw-r--r--http_prompt/contextio.py4
-rw-r--r--http_prompt/execution.py6
-rw-r--r--setup.py10
-rw-r--r--tests/test_execution.py10
4 files changed, 13 insertions, 17 deletions
diff --git a/http_prompt/contextio.py b/http_prompt/contextio.py
index e979939..cb84961 100644
--- a/http_prompt/contextio.py
+++ b/http_prompt/contextio.py
@@ -25,7 +25,7 @@ def load_context(context, file_path=None):
if not file_path:
file_path = _get_context_filepath()
if os.path.exists(file_path):
- with io.open(file_path, encoding='utf-8') as f:
+ with open(file_path, encoding='utf-8') as f:
for line in f:
execute(line, context)
@@ -34,5 +34,5 @@ def save_context(context):
"""Save a Context object to user data directory."""
file_path = _get_context_filepath()
content = format_to_http_prompt(context, excluded_options=EXCLUDED_OPTIONS)
- with io.open(file_path, 'w', encoding='utf-8') as f:
+ with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)
diff --git a/http_prompt/execution.py b/http_prompt/execution.py
index 5417f86..9a66d7a 100644
--- a/http_prompt/execution.py
+++ b/http_prompt/execution.py
@@ -313,7 +313,7 @@ class ExecutionVisitor(NodeVisitor):
def visit_exec(self, node, children):
path = normalize_filepath(children[3])
- with io.open(path, encoding='utf-8') as f:
+ with open(path, encoding='utf-8') as f:
# Wipe out context first
execute('rm *', self.context, self.listener)
for line in f:
@@ -322,7 +322,7 @@ class ExecutionVisitor(NodeVisitor):
def visit_source(self, node, children):
path = normalize_filepath(children[3])
- with io.open(path, encoding='utf-8') as f:
+ with open(path, encoding='utf-8') as f:
for line in f:
execute(line, self.context, self.listener)
return node
@@ -567,7 +567,7 @@ def execute(command, context, listener=None, style=None):
key = re.search(r"KeyError: u?'(.*)'", str(err)).group(1)
click.secho("Key '%s' not found" % key, err=True,
fg='red')
- elif issubclass(exc_class, IOError):
+ elif issubclass(exc_class, OSError):
msg = str(err).splitlines()[0]
# Remove the exception class name at the beginning
diff --git a/setup.py b/setup.py
index 032fe0e..2c1d25b 100644
--- a/setup.py
+++ b/setup.py
@@ -1,10 +1,6 @@
-try:
- from setuptools import setup
-except ImportError:
- from distutils.core import setup
-
import os
import re
+from setuptools import setup
here = os.path.abspath(os.path.dirname(__file__))
@@ -36,8 +32,8 @@ def read_requirements(filename):
try:
with open(filename) as f:
return [line.rstrip() for line in f]
- except IOError:
- raise IOError(os.getcwd())
+ except OSError:
+ raise OSError(os.getcwd())
setup(
diff --git a/tests/test_execution.py b/tests/test_execution.py
index 0f46b32..ecb2063 100644
--- a/tests/test_execution.py
+++ b/tests/test_execution.py
@@ -198,7 +198,7 @@ class TestExecution_env(ExecutionTestCase):
self.context.body_params['name'] = '許 功蓋'
execute('env > %s' % filename, self.context)
- with io.open(filename, encoding='utf-8') as f:
+ with open(filename, encoding='utf-8') as f:
content = f.read()
self.assertEqual(content,
@@ -332,9 +332,9 @@ class TestExecution_source_and_exec(ExecutionTestCase):
# Expect the error message would be the same as when we open the
# non-existing file
try:
- with io.open('no_such_file.txt'):
+ with open('no_such_file.txt'):
pass
- except IOError as err:
+ except OSError as err:
err_msg = str(err)
else:
assert False, 'what?! no_such_file.txt exists!'
@@ -433,9 +433,9 @@ class TestExecution_source_and_exec(ExecutionTestCase):
# Try to get the error message when opening a non-existing file
try:
- with io.open('no_such_file.txt'):
+ with open('no_such_file.txt'):
pass
- except IOError as err:
+ except OSError as err:
err_msg = str(err)
else:
assert False, 'what?! no_such_file.txt exists!'