You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-08-10 22:42:05 +02:00
Review OSError exceptions handling (#1080)
- Replace obsolete `IOError` (Python 2) with `OSError`, cf https://docs.python.org/3/library/exceptions.html#OSError. - Improve `OSError` catches at different places, simplifying the code.
This commit is contained in:
committed by
GitHub
parent
a61f9e1114
commit
8374a9ed83
@@ -176,7 +176,7 @@ class HTTPieArgumentParser(argparse.ArgumentParser):
|
||||
self.args.output_file.seek(0)
|
||||
try:
|
||||
self.args.output_file.truncate()
|
||||
except IOError as e:
|
||||
except OSError as e:
|
||||
if e.errno == errno.EINVAL:
|
||||
# E.g. /dev/null on Linux.
|
||||
pass
|
||||
|
@@ -180,8 +180,8 @@ def readable_file_arg(filename):
|
||||
try:
|
||||
with open(filename, 'rb'):
|
||||
return filename
|
||||
except IOError as ex:
|
||||
raise argparse.ArgumentTypeError(f'{filename}: {ex.args[1]}')
|
||||
except OSError as ex:
|
||||
raise argparse.ArgumentTypeError(f'{ex.filename}: {ex.strerror}')
|
||||
|
||||
|
||||
def parse_format_options(s: str, defaults: Optional[dict]) -> dict:
|
||||
|
@@ -106,7 +106,7 @@ def process_file_upload_arg(arg: KeyValueArg) -> Tuple[str, IO, str]:
|
||||
mime_type = parts[1] if len(parts) > 1 else None
|
||||
try:
|
||||
f = open(os.path.expanduser(filename), 'rb')
|
||||
except IOError as e:
|
||||
except OSError as e:
|
||||
raise ParseError(f'{arg.orig!r}: {e}')
|
||||
return (
|
||||
os.path.basename(filename),
|
||||
@@ -139,7 +139,7 @@ def load_text_file(item: KeyValueArg) -> str:
|
||||
try:
|
||||
with open(os.path.expanduser(path), 'rb') as f:
|
||||
return f.read().decode()
|
||||
except IOError as e:
|
||||
except OSError as e:
|
||||
raise ParseError(f'{item.orig!r}: {e}')
|
||||
except UnicodeDecodeError:
|
||||
raise ParseError(
|
||||
|
Reference in New Issue
Block a user