diff --git a/gnupg/_util.py b/gnupg/_util.py index c9c288c..9a7bc1b 100644 --- a/gnupg/_util.py +++ b/gnupg/_util.py @@ -40,13 +40,15 @@ _STREAMLIKE_TYPES = [] # These StringIO classes are actually utilised. try: + import io from io import StringIO from io import BytesIO except ImportError: from cStringIO import StringIO else: - _STREAMLIKE_TYPES.append(BytesIO) - _STREAMLIKE_TYPES.append(StringIO) + # The io.IOBase type covers the above example for an open file handle in + # Python3, as well as both io.BytesIO and io.StringIO. + _STREAMLIKE_TYPES.append(io.IOBase) # The remaining StringIO classes which are imported are used to determine if a # object is a stream-like in :func:`_is_stream`. @@ -65,6 +67,20 @@ if sys.version_info.major == 2: _STREAMLIKE_TYPES.append(_cStringIO.InputType) _STREAMLIKE_TYPES.append(_cStringIO.OutputType) + # In Python2: + # + # >>> type(open('README.md', 'rb')) + # + # + # whereas, in Python3, the `file` builtin doesn't exist and instead we get: + # + # >>> type(open('README.md', 'rb')) + # <_io.BufferedReader name='README.md'> + # + # which is covered by the above addition of io.IOBase. + _STREAMLIKE_TYPES.append(file) + + from . import _logger