From 318d443010954e4da6f0c5e2b8b536e8e9fb058f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 02 2019 14:01:33 +0000 Subject: Port elections to python3 Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedora_elections/__init__.py b/fedora_elections/__init__.py index 81e4b36..00ff7fa 100644 --- a/fedora_elections/__init__.py +++ b/fedora_elections/__init__.py @@ -23,6 +23,7 @@ # Frank Chiulli # Pierre-Yves Chibon # +from __future__ import unicode_literals, absolute_import __version__ = '2.7' @@ -36,10 +37,11 @@ import arrow # noqa from datetime import datetime, time, timedelta # noqa from functools import wraps # noqa -from urlparse import urlparse, urljoin # noqa +from six.moves.urllib.parse import urlparse, urljoin, urlencode # noqa import flask # noqa import munch # noqa +import six # noqa from fedora.client import AuthError, AppError # noqa from fedora.client.fas2 import AccountSystem # noqa @@ -126,7 +128,7 @@ def is_admin(user, user_groups=None): return False admins = APP.config['FEDORA_ELECTIONS_ADMIN_GROUP'] - if isinstance(admins, basestring): # pragma: no cover + if isinstance(admins, six.string_types): # pragma: no cover admins = set([admins]) else: admins = set(admins) @@ -189,7 +191,8 @@ def rjust_filter(text, length): @APP.template_filter('avatar') def avatar_filter(openid, size=64, default='retro'): - query = urllib.urlencode({'s': size, 'd': default}) + query = urlencode({'s': size, 'd': default}) + openid = openid.encode("utf-8") hashhex = hashlib.sha256(openid).hexdigest() return "https://seccdn.libravatar.org/avatar/%s?%s" % (hashhex, query) @@ -344,5 +347,5 @@ def auth_logout(): # Finalize the import of other controllers -import admin # noqa -import elections # noqa +import fedora_elections.admin # noqa +import fedora_elections.elections # noqa diff --git a/fedora_elections/admin.py b/fedora_elections/admin.py index c34694d..beab90e 100644 --- a/fedora_elections/admin.py +++ b/fedora_elections/admin.py @@ -23,6 +23,7 @@ # Frank Chiulli # Pierre-Yves Chibon # +from __future__ import unicode_literals, absolute_import from datetime import datetime, time from functools import wraps diff --git a/fedora_elections/default_config.py b/fedora_elections/default_config.py index 6799bf6..938cb53 100644 --- a/fedora_elections/default_config.py +++ b/fedora_elections/default_config.py @@ -5,6 +5,7 @@ Fedora elections default configuration. ''' import os from datetime import timedelta +from fedora_elections.mail_logging import MSG_FORMAT, ContextInjector # Set the time after which the session expires PERMANENT_SESSION_LIFETIME = timedelta(hours=1) @@ -25,6 +26,6 @@ FAS_CHECK_CERT = False OIDC_CLIENT_SECRETS = os.path.join(os.path.dirname( - os.path.abspath(__file__)), 'client_secrets.json') + os.path.abspath(__file__)), '..', 'client_secrets.json') OIDC_SCOPES = ['openid', 'email', 'profile', 'fedora'] OIDC_OPENID_REALM = 'http://localhost:5005/oidc_callback' diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py index 41a2804..a4c98c7 100644 --- a/fedora_elections/elections.py +++ b/fedora_elections/elections.py @@ -23,6 +23,7 @@ # Frank Chiulli # Pierre-Yves Chibon # +from __future__ import unicode_literals, absolute_import from datetime import datetime from functools import wraps diff --git a/fedora_elections/fedmsgshim.py b/fedora_elections/fedmsgshim.py index 1285b34..0336d16 100644 --- a/fedora_elections/fedmsgshim.py +++ b/fedora_elections/fedmsgshim.py @@ -4,6 +4,7 @@ :Author: Pierre-Yves Chibon """ +from __future__ import unicode_literals, absolute_import import warnings import logging diff --git a/fedora_elections/forms.py b/fedora_elections/forms.py index 1c3fb75..8fc90b0 100644 --- a/fedora_elections/forms.py +++ b/fedora_elections/forms.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals, absolute_import import flask import wtforms diff --git a/fedora_elections/mail_logging.py b/fedora_elections/mail_logging.py index 39562ad..c990b0e 100644 --- a/fedora_elections/mail_logging.py +++ b/fedora_elections/mail_logging.py @@ -22,6 +22,8 @@ ''' Mail handler for logging. ''' +from __future__ import unicode_literals, absolute_import + import logging import logging.handlers diff --git a/fedora_elections/models.py b/fedora_elections/models.py index b82af00..b447bb6 100644 --- a/fedora_elections/models.py +++ b/fedora_elections/models.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals, absolute_import from datetime import datetime diff --git a/fedora_elections/proxy.py b/fedora_elections/proxy.py index 8e2e6b1..e53890f 100644 --- a/fedora_elections/proxy.py +++ b/fedora_elections/proxy.py @@ -25,6 +25,7 @@ redirects are using ``https``. Source: http://flask.pocoo.org/snippets/35/ by Peter Hansen ''' +from __future__ import unicode_literals, absolute_import class ReverseProxied(object): diff --git a/fedora_elections/utils.py b/fedora_elections/utils.py index 4bf23d1..c90460a 100644 --- a/fedora_elections/utils.py +++ b/fedora_elections/utils.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals, absolute_import import fedora_elections diff --git a/tests/__init__.py b/tests/__init__.py index 68b0a3a..49b1449 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -34,6 +34,7 @@ from datetime import date from datetime import timedelta from functools import wraps +import six from contextlib import contextmanager from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker @@ -117,7 +118,7 @@ class ModelFlasktests(Modeltests): def setup_db(self): """ Add a calendar and some meetings so that we can play with something. """ - from test_vote import Votetests + from tests.test_vote import Votetests votes = Votetests('test_init_vote') votes.session = self.session votes.test_init_vote() @@ -184,7 +185,7 @@ class FakeUser(object): :arg groups: list of the groups in which this fake user is supposed to be. """ - if isinstance(groups, basestring): + if isinstance(groups, six.string_types): groups = [groups] self.groups = groups self.username = username diff --git a/tests/test_candidate.py b/tests/test_candidate.py index 90bdc08..aab8751 100644 --- a/tests/test_candidate.py +++ b/tests/test_candidate.py @@ -35,7 +35,7 @@ sys.path.insert(0, os.path.join(os.path.dirname( from fedora_elections import models from tests import Modeltests, TODAY -from test_election import Electiontests +from tests.test_election import Electiontests # pylint: disable=R0904 diff --git a/tests/test_vote.py b/tests/test_vote.py index 92f1e71..1f9adac 100644 --- a/tests/test_vote.py +++ b/tests/test_vote.py @@ -35,7 +35,7 @@ sys.path.insert(0, os.path.join(os.path.dirname( from fedora_elections import models from tests import Modeltests, TODAY -from test_candidate import Candidatetests +from tests.test_candidate import Candidatetests # pylint: disable=R0904