py3ize obviously non-compatible code (#32866)

This commit is contained in:
Benjamin Dauvergne 2019-05-07 14:31:07 +02:00
parent 0077218685
commit 2746d095c5
3 changed files with 16 additions and 14 deletions

View File

@ -15,6 +15,8 @@
# 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 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',

View File

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

View File

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