Skip to content

Use collections.abc on Python 3 #154

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

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ script:
jobs:
include:
- stage: verify
env: DISTRO=fedora:rawhide PYTHON="2"
env: DISTRO=fedora:latest PYTHON="2"
script:
- source ./.travis/lib-util.sh
- util::docker-run $DISTRO ./.travis/verify.sh

- stage: verify
env: DISTRO=fedora:rawhide PYTHON="3"
env: DISTRO=fedora:latest PYTHON="3"
script:
- source ./.travis/lib-util.sh
- util::docker-run $DISTRO ./.travis/verify.sh
Expand All @@ -54,10 +54,10 @@ jobs:
env: DISTRO=centos:7 PYTHON="2" # el7 doesn't do python3 modules

- stage: test
env: DISTRO=fedora:rawhide PYTHON="3"
env: DISTRO=fedora:latest PYTHON="3"

- stage: test
env: DISTRO=fedora:rawhide PYTHON="2"
env: DISTRO=fedora:latest PYTHON="2"

- stage: test
env: PYTHON="2" KRB5_VER="heimdal" PYENV="2.7.14"
Expand All @@ -75,7 +75,7 @@ jobs:
- stage: deploy latest docs
script: skip
env:
- DISTRO=fedora:rawhide
- DISTRO=fedora:latest
- PYTHON="3"
- secure: L5SpEj5+no20PWwC9Y/XNhAfmUvYiuykwSMa/YyqvUuBjdizzpZcHr7Ego5nMdM1TniTxj4pSTM+GbM0FHCzNmAINSRh9g/D3hheRqlRBacqR0XwC9ZZRvkKvtzwnLh4vYWiauq4AoDeR5U6tkEcay6LjE57iMQcLjcKYBc+Eos=
before_deploy:
Expand All @@ -93,7 +93,7 @@ jobs:
- stage: deploy
script: skip
env:
- DISTRO=fedora:rawhide
- DISTRO=fedora:latest
- PYTHON="3"
- secure: L5SpEj5+no20PWwC9Y/XNhAfmUvYiuykwSMa/YyqvUuBjdizzpZcHr7Ego5nMdM1TniTxj4pSTM+GbM0FHCzNmAINSRh9g/D3hheRqlRBacqR0XwC9ZZRvkKvtzwnLh4vYWiauq4AoDeR5U6tkEcay6LjE57iMQcLjcKYBc+Eos=
before_deploy:
Expand Down
12 changes: 8 additions & 4 deletions gssapi/names.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import collections

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


rname_rfc6680 = _utils.import_gssapi_extension('rfc6680')
rname_rfc6680_comp_oid = _utils.import_gssapi_extension('rfc6680_comp_oid')

Expand Down Expand Up @@ -313,7 +317,7 @@ def attributes(self):
return self._attr_obj


class _NameAttributeMapping(collections.MutableMapping):
class _NameAttributeMapping(MutableMapping):

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

if (isinstance(value, (six.string_types, bytes)) or
not isinstance(value, collections.Iterable)):
not isinstance(value, Iterable)):
# NB(directxman12): this allows us to easily assign a single
# value, since that's a common case
value = [value]
Expand Down
8 changes: 7 additions & 1 deletion gssapi/raw/ext_dce.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ from gssapi.raw.sec_contexts cimport SecurityContext
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, Sequence
from collections import namedtuple

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
# than the header file, and uses size_t instead of int
Expand Down
7 changes: 6 additions & 1 deletion gssapi/raw/types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import numbers
import operator
import six

if six.PY2:
from collections import MutableSet
else:
from collections.abc import MutableSet


class NameType(object):
"""
Expand Down Expand Up @@ -106,7 +111,7 @@ class MechType(object):
# these are added in by the individual mechanism files on import


class GenericFlagSet(collections.MutableSet):
class GenericFlagSet(MutableSet):
"""A set backed by a 32-bit integer

This is a set backed by a 32 bit integer.
Expand Down
15 changes: 10 additions & 5 deletions gssapi/tests/test_raw.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import collections
import copy
import os
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


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

flags.shouldnt_be_none()
flags.should_be_a(collections.Set)
flags.should_be_a(Set)
flags.shouldnt_be_empty()

local_est.should_be_a(bool)
Expand Down Expand Up @@ -1084,7 +1089,7 @@ def test_basic_init_default_ctx(self):

out_mech_type.should_be(gb.MechType.kerberos)

out_req_flags.should_be_a(collections.Set)
out_req_flags.should_be_a(Set)
out_req_flags.should_be_at_least_length(2)

out_token.shouldnt_be_empty()
Expand Down Expand Up @@ -1139,7 +1144,7 @@ def test_basic_accept_context_no_acceptor_creds(self):

out_token.shouldnt_be_empty()

out_req_flags.should_be_a(collections.Set)
out_req_flags.should_be_a(Set)
out_req_flags.should_be_at_least_length(2)

out_ttl.should_be_greater_than(0)
Expand Down Expand Up @@ -1167,7 +1172,7 @@ def test_basic_accept_context(self):

out_token.shouldnt_be_empty()

out_req_flags.should_be_a(collections.Set)
out_req_flags.should_be_a(Set)
out_req_flags.should_be_at_least_length(2)

out_ttl.should_be_greater_than(0)
Expand Down
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
envlist = py27,py33,py34,py35,py36,py37

[testenv]
whitelist_externals=bash
Expand Down