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

remove six transitional dependency #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ exclude_lines =
def __str__
raise AssertionError
raise NotImplementedError
if six.PY3:
8 changes: 2 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Dependencies
* requests >= 2.4
* requests_futures >= 0.9.5
* lxml >= 3.4
* six >= 1.8

Minimal version of package dependencies are just indicative and means that ``django-cas-server`` has
been tested with it. Previous versions of dependencies may or may not work.
Expand All @@ -51,7 +50,6 @@ them on debian like systems and centos like systems.
You should try as much as possible to use system packages as they are automatically updated when
you update your system. You can then install Not Available (N/A)
packages on your system using pip3 inside a virtualenv as described in the `Installation`_ section.
For use with python2, just replace python3(6) in the table by python.

+------------------+--------------------------+---------------------+
| python package | debian like systems | centos like systems |
Expand All @@ -64,8 +62,6 @@ For use with python2, just replace python3(6) in the table by python.
+------------------+--------------------------+---------------------+
| lxml | python3-lxml | python36-lxml |
+------------------+--------------------------+---------------------+
| six | python3-six | python36-six |
+------------------+--------------------------+---------------------+
| ldap3 | python3-ldap3 | python36-ldap3 |
+------------------+--------------------------+---------------------+
| psycopg2 | python3-psycopg2 | python36-psycopg2 |
Expand All @@ -84,14 +80,14 @@ The recommended installation mode is to use a virtualenv with ``--system-site-pa

On debian like systems::

$ sudo apt-get install python3-django python3-requests python3-six python3-lxml python3-requests-futures
$ sudo apt-get install python3-django python3-requests python3-lxml python3-requests-futures

On debian jessie, you can use the version of python-django available in the
`backports <https://backports.debian.org/Instructions/>`_.

On centos like systems with epel enabled::

$ sudo yum install python36-django python36-requests python36-six python36-lxml
$ sudo yum install python36-django python36-requests python36-lxml

3. Create a virtualenv::

Expand Down
1 change: 0 additions & 1 deletion cas_server/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import warnings
from datetime import timedelta
from six.moves import range
try: # pragma: no cover
import MySQLdb
import MySQLdb.cursors
Expand Down
9 changes: 4 additions & 5 deletions cas_server/cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
# at commit ec1f2d4779625229398547b9234d0e9e874a2c9a
# some modifications have been made to be unicode coherent between python2 and python2

import six
from six.moves.urllib import parse as urllib_parse
from six.moves.urllib import request as urllib_request
from six.moves.urllib.request import Request
import urllib.parse as urllib_parse
import urllib.request as urllib_request
from urllib.request import Request
from uuid import uuid4
import datetime

Expand All @@ -37,7 +36,7 @@ class CASError(ValueError):
class ReturnUnicode(object):
@staticmethod
def u(string, charset):
if not isinstance(string, six.text_type):
if not isinstance(string, str):
return string.decode(charset)
else:
return string
Expand Down
2 changes: 1 addition & 1 deletion cas_server/federate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .models import FederatedUser, FederateSLO, User

import logging
from six.moves import urllib
import urllib

#: logger facility
logger = logging.getLogger(__name__)
Expand Down
6 changes: 3 additions & 3 deletions cas_server/tests/test_federate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
#
# (c) 2016 Valentin Samir
"""tests for the CAS federate mode"""
import importlib

from cas_server import default_settings
from cas_server.default_settings import settings

import django
from django.test import TestCase, Client
from django.test.utils import override_settings

from six.moves import reload_module

from cas_server import utils, models
from cas_server.tests.mixin import BaseServicePattern, CanLogin, FederatedIendityProviderModel
from cas_server.tests import utils as tests_utils
Expand Down Expand Up @@ -49,7 +49,7 @@ def setUp(self):
def test_default_settings(self):
"""default settings should populated some default variable then CAS_FEDERATE is True"""
del settings.CAS_AUTH_CLASS
reload_module(default_settings)
importlib.reload(default_settings)
self.assertEqual(settings.CAS_AUTH_CLASS, "cas_server.auth.CASFederateAuth")

def test_login_get_provider(self):
Expand Down
18 changes: 7 additions & 11 deletions cas_server/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from django.test import TestCase, RequestFactory
from django.db import connection

import six
import warnings
import datetime

Expand Down Expand Up @@ -66,15 +65,12 @@ def test_crypt(self):
salts = ["$6$UVVAQvrMyXMF3FF3", "aa"]
hashed_password1 = []
for salt in salts:
if six.PY3:
hashed_password1.append(
utils.crypt.crypt(
self.password1.decode("utf8"),
salt
).encode("utf8")
)
else:
hashed_password1.append(utils.crypt.crypt(self.password1, salt))
hashed_password1.append(
utils.crypt.crypt(
self.password1.decode("utf8"),
salt
).encode("utf8")
)

for hp1 in hashed_password1:
self.assertTrue(utils.check_password("crypt", self.password1, hp1, "utf8"))
Expand Down Expand Up @@ -240,7 +236,7 @@ def test_last_version(self):
)
else:
version = utils.last_version()
self.assertIsInstance(version, six.text_type)
self.assertIsInstance(version, str)
self.assertEqual(len(version.split('.')), 3)

# version is cached 24h so calling it a second time should return the save value
Expand Down
1 change: 0 additions & 1 deletion cas_server/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import json
import mock
from lxml import etree
from six.moves import range

from cas_server import models
from cas_server import utils
Expand Down
9 changes: 4 additions & 5 deletions cas_server/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
from django.utils import timezone

