Skip to content

Commit dac08a8

Browse files
jborean93frozencemetery
authored andcommitted
Removed six package and other older py cleanup values
Resolves: #221 [[email protected]: cleaned up a couple idioms]
1 parent 4f50c26 commit dac08a8

13 files changed

+28
-84
lines changed

README.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Basic
3838

3939
* Python 3.6+ (older releases support older versions, but are unsupported)
4040

41-
* the `six` and `decorator` python packages
41+
* the `decorator` python package
4242

4343
Compiling from Scratch
4444
----------------------

gssapi/_utils.py

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
22
import types
33

4-
import six
54
import decorator as deco
65

76
from typing import Optional
@@ -103,12 +102,12 @@ def set_encoding(enc):
103102
def _encode_dict(d):
104103
"""Encodes any relevant strings in a dict"""
105104
def enc(x):
106-
if isinstance(x, six.text_type):
105+
if isinstance(x, str):
107106
return x.encode(_ENCODING)
108107
else:
109108
return x
110109

111-
return dict((enc(k), enc(v)) for k, v in six.iteritems(d))
110+
return {enc(k): enc(v) for k, v in d.items()}
112111

113112

114113
# in case of Python 3, just use exception chaining
@@ -131,10 +130,7 @@ def catch_and_return_token(func, self, *args, **kwargs):
131130
if e.token is not None and self.__DEFER_STEP_ERRORS__:
132131
self._last_err = e
133132
# skip the "return func" line above in the traceback
134-
if six.PY2:
135-
self._last_tb = sys.exc_info()[2].tb_next.tb_next
136-
else:
137-
self._last_err.__traceback__ = e.__traceback__.tb_next
133+
self._last_err.__traceback__ = e.__traceback__.tb_next
138134

139135
return e.token
140136
else:
@@ -152,18 +148,8 @@ def check_last_err(func, self, *args, **kwargs):
152148

153149
if self._last_err is not None:
154150
try:
155-
if six.PY2:
156-
six.reraise(type(self._last_err), self._last_err,
157-
self._last_tb)
158-
else:
159-
# NB(directxman12): not using six.reraise in Python 3 leads
160-
# to cleaner tracebacks, and raise x is valid
161-
# syntax in Python 3 (unlike raise x, y, z)
162-
raise self._last_err
151+
raise self._last_err
163152
finally:
164-
if six.PY2:
165-
del self._last_tb # in case of cycles, break glass
166-
167153
self._last_err = None
168154
else:
169155
return func(self, *args, **kwargs)

gssapi/mechs.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import six
2-
31
from gssapi.raw import oids as roids
42
from gssapi._utils import import_gssapi_extension
53
from gssapi.raw import misc as rmisc
@@ -45,11 +43,7 @@ def _attrs(self):
4543
return rfc5587.inquire_attrs_for_mech(self)
4644

4745
def __str__(self):
48-
if issubclass(str, six.text_type):
49-
# Python 3 -- we should return unicode
50-
return self._bytes_desc().decode(_utils._get_encoding())
51-
else:
52-
return self._bytes_desc()
46+
return self._bytes_desc().decode(_utils._get_encoding())
5347

5448
def __unicode__(self):
5549
return self._bytes_desc().decode(_utils._get_encoding())
@@ -59,7 +53,7 @@ def _bytes_desc(self):
5953
if rfc5801 is not None and self._saslname and self._saslname.mech_name:
6054
base = self._saslname.mech_name
6155

62-
if isinstance(base, six.text_type):
56+
if isinstance(base, str):
6357
base = base.encode(_utils._get_encoding())
6458

6559
return base
@@ -156,7 +150,7 @@ def from_sasl_name(cls, name=None):
156150
if rfc5801 is None:
157151
raise NotImplementedError("Your GSSAPI implementation does not "
158152
"have support for RFC 5801")
159-
if isinstance(name, six.text_type):
153+
if isinstance(name, str):
160154
name = name.encode(_utils._get_encoding())
161155

162156
m = rfc5801.inquire_mech_for_saslname(name)

gssapi/names.py

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import six
2-
31
from gssapi.raw import names as rname
42
from gssapi.raw import NameType
53
from gssapi.raw import named_tuples as tuples
64
from gssapi import _utils
75

