Skip to content

Commit c42c20a

Browse files
tiranfrozencemetery
authored andcommitted
Use collections.abc on Python 3
Starting before Python 3.3 (which is the oldest version we support), the ABCs for collections are located at collections.abc, but aliased into collections. Starting in Python 3.7, referring to them using the aliases produces DeprecationWarnings, which breaks our users. The alias will be removed entirely in Python 3.8. Signed-off-by: Christian Heimes <cheimes@redhat.com> [rharwood@redhat.com: Write commit message, update style on checks] Merges: #154
1 parent 2af8e93 commit c42c20a

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

gssapi/names.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import collections
2-
31
import six
42

53
from gssapi.raw import names as rname
64
from gssapi.raw import NameType
75
from gssapi.raw import named_tuples as tuples
86
from gssapi import _utils
97

8+
if six.PY2:
9+
from collections import MutableMapping, Iterable
10+
else:
11+
from collections.abc import MutableMapping, Iterable
12+
13+
1014
rname_rfc6680 = _utils.import_gssapi_extension('rfc6680')
1115
rname_rfc6680_comp_oid = _utils.import_gssapi_extension('rfc6680_comp_oid')
1216

@@ -313,7 +317,7 @@ def attributes(self):
313317
return self._attr_obj
314318

315319

316-
class _NameAttributeMapping(collections.MutableMapping):
320+
class _NameAttributeMapping(MutableMapping):
317321

318322
"""Provides dict-like access to RFC 6680 Name attributes."""
319323
def __init__(self, name):
@@ -345,7 +349,7 @@ def __setitem__(self, key, value):
345349
complete = False
346350

347351
if (isinstance(value, (six.string_types, bytes)) or
348-
not isinstance(value, collections.Iterable)):
352+
not isinstance(value, Iterable)):
349353
# NB(directxman12): this allows us to easily assign a single
350354
# value, since that's a common case
351355
value = [value]

gssapi/raw/ext_dce.pyx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ from gssapi.raw.sec_contexts cimport SecurityContext
99
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
12-
from collections import namedtuple, Sequence
12+
from collections import namedtuple
1313

1414
from enum import IntEnum
1515
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+
23+
1824
cdef extern from "python_gssapi_ext.h":
1925
# NB(directxman12): this wiki page has a different argument order
2026
# than the header file, and uses size_t instead of int

gssapi/raw/types.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import numbers
1313
import operator
1414
import six
1515

16+
if six.PY2:
17+
from collections import MutableSet
18+
else:
19+
from collections.abc import MutableSet
20+
1621

1722
class NameType(object):
1823
"""
@@ -106,7 +111,7 @@ class MechType(object):
106111
# these are added in by the individual mechanism files on import
107112

108113

109-
class GenericFlagSet(collections.MutableSet):
114+
class GenericFlagSet(MutableSet):
110115
"""A set backed by a 32-bit integer
111116
112117
This is a set backed by a 32 bit integer.

gssapi/tests/test_raw.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import collections
21
import copy
32
import os
43
import socket
54
import unittest
65

6+
import six
77
import should_be.all # noqa
88

99
import gssapi.raw as gb
1010
import gssapi.raw.misc as gbmisc
1111
import k5test.unit as ktu
1212
import k5test as kt
1313

14+
if six.PY2:
15+
from collections import Set
16+
else:
17+
from collections.abc import Set
18+
1419

1520
TARGET_SERVICE_NAME = b'host'
1621
FQDN = socket.getfqdn().encode('utf-8')
@@ -355,7 +360,7 @@ def test_inquire_context(self):
355360
mech_type.should_be(gb.MechType.kerberos)
356361

357362
flags.shouldnt_be_none()
358-
flags.should_be_a(collections.Set)
363+
flags.should_be_a(Set)
359364
flags.shouldnt_be_empty()
360365

361366
local_est.should_be_a(bool)
@@ -1084,7 +1089,7 @@ def test_basic_init_default_ctx(self):
10841089

10851090
out_mech_type.should_be(gb.MechType.kerberos)
10861091

1087-
out_req_flags.should_be_a(collections.Set)
1092+
out_req_flags.should_be_a(Set)
10881093
out_req_flags.should_be_at_least_length(2)
10891094

10901095
out_token.shouldnt_be_empty()
@@ -1139,7 +1144,7 @@ def test_basic_accept_context_no_acceptor_creds(self):
11391144

11401145
out_token.shouldnt_be_empty()
11411146

1142-
out_req_flags.should_be_a(collections.Set)
1147+
out_req_flags.should_be_a(Set)
11431148
out_req_flags.should_be_at_least_length(2)
11441149

11451150
out_ttl.should_be_greater_than(0)
@@ -1167,7 +1172,7 @@ def test_basic_accept_context(self):
11671172

11681173
out_token.shouldnt_be_empty()
11691174

1170-
out_req_flags.should_be_a(collections.Set)
1175+
out_req_flags.should_be_a(Set)
11711176
out_req_flags.should_be_at_least_length(2)
11721177

11731178
out_ttl.should_be_greater_than(0)

tox.ini

Lines changed: 1 addition & 1 deletion
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
7+
envlist = py27,py33,py34,py35,py36,py37
88

99
[testenv]
1010
whitelist_externals=bash

0 commit comments

Comments
 (0)