remove six transitional dependency

This commit is contained in:
Alexandre Detiste 2023-10-09 20:56:51 +02:00
parent 0025a3772b
commit 7ce1979e90
13 changed files with 37 additions and 60 deletions

View file

@ -15,4 +15,3 @@ exclude_lines =
def __str__
raise AssertionError
raise NotImplementedError
if six.PY3:

View file

@ -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.
@ -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 |
@ -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 |
@ -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::

View file

@ -17,7 +17,6 @@ from django.db import connections, DatabaseError
import warnings
from datetime import timedelta
from six.moves import range
try: # pragma: no cover
import MySQLdb
import MySQLdb.cursors

View file

@ -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
@ -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

View file

@ -17,7 +17,7 @@ from .cas import CASClient
from .models import FederatedUser, FederateSLO, User
import logging
from six.moves import urllib
import urllib
#: logger facility
logger = logging.getLogger(__name__)

View file

@ -10,6 +10,8 @@
#
# (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
@ -17,8 +19,6 @@ 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
@ -49,7 +49,7 @@ class FederateAuthLoginLogoutTestCase(
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):

View file

@ -14,7 +14,6 @@ import django
from django.test import TestCase, RequestFactory
from django.db import connection
import six
import warnings
import datetime
@ -66,15 +65,12 @@ class CheckPasswordCase(TestCase):
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"))
@ -240,7 +236,7 @@ class UtilsTestCase(TestCase):
)
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

View file

@ -22,7 +22,6 @@ import random
import json
import mock
from lxml import etree
from six.moves import range
from cas_server import models
from cas_server import utils

View file

@ -18,11 +18,10 @@ from django.template import loader
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
@ -43,7 +42,7 @@ else:
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
@ -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

View file

@ -32,7 +32,6 @@ import json
import hashlib
import crypt
import base64
import six
import requests
import time
import logging
@ -40,7 +39,7 @@ 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
@ -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)
@ -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
@ -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)
@ -261,12 +260,8 @@ def update_url(url, params):
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))
@ -567,14 +562,12 @@ class LdapHashUserPassword(object):
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
@ -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
@ -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)

View file

@ -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

View file

@ -3,4 +3,3 @@ setuptools>=5.5
requests>=2.4
requests_futures>=0.9.5
lxml>=3.4
six>=1.8

View file

@ -62,7 +62,7 @@ if __name__ == '__main__':
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",