diff options
author | Jonathon Anderson <17242663+blue42u@users.noreply.github.com> | 2022-07-18 01:40:13 -0500 |
---|---|---|
committer | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2022-07-20 08:10:41 +0200 |
commit | 1bbf2fa93e863e299985ff520e63b97959523801 (patch) | |
tree | 39739eae8eb86b557458d03f3d9b5482b1b43f01 | |
parent | 67f2d64a3f57e81564549042bcf2111baa0416ed (diff) | |
download | spack-1bbf2fa93e863e299985ff520e63b97959523801.tar.gz spack-1bbf2fa93e863e299985ff520e63b97959523801.tar.bz2 spack-1bbf2fa93e863e299985ff520e63b97959523801.tar.xz spack-1bbf2fa93e863e299985ff520e63b97959523801.zip |
Only hack botocore when needed (#31610)
Newer versions of botocore (>=1.23.47) support the full IOBase
interface, so the hacks added to supplement the missing attributes are
no longer needed. Conditionally disable the hacks if they appear to be
unnecessary based on the class hierarchy found at runtime.
-rw-r--r-- | lib/spack/spack/s3_handler.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/spack/spack/s3_handler.py b/lib/spack/spack/s3_handler.py index 9f775abafb..932ba4611d 100644 --- a/lib/spack/spack/s3_handler.py +++ b/lib/spack/spack/s3_handler.py @@ -3,7 +3,7 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) -from io import BufferedReader +from io import BufferedReader, IOBase import six import six.moves.urllib.error as urllib_error @@ -23,11 +23,15 @@ import spack.util.url as url_util # https://github.com/python/cpython/pull/3249 class WrapStream(BufferedReader): def __init__(self, raw): - raw.readable = lambda: True - raw.writable = lambda: False - raw.seekable = lambda: False - raw.closed = False - raw.flush = lambda: None + # In botocore >=1.23.47, StreamingBody inherits from IOBase, so we + # only add missing attributes in older versions. + # https://github.com/boto/botocore/commit/a624815eabac50442ed7404f3c4f2664cd0aa784 + if not isinstance(raw, IOBase): + raw.readable = lambda: True + raw.writable = lambda: False + raw.seekable = lambda: False + raw.closed = False + raw.flush = lambda: None super(WrapStream, self).__init__(raw) def detach(self): |