Skip to content

Commit a42ec20

Browse files
authored
py27 going, going, gone (#1047)
* py27 going, going, gone * black * more black * ok then * forgot to remove pypy2
1 parent 91d670f commit a42ec20

File tree

8 files changed

+58
-126
lines changed

8 files changed

+58
-126
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ jobs:
1010
matrix:
1111
PYTHON:
1212
# Base builds
13-
- {VERSION: "2.7", TOXENV: "py27"}
1413
- {VERSION: "3.6", TOXENV: "py36"}
1514
- {VERSION: "3.7", TOXENV: "py37"}
1615
- {VERSION: "3.8", TOXENV: "py38"}
1716
- {VERSION: "3.9", TOXENV: "py39"}
18-
- {VERSION: "pypy2", TOXENV: "pypy"}
1917
- {VERSION: "pypy3", TOXENV: "pypy3"}
2018
# -cryptographyMain
2119
- {VERSION: "3.6", TOXENV: "py36-cryptographyMain"}
@@ -24,15 +22,12 @@ jobs:
2422
- {VERSION: "3.9", TOXENV: "py39-cryptographyMain"}
2523
- {VERSION: "pypy3", TOXENV: "pypy3-cryptographyMain"}
2624
# -cryptographyMinimum
27-
- {VERSION: "2.7", TOXENV: "py27-cryptographyMinimum"}
2825
- {VERSION: "3.6", TOXENV: "py36-cryptographyMinimum"}
2926
- {VERSION: "3.7", TOXENV: "py37-cryptographyMinimum"}
3027
- {VERSION: "3.8", TOXENV: "py38-cryptographyMinimum"}
3128
- {VERSION: "3.9", TOXENV: "py39-cryptographyMinimum"}
32-
- {VERSION: "pypy2", TOXENV: "pypy-cryptographyMinimum"}
3329
- {VERSION: "pypy3", TOXENV: "pypy3-cryptographyMinimum"}
3430
# Random order
35-
- {VERSION: "2.7", TOXENV: "py27-randomorder"}
3631
- {VERSION: "3.9", TOXENV: "py39-randomorder"}
3732
# Downstreams
3833
- {VERSION: "3.7", TOXENV: "py37-twistedTrunk"}

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ The third digit is only for regressions.
1010
Backward-incompatible changes:
1111
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13+
- Drop support for Python 2.7.
14+
`#1047 <https://github.com/pyca/pyopenssl/pull/1047>`_
15+
1316
Deprecations:
1417
^^^^^^^^^^^^^
1518

setup.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ def find_meta(meta):
7676
"Operating System :: MacOS :: MacOS X",
7777
"Operating System :: Microsoft :: Windows",
7878
"Operating System :: POSIX",
79-
"Programming Language :: Python :: 2",
80-
"Programming Language :: Python :: 2.7",
8179
"Programming Language :: Python :: 3",
8280
"Programming Language :: Python :: 3.6",
8381
"Programming Language :: Python :: 3.7",
@@ -89,15 +87,12 @@ def find_meta(meta):
8987
"Topic :: Software Development :: Libraries :: Python Modules",
9088
"Topic :: System :: Networking",
9189
],
92-
python_requires=(
93-
">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*"
94-
),
90+
python_requires=(">=3.6"),
9591
packages=find_packages(where="src"),
9692
package_dir={"": "src"},
9793
install_requires=[
9894
# Fix cryptographyMinimum in tox.ini when changing this!
9995
"cryptography>=3.3",
100-
"six>=1.5.2",
10196
],
10297
extras_require={
10398
"test": ["flaky", "pretend", "pytest>=3.0.1"],

src/OpenSSL/SSL.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from weakref import WeakValueDictionary
77
from errno import errorcode
88

9-
from six import integer_types, int2byte, indexbytes
10-
119
from OpenSSL._util import (
1210
UNSPECIFIED as _UNSPECIFIED,
1311
exception_from_error_queue as _exception_from_error_queue,
@@ -381,7 +379,7 @@ def wrapper(ssl, out, outlen, in_, inlen, arg):
381379
instr = _ffi.buffer(in_, inlen)[:]
382380
protolist = []
383381
while instr:
384-
encoded_len = indexbytes(instr, 0)
382+
encoded_len = instr[0]
385383
proto = instr[1 : encoded_len + 1]
386384
protolist.append(proto)
387385
instr = instr[encoded_len + 1 :]
@@ -551,15 +549,15 @@ def wrapper(ssl, cdata):
551549

552550
def _asFileDescriptor(obj):
553551
fd = None
554-
if not isinstance(obj, integer_types):
552+
if not isinstance(obj, int):
555553
meth = getattr(obj, "fileno", None)
556554
if meth is not None:
557555
obj = meth()
558556

559-
if isinstance(obj, integer_types):
557+
if isinstance(obj, int):
560558
fd = obj
561559

562-
if not isinstance(fd, integer_types):
560+
if not isinstance(fd, int):
563561
raise TypeError("argument must be an int, or have a fileno() method.")
564562
elif fd < 0:
565563
raise ValueError(
@@ -653,7 +651,7 @@ class Context(object):
653651
)
654652

655653
def __init__(self, method):
656-
if not isinstance(method, integer_types):
654+
if not isinstance(method, int):
657655
raise TypeError("method must be an integer")
658656

659657
try:
@@ -897,7 +895,7 @@ def use_certificate_file(self, certfile, filetype=FILETYPE_PEM):
897895
:return: None
898896
"""
899897
certfile = _path_string(certfile)
900-
if not isinstance(filetype, integer_types):
898+
if not isinstance(filetype, int):
901899
raise TypeError("filetype must be an integer")
902900

903901
use_result = _lib.SSL_CTX_use_certificate_file(
@@ -958,7 +956,7 @@ def use_privatekey_file(self, keyfile, filetype=_UNSPECIFIED):
958956

959957
if filetype is _UNSPECIFIED:
960958
filetype = FILETYPE_PEM
961-
elif not isinstance(filetype, integer_types):
959+
elif not isinstance(filetype, int):
962960
raise TypeError("filetype must be an integer")
963961

964962
use_result = _lib.SSL_CTX_use_PrivateKey_file(
@@ -1035,7 +1033,7 @@ def set_session_cache_mode(self, mode):
10351033
10361034
.. versionadded:: 0.14
10371035
"""
1038-
if not isinstance(mode, integer_types):
1036+
if not isinstance(mode, int):
10391037
raise TypeError("mode must be an integer")
10401038

10411039
return _lib.SSL_CTX_set_session_cache_mode(self._context, mode)
@@ -1070,7 +1068,7 @@ def set_verify(self, mode, callback=None):
10701068
10711069
See SSL_CTX_set_verify(3SSL) for further details.
10721070
"""
1073-
if not isinstance(mode, integer_types):
1071+
if not isinstance(mode, int):
10741072
raise TypeError("mode must be an integer")
10751073

10761074
if callback is None:
@@ -1093,7 +1091,7 @@ def set_verify_depth(self, depth):
10931091
:param depth: An integer specifying the verify depth
10941092
:return: None
10951093
"""
1096-
if not isinstance(depth, integer_types):
1094+
if not isinstance(depth, int):
10971095
raise TypeError("depth must be an integer")
10981096

10991097
_lib.SSL_CTX_set_verify_depth(self._context, depth)
@@ -1253,7 +1251,7 @@ def set_timeout(self, timeout):
12531251
:param timeout: The timeout in (whole) seconds
12541252
:return: The previous session timeout
12551253
"""
1256-
if not isinstance(timeout, integer_types):
1254+
if not isinstance(timeout, int):
12571255
raise TypeError("timeout must be an integer")
12581256

12591257
return _lib.SSL_CTX_set_timeout(self._context, timeout)
@@ -1356,7 +1354,7 @@ def set_options(self, options):
13561354
:param options: The options to add.
13571355
:return: The new option bitmask.
13581356
"""
1359-
if not isinstance(options, integer_types):
1357+
if not isinstance(options, int):
13601358
raise TypeError("options must be an integer")
13611359

13621360
return _lib.SSL_CTX_set_options(self._context, options)
@@ -1369,7 +1367,7 @@ def set_mode(self, mode):
13691367
:param mode: The mode to add.
13701368
:return: The new mode bitmask.
13711369
"""
1372-
if not isinstance(mode, integer_types):
1370+
if not isinstance(mode, int):
13731371
raise TypeError("mode must be an integer")
13741372

13751373
return _lib.SSL_CTX_set_mode(self._context, mode)
@@ -1426,7 +1424,7 @@ def set_alpn_protos(self, protos):
14261424
# Take the list of protocols and join them together, prefixing them
14271425
# with their lengths.
14281426
protostr = b"".join(
1429-
chain.from_iterable((int2byte(len(p)), p) for p in protos)
1427+
chain.from_iterable((bytes((len(p),)), p) for p in protos)
14301428
)
14311429

14321430
# Build a C string from the list. We don't need to save this off
@@ -1839,7 +1837,7 @@ def bio_read(self, bufsiz):
18391837
if self._from_ssl is None:
18401838
raise TypeError("Connection sock was not None")
18411839

1842-
if not isinstance(bufsiz, integer_types):
1840+
if not isinstance(bufsiz, int):
18431841
raise TypeError("bufsiz must be an integer")
18441842

18451843
buf = _no_zero_allocator("char[]", bufsiz)
@@ -2070,7 +2068,7 @@ def set_shutdown(self, state):
20702068
:param state: bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN.
20712069
:return: None
20722070
"""
2073-
if not isinstance(state, integer_types):
2071+
if not isinstance(state, int):
20742072
raise TypeError("state must be an integer")
20752073

20762074
_lib.SSL_set_shutdown(self._ssl, state)
@@ -2454,7 +2452,7 @@ def set_alpn_protos(self, protos):
24542452
# Take the list of protocols and join them together, prefixing them
24552453
# with their lengths.
24562454
protostr = b"".join(
2457-
chain.from_iterable((int2byte(len(p)), p) for p in protos)
2455+
chain.from_iterable((bytes((len(p),)), p) for p in protos)
24582456
)
24592457

24602458
# Build a C string from the list. We don't need to save this off

src/OpenSSL/_util.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import sys
22
import warnings
33

4-
from six import PY2, text_type
5-
64
from cryptography.hazmat.bindings.openssl.binding import Binding
75

86

@@ -83,14 +81,10 @@ def native(s):
8381
:raise TypeError: The input is neither :py:class:`bytes` nor
8482
:py:class:`unicode`.
8583
"""
86-
if not isinstance(s, (bytes, text_type)):
84+
if not isinstance(s, (bytes, str)):
8785
raise TypeError("%r is neither bytes nor unicode" % s)
88-
if PY2:
89-
if isinstance(s, text_type):
90-
return s.encode("utf-8")
91-
else:
92-
if isinstance(s, bytes):
93-
return s.decode("utf-8")
86+
if isinstance(s, bytes):
87+
return s.decode("utf-8")
9488
return s
9589

9690

@@ -105,31 +99,21 @@ def path_string(s):
10599
"""
106100
if isinstance(s, bytes):
107101
return s
108-
elif isinstance(s, text_type):
102+
elif isinstance(s, str):
109103
return s.encode(sys.getfilesystemencoding())
110104
else:
111105
raise TypeError("Path must be represented as bytes or unicode string")
112106

113107

114-
if PY2:
115-
116-
def byte_string(s):
117-
return s
118-
119-
120-
else:
121-
122-
def byte_string(s):
123-
return s.encode("charmap")
108+
def byte_string(s):
109+
return s.encode("charmap")
124110

125111

126112
# A marker object to observe whether some optional arguments are passed any
127113
# value or not.
128114
UNSPECIFIED = object()
129115

130-
_TEXT_WARNING = (
131-
text_type.__name__ + " for {0} is no longer accepted, use bytes"
132-
)
116+
_TEXT_WARNING = "str for {0} is no longer accepted, use bytes"
133117

134118

135119
def text_to_bytes_and_warn(label, obj):
@@ -145,7 +129,7 @@ def text_to_bytes_and_warn(label, obj):
145129
UTF-8 encoding of that text is returned. Otherwise, ``obj`` itself is
146130
returned.
147131
"""
148-
if isinstance(obj, text_type):
132+
if isinstance(obj, str):
149133
warnings.warn(
150134
_TEXT_WARNING.format(label),
151135
category=DeprecationWarning,

0 commit comments

Comments
 (0)