8-
if six.PY2:
9-
from collections import MutableMapping, Iterable
10-
else:
11-
from collections.abc import MutableMapping, Iterable
6+
from collections.abc import MutableMapping, Iterable
127

138

149
rname_rfc6680 = _utils.import_gssapi_extension('rfc6680')
@@ -69,7 +64,7 @@ def __new__(cls, base=None, name_type=None, token=None,
6964
elif isinstance(base, rname.Name):
7065
base_name = base
7166
else:
72-
if isinstance(base, six.text_type):
67+
if isinstance(base, str):
7368
base = base.encode(_utils._get_encoding())
7469

7570
base_name = rname.import_name(base, name_type)
@@ -107,12 +102,7 @@ def __init__(self, base=None, name_type=None, token=None, composite=False):
107102
self._attr_obj = None
108103

109104
def __str__(self):
110-
if issubclass(str, six.text_type):
111-
# Python 3 -- we should return unicode
112-
return bytes(self).decode(_utils._get_encoding())
113-
else:
114-
# Python 2 -- we should return a string
115-
return self.__bytes__()
105+
return bytes(self).decode(_utils._get_encoding())
116106

117107
def __unicode__(self):
118108
# Python 2 -- someone asked for unicode
@@ -324,7 +314,7 @@ def __init__(self, name):
324314
self._name = name
325315

326316
def __getitem__(self, key):
327-
if isinstance(key, six.text_type):
317+
if isinstance(key, str):
328318
key = key.encode(_utils._get_encoding())
329319

330320
res = rname_rfc6680.get_name_attribute(self._name, key)
@@ -334,7 +324,7 @@ def __getitem__(self, key):
334324
res.complete)
335325

336326
def __setitem__(self, key, value):
337-
if isinstance(key, six.text_type):
327+
if isinstance(key, str):
338328
key = key.encode(_utils._get_encoding())
339329

340330
rname_rfc6680.delete_name_attribute(self._name, key)
@@ -348,7 +338,7 @@ def __setitem__(self, key, value):
348338
else:
349339
complete = False
350340

351-
if (isinstance(value, (six.string_types, bytes)) or
341+
if (isinstance(value, (str, bytes)) or
352342
not isinstance(value, Iterable)):
353343
# NB(directxman12): this allows us to easily assign a single
354344
# value, since that's a common case
@@ -358,7 +348,7 @@ def __setitem__(self, key, value):
358348
complete=complete)
359349

360350
def __delitem__(self, key):
361-
if isinstance(key, six.text_type):
351+
if isinstance(key, str):
362352
key = key.encode(_utils._get_encoding())
363353

364354
rname_rfc6680.delete_name_attribute(self._name, key)

gssapi/raw/ext_dce.pyx

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ from gssapi.raw.misc import GSSError
1010
from gssapi.raw import types as gssapi_types
1111
from gssapi.raw.named_tuples import IOVUnwrapResult, WrapResult, UnwrapResult
1212
from collections import namedtuple
13+
from collections.abc import Sequence
1314

1415
from enum import IntEnum
15-
import six
1616
from gssapi.raw._enum_extensions import ExtendableEnum
1717

18-
if six.PY2:
19-
from collections import Sequence
20-
else:
21-
from collections.abc import Sequence
22-
2318

2419
cdef extern from "python_gssapi_ext.h":
2520
# NB(directxman12): this wiki page has a different argument order

gssapi/raw/oids.pyx

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
GSSAPI="BASE" # This ensures that a full module is generated by Cython
22

3-
import six
4-
53
from libc.string cimport memcmp, memcpy
64
from libc.stdlib cimport free, malloc
75

