misc: remove some python2 compatibility code (#52457)
This commit is contained in:
parent
41e2c8eee3
commit
6c4aad3ab5
|
@ -18,7 +18,6 @@ import inspect
|
|||
from datetime import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils import six
|
||||
|
||||
try:
|
||||
from django.contrib.auth import get_user_model
|
||||
|
@ -36,11 +35,6 @@ except ImportError:
|
|||
|
||||
user_model_label = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
|
||||
|
||||
if six.PY2:
|
||||
Base64Error = TypeError
|
||||
else:
|
||||
from binascii import Error as Base64Error
|
||||
|
||||
if hasattr(inspect, 'signature'):
|
||||
|
||||
def signature_parameters(func):
|
||||
|
|
|
@ -18,6 +18,7 @@ import base64
|
|||
import hashlib
|
||||
import hmac
|
||||
import struct
|
||||
from binascii import Error as Base64Error
|
||||
|
||||
from Cryptodome import Random
|
||||
from Cryptodome.Cipher import AES
|
||||
|
@ -27,8 +28,6 @@ from django.utils.crypto import constant_time_compare
|
|||
from django.utils.encoding import force_bytes
|
||||
from django.utils.six import text_type
|
||||
|
||||
from authentic2.compat.misc import Base64Error
|
||||
|
||||
|
||||
class DecryptionError(Exception):
|
||||
pass
|
||||
|
|
|
@ -83,10 +83,7 @@ class UTF8Recoder(object):
|
|||
return self
|
||||
|
||||
def __next__(self):
|
||||
if six.PY2:
|
||||
return self.fd.next().encode('utf-8')
|
||||
else:
|
||||
return force_text(self.fd.__next__().encode('utf-8'))
|
||||
return force_text(self.fd.__next__().encode('utf-8'))
|
||||
|
||||
next = __next__
|
||||
|
||||
|
@ -96,12 +93,8 @@ class UnicodeReader(object):
|
|||
self.reader = csv.reader(UTF8Recoder(fd), dialect=dialect, **kwargs)
|
||||
|
||||
def __next__(self):
|
||||
if six.PY2:
|
||||
row = self.reader.next()
|
||||
return [s.decode('utf-8') for s in row]
|
||||
else:
|
||||
row = self.reader.__next__()
|
||||
return [force_bytes(s).decode('utf-8') for s in row]
|
||||
row = self.reader.__next__()
|
||||
return [force_bytes(s).decode('utf-8') for s in row]
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
|
|
@ -18,6 +18,7 @@ import base64
|
|||
import datetime
|
||||
import logging
|
||||
import math
|
||||
from binascii import Error as Base64Error
|
||||
|
||||
try:
|
||||
from secrets import compare_digest
|
||||
|
@ -45,7 +46,6 @@ from ratelimit.utils import is_ratelimited
|
|||
|
||||
from authentic2 import app_settings as a2_app_settings
|
||||
from authentic2 import hooks
|
||||
from authentic2.compat.misc import Base64Error
|
||||
from authentic2.decorators import setting_enabled
|
||||
from authentic2.exponential_retry_timeout import ExponentialRetryTimeout
|
||||
from authentic2.utils import last_authentication_event, login_require, make_url, redirect
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
import datetime
|
||||
import importlib
|
||||
import json
|
||||
from io import BufferedReader, BufferedWriter, TextIOWrapper
|
||||
|
||||
import py
|
||||
import pytest
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.utils import six
|
||||
from django.utils.timezone import now
|
||||
|
||||
from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP, VIEW_OP
|
||||
|
@ -37,13 +37,6 @@ from .utils import call_command, login
|
|||
|
||||
User = get_user_model()
|
||||
|
||||
if six.PY2:
|
||||
FileType = file # noqa: F821
|
||||
else:
|
||||
from io import BufferedReader, BufferedWriter, TextIOWrapper
|
||||
|
||||
FileType = (TextIOWrapper, BufferedReader, BufferedWriter)
|
||||
|
||||
|
||||
def test_changepassword(db, simple_user, monkeypatch):
|
||||
import getpass
|
||||
|
@ -191,6 +184,7 @@ def test_cleanupauthentic(db):
|
|||
|
||||
|
||||
def test_load_ldif(db, monkeypatch, tmpdir):
|
||||
FileType = (TextIOWrapper, BufferedReader, BufferedWriter)
|
||||
ldif = tmpdir.join('some.ldif')
|
||||
ldif.ensure()
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import pytest
|
|||
from django import VERSION
|
||||
from django.core import management
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils import six
|
||||
from django.utils.six.moves import builtins as __builtin__
|
||||
|
||||
from django_rbac.utils import get_role_model
|
||||
|
@ -168,8 +167,7 @@ def test_import_site_confirm_prompt_yes(db, monkeypatch, json_fixture):
|
|||
def yes_raw_input(*args, **kwargs):
|
||||
return 'yes'
|
||||
|
||||
input_funcname = 'raw_input' if six.PY2 else 'input'
|
||||
monkeypatch.setattr(__builtin__, input_funcname, yes_raw_input)
|
||||
monkeypatch.setattr(__builtin__, 'input', yes_raw_input)
|
||||
|
||||
management.call_command('import_site', json_fixture(content), stdin='yes')
|
||||
assert Role.objects.get(uuid='dqfewrvesvews2532')
|
||||
|
|
|
@ -14,10 +14,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
from django.utils import six
|
||||
|
||||
from authentic2.utils.lazy import lazy_join
|
||||
|
||||
|
@ -25,14 +22,3 @@ from authentic2.utils.lazy import lazy_join
|
|||
def test_lazy_join():
|
||||
assert lazy_join(', ', ['\xe9']) == '\xe9'
|
||||
assert lazy_join(', ', ['\xe9'] * 2) == '\xe9, \xe9'
|
||||
if six.PY2:
|
||||
assert lazy_join(b', ', ['\xe9']) == '\xe9'
|
||||
assert lazy_join(b', ', ['\xe9'] * 2) == '\xe9, \xe9'
|
||||
with pytest.raises(UnicodeDecodeError):
|
||||
assert lazy_join(b', ', [b'\xe9']) == ''
|
||||
with pytest.raises(UnicodeDecodeError):
|
||||
assert lazy_join(b', ', [b'\xe9'] * 2) == ''
|
||||
with pytest.raises(UnicodeDecodeError):
|
||||
assert lazy_join(', ', [b'\xe9']) == ''
|
||||
with pytest.raises(UnicodeDecodeError):
|
||||
assert lazy_join(', ', [b'\xe9'] * 2) == ''
|
||||
|
|
Loading…
Reference in New Issue