Skip to content

Commit

Permalink
Remove Python 2 support from SecureTransport makefile function (#2063)
Browse files Browse the repository at this point in the history
  • Loading branch information
hramezani committed Nov 16, 2020
1 parent b6061f0 commit de946a7
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/urllib3/contrib/securetransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import six

from .. import util
from ..packages.backports.makefile import backport_makefile
from ._securetransport.bindings import CoreFoundation, Security, SecurityConst
from ._securetransport.low_level import (
_assert_no_error,
Expand All @@ -76,12 +77,6 @@
_temporary_keychain,
)

try: # Platform-specific: Python 2
from socket import _fileobject
except ImportError: # Platform-specific: Python 3
_fileobject = None
from ..packages.backports.makefile import backport_makefile

__all__ = ["inject_into_urllib3", "extract_from_urllib3"]

# SNI always works
Expand Down Expand Up @@ -761,20 +756,11 @@ def _drop(self):
self._makefile_refs -= 1


if _fileobject: # Platform-specific: Python 2

def makefile(self, mode, bufsize=-1):
self._makefile_refs += 1
return _fileobject(self, mode, bufsize, close=True)


else: # Platform-specific: Python 3

def makefile(self, mode="r", buffering=None, *args, **kwargs):
# We disable buffering with SecureTransport because it conflicts with
# the buffering that ST does internally (see issue #1153 for more).
buffering = 0
return backport_makefile(self, mode, buffering, *args, **kwargs)
def makefile(self, mode="r", buffering=None, *args, **kwargs):
# We disable buffering with SecureTransport because it conflicts with
# the buffering that ST does internally (see issue #1153 for more).
buffering = 0
return backport_makefile(self, mode, buffering, *args, **kwargs)


WrappedSocket.makefile = makefile
Expand Down

0 comments on commit de946a7

Please sign in to comment.