import cgi
import six
from threading import Thread
from lxml import etree
from six.moves import BaseHTTPServer
from six.moves.urllib.parse import urlparse, parse_qsl, parse_qs
import http.server as BaseHTTPServer
from urllib.parse import urlparse, parse_qsl, parse_qs
from datetime import timedelta

from cas_server import models
Expand All @@ -43,7 +42,7 @@ def Context(arg):

def return_unicode(string, charset):
"""make `string` a unicode if `string` is a unicode or bytes encoded with `charset`"""
if not isinstance(string, six.text_type):
if not isinstance(string, str):
return string.decode(charset)
else:
return string
Expand All @@ -54,7 +53,7 @@ def return_bytes(string, charset):
make `string` a bytes encoded with `charset` if `string` is a unicode
or bytes encoded with `charset`
"""
if isinstance(string, six.text_type):
if isinstance(string, str):
return string.encode(charset)
else:
return string
Expand Down
38 changes: 15 additions & 23 deletions cas_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@
import hashlib
import crypt
import base64
import six
import requests
import time
import logging
import binascii

from importlib import import_module
from datetime import datetime, timedelta
from six.moves.urllib.parse import urlparse, urlunparse, parse_qsl, urlencode
from urllib.parse import urlparse, urlunparse, parse_qsl, urlencode

from . import VERSION

Expand All @@ -53,7 +52,7 @@ def json_encode(obj):
try:
return json_encode.encoder.encode(obj)
except AttributeError:
json_encode.encoder = DjangoJSONEncoder(default=six.text_type)
json_encode.encoder = DjangoJSONEncoder(default=str)
return json_encode(obj)


Expand Down Expand Up @@ -92,7 +91,7 @@ def context(params):
# make box discardable by default
msg["discardable"] = msg.get("discardable", True)
msg_hash = (
six.text_type(msg["message"]).encode("utf-8") +
str(msg["message"]).encode("utf-8") +
msg["type"].encode("utf-8")
)
# hash depend of the rendering language
Expand Down Expand Up @@ -125,10 +124,10 @@ def import_attr(path):
:return: The python object pointed by the dotted path or the python object unchanged
"""
# if we got a str, decode it to unicode (normally it should only contain ascii)
if isinstance(path, six.binary_type):
if isinstance(path, bytes):
path = path.decode("utf-8")
# if path is not an unicode, return it unchanged (may be it is already the attribute to import)
if not isinstance(path, six.text_type):
if not isinstance(path, str):
return path
if u"." not in path:
ValueError("%r should be of the form `module.attr` and we just got `attr`" % path)
Expand Down Expand Up @@ -261,12 +260,8 @@ def to_bytes(data):
else:
return data

if six.PY3:
url = to_unicode(url)
params = {to_unicode(key): to_unicode(value) for (key, value) in params.items()}
else:
url = to_bytes(url)
params = {to_bytes(key): to_bytes(value) for (key, value) in params.items()}
url = to_unicode(url)
params = {to_unicode(key): to_unicode(value) for (key, value) in params.items()}

url_parts = list(urlparse(url))
query = dict(parse_qsl(url_parts[4], keep_blank_values=True))
Expand Down Expand Up @@ -567,14 +562,12 @@ def hash(cls, scheme, password, salt=None, charset="utf8"):
cls._schemes_to_hash[scheme](password + salt).digest() + salt
)
except KeyError:
if six.PY3:
password = password.decode(charset)
salt = salt.decode(charset)
password = password.decode(charset)
salt = salt.decode(charset)
if not crypt_salt_is_valid(salt):
raise cls.BadSalt("System crypt implementation do not support the salt %r" % salt)
hashed_password = crypt.crypt(password, salt)
if six.PY3:
hashed_password = hashed_password.encode(charset)
hashed_password = hashed_password.encode(charset)
return scheme + hashed_password

@classmethod
Expand Down Expand Up @@ -639,9 +632,9 @@ def check_password(method, password, hashed_password, charset):
``False`` otherwise
:rtype: bool
"""
if not isinstance(password, six.binary_type):
if not isinstance(password, bytes):
password = password.encode(charset)
if not isinstance(hashed_password, six.binary_type):
if not isinstance(hashed_password, bytes):
hashed_password = hashed_password.encode(charset)
if method == "plain":
return password == hashed_password
Expand All @@ -652,10 +645,9 @@ def check_password(method, password, hashed_password, charset):
salt = hashed_password[:9]
else:
salt = hashed_password[:2]
if six.PY3:
password = password.decode(charset)
salt = salt.decode(charset)
hashed_password = hashed_password.decode(charset)
password = password.decode(charset)
salt = salt.decode(charset)
hashed_password = hashed_password.decode(charset)
if not crypt_salt_is_valid(salt):
raise ValueError("System crypt implementation do not support the salt %r" % salt)
crypted_password = crypt.crypt(password, salt)
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ setuptools>=5.5
requests>=2.4
requests_futures>=0.9.5
lxml>=3.4
six>=1.8
tox>=1.8.1
pytest>=7
pytest-django>=2.8.0
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ setuptools>=5.5
requests>=2.4
requests_futures>=0.9.5
lxml>=3.4
six>=1.8
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
keywords=['django', 'cas', 'cas3', 'server', 'sso', 'single sign-on', 'authentication', 'auth'],
install_requires=[
'Django >= 1.11,<4.2', 'requests >= 2.4', 'requests_futures >= 0.9.5',
'lxml >= 3.4', 'six >= 1'
'lxml >= 3.4'
],
url="https://github.com/nitmir/django-cas-server",
download_url="https://github.com/nitmir/django-cas-server/releases/latest",
Expand Down