From 371c7ee88b59c7d609eec2f89fa67b288ac26223 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Wed, 15 Jul 2020 09:18:52 +1000 Subject: [PATCH] Removed six package and other older py cleanup values --- README.txt | 2 +- gssapi/_utils.py | 22 ++++------------------ gssapi/mechs.py | 12 +++--------- gssapi/names.py | 24 +++++++----------------- gssapi/raw/ext_dce.pyx | 7 +------ gssapi/raw/oids.pyx | 8 +------- gssapi/raw/types.pyx | 6 +----- gssapi/sec_contexts.py | 6 ++---- gssapi/tests/test_high_level.py | 13 ++++++------- gssapi/tests/test_raw.py | 6 +----- setup.py | 3 --- test-requirements.txt | 1 - tox.ini | 2 +- 13 files changed, 28 insertions(+), 84 deletions(-) diff --git a/README.txt b/README.txt index 8a24242d..3df6a6f9 100644 --- a/README.txt +++ b/README.txt @@ -38,7 +38,7 @@ Basic * Python 3.6+ (older releases support older versions, but are unsupported) -* the `six` and `decorator` python packages +* the `decorator` python packages Compiling from Scratch ---------------------- diff --git a/gssapi/_utils.py b/gssapi/_utils.py index 0ad752ec..42357edd 100644 --- a/gssapi/_utils.py +++ b/gssapi/_utils.py @@ -1,7 +1,6 @@ import sys import types -import six import decorator as deco from typing import Optional @@ -103,12 +102,12 @@ def set_encoding(enc): def _encode_dict(d): """Encodes any relevant strings in a dict""" def enc(x): - if isinstance(x, six.text_type): + if isinstance(x, str): return x.encode(_ENCODING) else: return x - return dict((enc(k), enc(v)) for k, v in six.iteritems(d)) + return dict((enc(k), enc(v)) for k, v in iter(d.items())) # in case of Python 3, just use exception chaining @@ -131,10 +130,7 @@ def catch_and_return_token(func, self, *args, **kwargs): if e.token is not None and self.__DEFER_STEP_ERRORS__: self._last_err = e # skip the "return func" line above in the traceback - if six.PY2: - self._last_tb = sys.exc_info()[2].tb_next.tb_next - else: - self._last_err.__traceback__ = e.__traceback__.tb_next + self._last_err.__traceback__ = e.__traceback__.tb_next return e.token else: @@ -152,18 +148,8 @@ def check_last_err(func, self, *args, **kwargs): if self._last_err is not None: try: - if six.PY2: - six.reraise(type(self._last_err), self._last_err, - self._last_tb) - else: - # NB(directxman12): not using six.reraise in Python 3 leads - # to cleaner tracebacks, and raise x is valid - # syntax in Python 3 (unlike raise x, y, z) - raise self._last_err + raise self._last_err finally: - if six.PY2: - del self._last_tb # in case of cycles, break glass - self._last_err = None else: return func(self, *args, **kwargs) diff --git a/gssapi/mechs.py b/gssapi/mechs.py index c00f9bfb..5e6b6825 100644 --- a/gssapi/mechs.py +++ b/gssapi/mechs.py @@ -1,5 +1,3 @@ -import six - from gssapi.raw import oids as roids from gssapi._utils import import_gssapi_extension from gssapi.raw import misc as rmisc @@ -45,11 +43,7 @@ def _attrs(self): return rfc5587.inquire_attrs_for_mech(self) def __str__(self): - if issubclass(str, six.text_type): - # Python 3 -- we should return unicode - return self._bytes_desc().decode(_utils._get_encoding()) - else: - return self._bytes_desc() + return self._bytes_desc().decode(_utils._get_encoding()) def __unicode__(self): return self._bytes_desc().decode(_utils._get_encoding()) @@ -59,7 +53,7 @@ def _bytes_desc(self): if rfc5801 is not None and self._saslname and self._saslname.mech_name: base = self._saslname.mech_name - if isinstance(base, six.text_type): + if isinstance(base, str): base = base.encode(_utils._get_encoding()) return base @@ -156,7 +150,7 @@ def from_sasl_name(cls, name=None): if rfc5801 is None: raise NotImplementedError("Your GSSAPI implementation does not " "have support for RFC 5801") - if isinstance(name, six.text_type): + if isinstance(name, str): name = name.encode(_utils._get_encoding()) m = rfc5801.inquire_mech_for_saslname(name) diff --git a/gssapi/names.py b/gssapi/names.py index ee7a1db1..acd4b8bd 100644 --- a/gssapi/names.py +++ b/gssapi/names.py @@ -1,14 +1,9 @@ -import six - from gssapi.raw import names as rname from gssapi.raw import NameType from gssapi.raw import named_tuples as tuples from gssapi import _utils -if six.PY2: - from collections import MutableMapping, Iterable -else: - from collections.abc import MutableMapping, Iterable +from collections.abc import MutableMapping, Iterable rname_rfc6680 = _utils.import_gssapi_extension('rfc6680') @@ -69,7 +64,7 @@ def __new__(cls, base=None, name_type=None, token=None, elif isinstance(base, rname.Name): base_name = base else: - if isinstance(base, six.text_type): + if isinstance(base, str): base = base.encode(_utils._get_encoding()) base_name = rname.import_name(base, name_type) @@ -107,12 +102,7 @@ def __init__(self, base=None, name_type=None, token=None, composite=False): self._attr_obj = None def __str__(self): - if issubclass(str, six.text_type): - # Python 3 -- we should return unicode - return bytes(self).decode(_utils._get_encoding()) - else: - # Python 2 -- we should return a string - return self.__bytes__() + return bytes(self).decode(_utils._get_encoding()) def __unicode__(self): # Python 2 -- someone asked for unicode @@ -324,7 +314,7 @@ def __init__(self, name): self._name = name def __getitem__(self, key): - if isinstance(key, six.text_type): + if isinstance(key, str): key = key.encode(_utils._get_encoding()) res = rname_rfc6680.get_name_attribute(self._name, key) @@ -334,7 +324,7 @@ def __getitem__(self, key): res.complete) def __setitem__(self, key, value): - if isinstance(key, six.text_type): + if isinstance(key, str): key = key.encode(_utils._get_encoding()) rname_rfc6680.delete_name_attribute(self._name, key) @@ -348,7 +338,7 @@ def __setitem__(self, key, value): else: complete = False - if (isinstance(value, (six.string_types, bytes)) or + if (isinstance(value, (str, bytes)) or not isinstance(value, Iterable)): # NB(directxman12): this allows us to easily assign a single # value, since that's a common case @@ -358,7 +348,7 @@ def __setitem__(self, key, value): complete=complete) def __delitem__(self, key): - if isinstance(key, six.text_type): + if isinstance(key, str): key = key.encode(_utils._get_encoding()) rname_rfc6680.delete_name_attribute(self._name, key) diff --git a/gssapi/raw/ext_dce.pyx b/gssapi/raw/ext_dce.pyx index afc56545..52d87e5d 100644 --- a/gssapi/raw/ext_dce.pyx +++ b/gssapi/raw/ext_dce.pyx @@ -10,16 +10,11 @@ from gssapi.raw.misc import GSSError from gssapi.raw import types as gssapi_types from gssapi.raw.named_tuples import IOVUnwrapResult, WrapResult, UnwrapResult from collections import namedtuple +from collections.abc import Sequence from enum import IntEnum -import six from gssapi.raw._enum_extensions import ExtendableEnum -if six.PY2: - from collections import Sequence -else: - from collections.abc import Sequence - cdef extern from "python_gssapi_ext.h": # NB(directxman12): this wiki page has a different argument order diff --git a/gssapi/raw/oids.pyx b/gssapi/raw/oids.pyx index 2f133da1..b0bd5546 100644 --- a/gssapi/raw/oids.pyx +++ b/gssapi/raw/oids.pyx @@ -1,7 +1,5 @@ GSSAPI="BASE" # This ensures that a full module is generated by Cython -import six - from libc.string cimport memcmp, memcpy from libc.stdlib cimport free, malloc @@ -97,7 +95,7 @@ cdef class OID: ValueError: the sequence is less than two elements long """ - if isinstance(integer_sequence, six.string_types): + if isinstance(integer_sequence, str): integer_sequence = integer_sequence.split('.') oid_seq = [int(x) for x in integer_sequence] @@ -134,10 +132,6 @@ cdef class OID: def _decode_asn1ber(self): ber_encoding = self.__bytes__() - # NB(directxman12): indexing a byte string yields an int in Python 3, - # but yields a substring in Python 2 - if six.PY2: - ber_encoding = [ord(c) for c in ber_encoding] decoded = [ber_encoding[0] // 40, ber_encoding[0] % 40] pos = 1 diff --git a/gssapi/raw/types.pyx b/gssapi/raw/types.pyx index 5a2ca053..d2013fb9 100644 --- a/gssapi/raw/types.pyx +++ b/gssapi/raw/types.pyx @@ -11,12 +11,8 @@ import collections import copy import numbers import operator -import six -if six.PY2: - from collections import MutableSet -else: - from collections.abc import MutableSet +from collections.abc import MutableSet class NameType(object): diff --git a/gssapi/sec_contexts.py b/gssapi/sec_contexts.py index 9f8ec31c..a1893d98 100644 --- a/gssapi/sec_contexts.py +++ b/gssapi/sec_contexts.py @@ -1,5 +1,3 @@ -import six - from gssapi.raw import sec_contexts as rsec_contexts from gssapi.raw import message as rmessage from gssapi.raw import named_tuples as tuples @@ -11,8 +9,8 @@ from gssapi.creds import Credentials -@six.add_metaclass(_utils.CheckLastError) -class SecurityContext(rsec_contexts.SecurityContext): +class SecurityContext(rsec_contexts.SecurityContext, + metaclass=_utils.CheckLastError): """A GSSAPI Security Context This class represents a GSSAPI security context that may be used diff --git a/gssapi/tests/test_high_level.py b/gssapi/tests/test_high_level.py index a3137c32..feaddaba 100644 --- a/gssapi/tests/test_high_level.py +++ b/gssapi/tests/test_high_level.py @@ -5,7 +5,6 @@ import pickle import should_be.all # noqa -import six from parameterized import parameterized from gssapi import creds as gsscreds @@ -388,10 +387,10 @@ def test_sasl_properties(self): # Note that some mechanisms don't have SASL names or SASL # descriptions; in this case, GSSAPI returns empty strings. if mech.sasl_name: - mech.sasl_name.should_be_a(six.text_type) + mech.sasl_name.should_be_a(str) if mech.description: - mech.description.should_be_a(six.text_type) + mech.description.should_be_a(str) cmp_mech = gssmechs.Mechanism.from_sasl_name(mech.sasl_name) str(cmp_mech).should_be(str(mech)) @@ -467,8 +466,8 @@ def test_display_as(self): gb.NameType.hostbased_service) princ_str = SERVICE_PRINCIPAL.decode('utf-8') + '@' - six.text_type(canonical_name).should_be(princ_str) - krb_name.should_be_a(six.text_type) + str(canonical_name).should_be(princ_str) + krb_name.should_be_a(str) krb_name.should_be(princ_str) @ktu.gssapi_extension_test('rfc6680', 'RFC 6680') @@ -526,9 +525,9 @@ def test_to_str(self): def test_to_unicode(self): name = gssnames.Name(SERVICE_PRINCIPAL, gb.NameType.kerberos_principal) - name_str = six.text_type(name) + name_str = str(name) - name_str.should_be_a(six.text_type) + name_str.should_be_a(str) name_str.should_be(SERVICE_PRINCIPAL.decode(gssutils._get_encoding())) def test_to_bytes(self): diff --git a/gssapi/tests/test_raw.py b/gssapi/tests/test_raw.py index 74cf6ee6..bfa5f550 100644 --- a/gssapi/tests/test_raw.py +++ b/gssapi/tests/test_raw.py @@ -3,7 +3,6 @@ import socket import unittest -import six import should_be.all # noqa import gssapi.raw as gb @@ -11,10 +10,7 @@ import k5test.unit as ktu import k5test as kt -if six.PY2: - from collections import Set -else: - from collections.abc import Set +from collections.abc import Set TARGET_SERVICE_NAME = b'host' diff --git a/setup.py b/setup.py index c7d52146..7cd3d9b7 100755 --- a/setup.py +++ b/setup.py @@ -288,10 +288,7 @@ def gssapi_modules(lst): install_requires = [ 'decorator', - 'six >= 1.4.0' ] -if sys.version_info < (3, 4): - install_requires.append('enum34') setup( name='gssapi', diff --git a/test-requirements.txt b/test-requirements.txt index 422e6cbc..57adc2b0 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,6 @@ flake8 nose parameterized shouldbe -six Cython k5test decorator diff --git a/tox.ini b/tox.ini index cb9a385a..30da1a0a 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py27,py33,py34,py35,py36,py37 +envlist = py36,py37,py38 [testenv] whitelist_externals=bash