From 2746d095c5f7eb08d7ef587937b870756e59f0d0 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 7 May 2019 14:31:07 +0200 Subject: [PATCH] py3ize obviously non-compatible code (#32866) --- setup.py | 17 +++++++++-------- src/authentic2_auth_fc/utils.py | 8 ++++---- src/authentic2_auth_fc/views.py | 5 +++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index 8641625..b317f66 100755 --- a/setup.py +++ b/setup.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from __future__ import print_function + import sys import os import subprocess @@ -50,10 +52,10 @@ class compile_translations(Command): call_command('compilemessages') os.chdir(curdir) except ImportError: - print + print() sys.stderr.write('!!! Please install Django >= 1.4 to build translations') - print - print + print() + print() os.chdir(curdir) @@ -64,7 +66,7 @@ class build(_build): class eo_sdist(sdist): def run(self): - print "creating VERSION file" + print("creating VERSION file") if os.path.exists('VERSION'): os.remove('VERSION') version = get_version() @@ -72,7 +74,7 @@ class eo_sdist(sdist): version_file.write(version) version_file.close() sdist.run(self) - print "removing VERSION file" + print("removing VERSION file") if os.path.exists('VERSION'): os.remove('VERSION') @@ -108,9 +110,8 @@ def get_version(): ['git', 'rev-list', 'HEAD']).splitlines()) return '0.0' -README = file(os.path.join( - os.path.dirname(__file__), - 'README')).read() +with open(os.path.join(os.path.dirname(__file__), 'README')) as fd: + README = fd.read() setup( name='authentic2-auth-fc', diff --git a/src/authentic2_auth_fc/utils.py b/src/authentic2_auth_fc/utils.py index f547f4d..a713d77 100644 --- a/src/authentic2_auth_fc/utils.py +++ b/src/authentic2_auth_fc/utils.py @@ -40,7 +40,7 @@ def build_logout_url(request, next_url=None): """ if not next_url: next_url = resolve_url(settings.LOGIN_REDIRECT_URL) - state = unicode(uuid.uuid4()) + state = str(uuid.uuid4()) states = request.session.setdefault('fc_states', {}) request.session.modified = True states[state] = { @@ -93,7 +93,7 @@ def mapping_to_value(mapping, user_info): if mapping['compute'] == 'today': value = datetime.date.today() elif mapping['compute'] == 'random': - value = unicode(uuid.uuid4()) + value = str(uuid.uuid4()) else: raise NotImplementedError @@ -151,8 +151,8 @@ def apply_user_info_mappings(user, user_info): save_user = False tags = set() for attribute, mapping in mappings.iteritems(): - # normalize mapping to dictionaries - if isinstance(mapping, basestring): + # normalize mapping to dictionaries: if string, convert into a simple reference + if hasattr(mapping, 'format'): mapping = {'ref': mapping} try: value = mapping_to_value(mapping, user_info) diff --git a/src/authentic2_auth_fc/views.py b/src/authentic2_auth_fc/views.py index 3ad3cf3..7505db7 100644 --- a/src/authentic2_auth_fc/views.py +++ b/src/authentic2_auth_fc/views.py @@ -72,7 +72,7 @@ def ask_authorization(request, scopes, logger): if not isinstance(scopes, (list, tuple)): scopes = [scopes] redirect_uri = request.build_absolute_uri() - state = unicode(uuid.uuid4()) + state = str(uuid.uuid4()) states = request.session.setdefault('fc_states', {}) states[state] = { 'redirect_uri': redirect_uri, @@ -274,7 +274,8 @@ class FcOAuthSessionViewMixin(LoggerMixin): messages.warning(request, _('Unable to connect to FranceConnect.')) return self.redirect(request) key = app_settings.client_secret - if isinstance(key, unicode): + # duck-type unicode/Py3 strings + if hasattr(key, 'isdecimal'): key = key.encode('utf-8') self.id_token, error = models.parse_id_token( self.token['id_token'], client_id=app_settings.client_id, client_secret=key)