From 47e1b31b426c9d3deaf8353b242987cd6730fa1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Wed, 22 Apr 2020 20:12:42 +0200
Subject: [PATCH] trivial: remove conditional Python 2 code (#42003)

---
 combo/apps/lingo/manager_views.py | 5 +----
 combo/apps/pwa/models.py          | 6 ++----
 combo/utils/signature.py          | 8 ++------
 setup.py                          | 1 -
 tests/test_public.py              | 3 +--
 5 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/combo/apps/lingo/manager_views.py b/combo/apps/lingo/manager_views.py
index 98efa6bd..6227207e 100644
--- a/combo/apps/lingo/manager_views.py
+++ b/combo/apps/lingo/manager_views.py
@@ -185,10 +185,7 @@ def download_transactions_csv(request):
                        str(transaction.amount)]
                 for item in transaction.items.all():
                     row.extend([item.subject, str(item.amount)])
-                if six.PY3:
-                    writer.writerow([x for x in row])
-                else:
-                    writer.writerow([unicode(x).encode('utf-8') for x in row])
+                writer.writerow([x for x in row])
             return response
     else:
         form = TransactionExportForm()
diff --git a/combo/apps/pwa/models.py b/combo/apps/pwa/models.py
index c925f093..281089a0 100644
--- a/combo/apps/pwa/models.py
+++ b/combo/apps/pwa/models.py
@@ -144,8 +144,7 @@ class PwaNavigationEntry(models.Model):
         serialized_entry = json.loads(serializers.serialize('json', [self],
             use_natural_foreign_keys=True, use_natural_primary_keys=True))[0]
         if self.icon:
-            encode = base64.encodestring if six.PY2 else base64.encodebytes
-            serialized_entry['icon:base64'] = force_text(encode(self.icon.read()))
+            serialized_entry['icon:base64'] = force_text(base64.encodebytes(self.icon.read()))
         del serialized_entry['model']
         del serialized_entry['pk']
         return serialized_entry
@@ -170,8 +169,7 @@ class PwaNavigationEntry(models.Model):
         entry = next(serializers.deserialize('json', json.dumps([json_entry]), ignorenonexistent=True))
         entry.save()
         if json_entry.get('icon:base64'):
-            decode = base64.decodestring if six.PY2 else base64.decodebytes
-            decoded_icon = decode(force_bytes(json_entry['icon:base64']))
+            decoded_icon = base64.decodebytes(force_bytes(json_entry['icon:base64']))
             if not default_storage.exists(entry.object.icon.name) or entry.object.icon.read() != decoded_icon:
                 # save new file
                 entry.object.icon.save(entry.object.icon.name, ContentFile(decoded_icon))
diff --git a/combo/utils/signature.py b/combo/utils/signature.py
index dd6ec309..f43d89f0 100644
--- a/combo/utils/signature.py
+++ b/combo/utils/signature.py
@@ -100,12 +100,8 @@ def check_string(s, signature, keys, algo='sha256'):
             continue
         res = 0
         # constant time compare
-        if six.PY3:
-            for a, b in zip(signature, signature2):
-                res |= a ^ b
-        else:
-            for a, b in zip(signature, signature2):
-                res |= ord(a) ^ ord(b)
+        for a, b in zip(signature, signature2):
+            res |= a ^ b
         if res == 0:
             return True
     return False
diff --git a/setup.py b/setup.py
index 438f357d..d97c7271 100644
--- a/setup.py
+++ b/setup.py
@@ -145,7 +145,6 @@ setup(
         'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
         'Operating System :: OS Independent',
         'Programming Language :: Python',
-        'Programming Language :: Python :: 2',
         'Programming Language :: Python :: 3',
     ],
     install_requires=['django>=1.11, <2.3',
diff --git a/tests/test_public.py b/tests/test_public.py
index f6c1eed5..973ea87d 100644
--- a/tests/test_public.py
+++ b/tests/test_public.py
@@ -88,8 +88,7 @@ def test_mellon_login(app):
         assert urlparse.urlparse(resp.location).path == '/accounts/mellon/login/'
         resp = app.get('/login/?next=whatever')
         assert urlparse.urlparse(resp.location).query == 'next=whatever'
-        if six.PY2:
-            resp = app.get('/login/?next=%e0%40', status=400)
+
 
 def test_page_contents_group_presence(app, normal_user):
     group = Group(name='plop')
-- 
2.26.2

