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.
This commit is contained in:
parent
7b95e2f050
commit
117c7cc3db
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
|
|
||||||
from io import BufferedReader
|
from io import BufferedReader, IOBase
|
||||||
|
|
||||||
import six
|
import six
|
||||||
import six.moves.urllib.error as urllib_error
|
import six.moves.urllib.error as urllib_error
|
||||||
@ -23,11 +23,15 @@
|
|||||||
# https://github.com/python/cpython/pull/3249
|
# https://github.com/python/cpython/pull/3249
|
||||||
class WrapStream(BufferedReader):
|
class WrapStream(BufferedReader):
|
||||||
def __init__(self, raw):
|
def __init__(self, raw):
|
||||||
raw.readable = lambda: True
|
# In botocore >=1.23.47, StreamingBody inherits from IOBase, so we
|
||||||
raw.writable = lambda: False
|
# only add missing attributes in older versions.
|
||||||
raw.seekable = lambda: False
|
# https://github.com/boto/botocore/commit/a624815eabac50442ed7404f3c4f2664cd0aa784
|
||||||
raw.closed = False
|
if not isinstance(raw, IOBase):
|
||||||
raw.flush = lambda: None
|
raw.readable = lambda: True
|
||||||
|
raw.writable = lambda: False
|
||||||
|
raw.seekable = lambda: False
|
||||||
|
raw.closed = False
|
||||||
|
raw.flush = lambda: None
|
||||||
super(WrapStream, self).__init__(raw)
|
super(WrapStream, self).__init__(raw)
|
||||||
|
|
||||||
def detach(self):
|
def detach(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user