@@ -97,7 +95,7 @@ cdef class OID:
9795
ValueError: the sequence is less than two elements long
9896
"""
9997

100-
if isinstance(integer_sequence, six.string_types):
98+
if isinstance(integer_sequence, str):
10199
integer_sequence = integer_sequence.split('.')
102100

103101
oid_seq = [int(x) for x in integer_sequence]
@@ -134,10 +132,6 @@ cdef class OID:
134132

135133
def _decode_asn1ber(self):
136134
ber_encoding = self.__bytes__()
137-
# NB(directxman12): indexing a byte string yields an int in Python 3,
138-
# but yields a substring in Python 2
139-
if six.PY2:
140-
ber_encoding = [ord(c) for c in ber_encoding]
141135

142136
decoded = [ber_encoding[0] // 40, ber_encoding[0] % 40]
143137
pos = 1

gssapi/raw/types.pyx

+1-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ import collections
1111
import copy
1212
import numbers
1313
import operator
14-
import six
1514

16-
if six.PY2:
17-
from collections import MutableSet
18-
else:
19-
from collections.abc import MutableSet
15+
from collections.abc import MutableSet
2016

2117

2218
class NameType(object):

gssapi/sec_contexts.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import six
2-
31
from gssapi.raw import sec_contexts as rsec_contexts
42
from gssapi.raw import message as rmessage
53
from gssapi.raw import named_tuples as tuples
@@ -11,8 +9,8 @@
119
from gssapi.creds import Credentials
1210

1311

14-
@six.add_metaclass(_utils.CheckLastError)
15-
class SecurityContext(rsec_contexts.SecurityContext):
12+
class SecurityContext(rsec_contexts.SecurityContext,
13+
metaclass=_utils.CheckLastError):
1614
"""A GSSAPI Security Context
1715
1816
This class represents a GSSAPI security context that may be used

gssapi/tests/test_high_level.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pickle
66

77
import should_be.all # noqa
8-
import six
98
from parameterized import parameterized
109

1110
from gssapi import creds as gsscreds
@@ -388,10 +387,10 @@ def test_sasl_properties(self):
388387
# Note that some mechanisms don't have SASL names or SASL
389388
# descriptions; in this case, GSSAPI returns empty strings.
390389
if mech.sasl_name:
391-
mech.sasl_name.should_be_a(six.text_type)
390+
mech.sasl_name.should_be_a(str)
392391

393392
if mech.description:
394-
mech.description.should_be_a(six.text_type)
393+
mech.description.should_be_a(str)
395394

396395
cmp_mech = gssmechs.Mechanism.from_sasl_name(mech.sasl_name)
397396
str(cmp_mech).should_be(str(mech))
@@ -467,8 +466,8 @@ def test_display_as(self):
467466
gb.NameType.hostbased_service)
468467

469468
princ_str = SERVICE_PRINCIPAL.decode('utf-8') + '@'
470-
six.text_type(canonical_name).should_be(princ_str)
471-
krb_name.should_be_a(six.text_type)
469+
str(canonical_name).should_be(princ_str)
470+
krb_name.should_be_a(str)
472471
krb_name.should_be(princ_str)
473472

474473
@ktu.gssapi_extension_test('rfc6680', 'RFC 6680')
@@ -526,9 +525,9 @@ def test_to_str(self):
526525
def test_to_unicode(self):
527526
name = gssnames.Name(SERVICE_PRINCIPAL, gb.NameType.kerberos_principal)
528527

529-
name_str = six.text_type(name)
528+
name_str = str(name)
530529

531-
name_str.should_be_a(six.text_type)
530+
name_str.should_be_a(str)
532531
name_str.should_be(SERVICE_PRINCIPAL.decode(gssutils._get_encoding()))
533532

534533
def test_to_bytes(self):

gssapi/tests/test_raw.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
import socket
44
import unittest
55

6-
import six
76
import should_be.all # noqa
87

98
import gssapi.raw as gb
109
import gssapi.raw.misc as gbmisc
1110
import k5test.unit as ktu
1211
import k5test as kt
1312

14-
if six.PY2:
15-
from collections import Set
16-
else:
17-
from collections.abc import Set
13+
from collections.abc import Set
1814

1915

2016
TARGET_SERVICE_NAME = b'host'

setup.py

-3
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,7 @@ def gssapi_modules(lst):
288288

289289
install_requires = [
290290
'decorator',
291-
'six >= 1.4.0'
292291
]
293-
if sys.version_info < (3, 4):
294-
install_requires.append('enum34')
295292

296293
setup(
297294
name='gssapi',

test-requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ flake8
22
nose
33
parameterized
44
shouldbe
5-
six
65
Cython
76
k5test
87
decorator

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# and then run "tox" from this directory.
55

66
[tox]
7-
envlist = py27,py33,py34,py35,py36,py37
7+
envlist = py36,py37,py38
88

99
[testenv]
1010
whitelist_externals=bash

0 commit comments

Comments
 (0)