Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed six package and other older py cleanup values #222

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 package

Compiling from Scratch
----------------------
Expand Down
22 changes: 4 additions & 18 deletions gssapi/_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
import types

import six
import decorator as deco

from typing import Optional
Expand Down Expand Up @@ -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 {enc(k): enc(v) for k, v in d.items()}


# in case of Python 3, just use exception chaining
Expand All @@ -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:
Expand All @@ -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)
Expand Down
12 changes: 3 additions & 9 deletions gssapi/mechs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 7 additions & 17 deletions gssapi/names.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions gssapi/raw/ext_dce.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions gssapi/raw/oids.pyx
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions gssapi/raw/types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions gssapi/sec_contexts.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
13 changes: 6 additions & 7 deletions gssapi/tests/test_high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pickle

import should_be.all # noqa
import six
from parameterized import parameterized

from gssapi import creds as gsscreds
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 1 addition & 5 deletions gssapi/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import socket
import unittest

import six
import should_be.all # noqa

import gssapi.raw as gb
import gssapi.raw.misc as gbmisc
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'
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ flake8
nose
parameterized
shouldbe
six
Cython
k5test
decorator
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py27,py33,py34,py35,py36,py37
envlist = py36,py37,py38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python-3.8 won't work yet; we need to figure out and merge #219 for that. This PR will cause a merge conflict with that one, but it should be easily sorted once this merges. Since we don't use tox ourselves, this is probably fine.


[testenv]
whitelist_externals=bash
Expand Down