From 8922a77156a7dc96bac9e3e94fe900bb17f976c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Schoentgen?= Date: Thu, 5 Aug 2021 18:13:22 +0200 Subject: Continue Python 2 removal clean-up --- http_prompt/contextio.py | 4 ++-- http_prompt/execution.py | 6 +++--- setup.py | 10 +++------- tests/test_execution.py | 10 +++++----- 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!' -- cgit v1.2.3