Skip to content

Commit

Permalink
py27 going, going, gone (#1047)
Browse files Browse the repository at this point in the history
* py27 going, going, gone

* black

* more black

* ok then

* forgot to remove pypy2
  • Loading branch information
reaperhulk authored Oct 4, 2021
1 parent 91d670f commit a42ec20
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 126 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ jobs:
matrix:
PYTHON:
# Base builds
- {VERSION: "2.7", TOXENV: "py27"}
- {VERSION: "3.6", TOXENV: "py36"}
- {VERSION: "3.7", TOXENV: "py37"}
- {VERSION: "3.8", TOXENV: "py38"}
- {VERSION: "3.9", TOXENV: "py39"}
- {VERSION: "pypy2", TOXENV: "pypy"}
- {VERSION: "pypy3", TOXENV: "pypy3"}
# -cryptographyMain
- {VERSION: "3.6", TOXENV: "py36-cryptographyMain"}
Expand All @@ -24,15 +22,12 @@ jobs:
- {VERSION: "3.9", TOXENV: "py39-cryptographyMain"}
- {VERSION: "pypy3", TOXENV: "pypy3-cryptographyMain"}
# -cryptographyMinimum
- {VERSION: "2.7", TOXENV: "py27-cryptographyMinimum"}
- {VERSION: "3.6", TOXENV: "py36-cryptographyMinimum"}
- {VERSION: "3.7", TOXENV: "py37-cryptographyMinimum"}
- {VERSION: "3.8", TOXENV: "py38-cryptographyMinimum"}
- {VERSION: "3.9", TOXENV: "py39-cryptographyMinimum"}
- {VERSION: "pypy2", TOXENV: "pypy-cryptographyMinimum"}
- {VERSION: "pypy3", TOXENV: "pypy3-cryptographyMinimum"}
# Random order
- {VERSION: "2.7", TOXENV: "py27-randomorder"}
- {VERSION: "3.9", TOXENV: "py39-randomorder"}
# Downstreams
- {VERSION: "3.7", TOXENV: "py37-twistedTrunk"}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ The third digit is only for regressions.
Backward-incompatible changes:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Drop support for Python 2.7.
`#1047 </~https://github.com/pyca/pyopenssl/pull/1047>`_

Deprecations:
^^^^^^^^^^^^^

Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ def find_meta(meta):
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
Expand All @@ -89,15 +87,12 @@ def find_meta(meta):
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Networking",
],
python_requires=(
">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*"
),
python_requires=(">=3.6"),
packages=find_packages(where="src"),
package_dir={"": "src"},
install_requires=[
# Fix cryptographyMinimum in tox.ini when changing this!
"cryptography>=3.3",
"six>=1.5.2",
],
extras_require={
"test": ["flaky", "pretend", "pytest>=3.0.1"],
Expand Down
36 changes: 17 additions & 19 deletions src/OpenSSL/SSL.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from weakref import WeakValueDictionary
from errno import errorcode

from six import integer_types, int2byte, indexbytes

from OpenSSL._util import (
UNSPECIFIED as _UNSPECIFIED,
exception_from_error_queue as _exception_from_error_queue,
Expand Down Expand Up @@ -381,7 +379,7 @@ def wrapper(ssl, out, outlen, in_, inlen, arg):
instr = _ffi.buffer(in_, inlen)[:]
protolist = []
while instr:
encoded_len = indexbytes(instr, 0)
encoded_len = instr[0]
proto = instr[1 : encoded_len + 1]
protolist.append(proto)
instr = instr[encoded_len + 1 :]
Expand Down Expand Up @@ -551,15 +549,15 @@ def wrapper(ssl, cdata):

def _asFileDescriptor(obj):
fd = None
if not isinstance(obj, integer_types):
if not isinstance(obj, int):
meth = getattr(obj, "fileno", None)
if meth is not None:
obj = meth()

if isinstance(obj, integer_types):
if isinstance(obj, int):
fd = obj

if not isinstance(fd, integer_types):
if not isinstance(fd, int):
raise TypeError("argument must be an int, or have a fileno() method.")
elif fd < 0:
raise ValueError(
Expand Down Expand Up @@ -653,7 +651,7 @@ class Context(object):
)

def __init__(self, method):
if not isinstance(method, integer_types):
if not isinstance(method, int):
raise TypeError("method must be an integer")

try:
Expand Down Expand Up @@ -897,7 +895,7 @@ def use_certificate_file(self, certfile, filetype=FILETYPE_PEM):
:return: None
"""
certfile = _path_string(certfile)
if not isinstance(filetype, integer_types):
if not isinstance(filetype, int):
raise TypeError("filetype must be an integer")

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

if filetype is _UNSPECIFIED:
filetype = FILETYPE_PEM
elif not isinstance(filetype, integer_types):
elif not isinstance(filetype, int):
raise TypeError("filetype must be an integer")

use_result = _lib.SSL_CTX_use_PrivateKey_file(
Expand Down Expand Up @@ -1035,7 +1033,7 @@ def set_session_cache_mode(self, mode):
.. versionadded:: 0.14
"""
if not isinstance(mode, integer_types):
if not isinstance(mode, int):
raise TypeError("mode must be an integer")

return _lib.SSL_CTX_set_session_cache_mode(self._context, mode)
Expand Down Expand Up @@ -1070,7 +1068,7 @@ def set_verify(self, mode, callback=None):
See SSL_CTX_set_verify(3SSL) for further details.
"""
if not isinstance(mode, integer_types):
if not isinstance(mode, int):
raise TypeError("mode must be an integer")

if callback is None:
Expand All @@ -1093,7 +1091,7 @@ def set_verify_depth(self, depth):
:param depth: An integer specifying the verify depth
:return: None
"""
if not isinstance(depth, integer_types):
if not isinstance(depth, int):
raise TypeError("depth must be an integer")

_lib.SSL_CTX_set_verify_depth(self._context, depth)
Expand Down Expand Up @@ -1253,7 +1251,7 @@ def set_timeout(self, timeout):
:param timeout: The timeout in (whole) seconds
:return: The previous session timeout
"""
if not isinstance(timeout, integer_types):
if not isinstance(timeout, int):
raise TypeError("timeout must be an integer")

return _lib.SSL_CTX_set_timeout(self._context, timeout)
Expand Down Expand Up @@ -1356,7 +1354,7 @@ def set_options(self, options):
:param options: The options to add.
:return: The new option bitmask.
"""
if not isinstance(options, integer_types):
if not isinstance(options, int):
raise TypeError("options must be an integer")

return _lib.SSL_CTX_set_options(self._context, options)
Expand All @@ -1369,7 +1367,7 @@ def set_mode(self, mode):
:param mode: The mode to add.
:return: The new mode bitmask.
"""
if not isinstance(mode, integer_types):
if not isinstance(mode, int):
raise TypeError("mode must be an integer")

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

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

if not isinstance(bufsiz, integer_types):
if not isinstance(bufsiz, int):
raise TypeError("bufsiz must be an integer")

buf = _no_zero_allocator("char[]", bufsiz)
Expand Down Expand Up @@ -2070,7 +2068,7 @@ def set_shutdown(self, state):
:param state: bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN.
:return: None
"""
if not isinstance(state, integer_types):
if not isinstance(state, int):
raise TypeError("state must be an integer")

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

# Build a C string from the list. We don't need to save this off
Expand Down
32 changes: 8 additions & 24 deletions src/OpenSSL/_util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import sys
import warnings

from six import PY2, text_type

from cryptography.hazmat.bindings.openssl.binding import Binding


Expand Down Expand Up @@ -83,14 +81,10 @@ def native(s):
:raise TypeError: The input is neither :py:class:`bytes` nor
:py:class:`unicode`.
"""
if not isinstance(s, (bytes, text_type)):
if not isinstance(s, (bytes, str)):
raise TypeError("%r is neither bytes nor unicode" % s)
if PY2:
if isinstance(s, text_type):
return s.encode("utf-8")
else:
if isinstance(s, bytes):
return s.decode("utf-8")
if isinstance(s, bytes):
return s.decode("utf-8")
return s


Expand All @@ -105,31 +99,21 @@ def path_string(s):
"""
if isinstance(s, bytes):
return s
elif isinstance(s, text_type):
elif isinstance(s, str):
return s.encode(sys.getfilesystemencoding())
else:
raise TypeError("Path must be represented as bytes or unicode string")


if PY2:

def byte_string(s):
return s


else:

def byte_string(s):
return s.encode("charmap")
def byte_string(s):
return s.encode("charmap")


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

_TEXT_WARNING = (
text_type.__name__ + " for {0} is no longer accepted, use bytes"
)
_TEXT_WARNING = "str for {0} is no longer accepted, use bytes"


def text_to_bytes_and_warn(label, obj):
Expand All @@ -145,7 +129,7 @@ def text_to_bytes_and_warn(label, obj):
UTF-8 encoding of that text is returned. Otherwise, ``obj`` itself is
returned.
"""
if isinstance(obj, text_type):
if isinstance(obj, str):
warnings.warn(
_TEXT_WARNING.format(label),
category=DeprecationWarning,
Expand Down
Loading

0 comments on commit a42ec20

Please sign in to comment.