Skip to content

Commit

Permalink
Merge pull request #106 from level12/88-remove-six
Browse files Browse the repository at this point in the history
Remove six dependency
  • Loading branch information
guruofgentoo committed Apr 1, 2020
2 parents 5fbd88a + bcae578 commit 477a415
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 39 deletions.
14 changes: 6 additions & 8 deletions keg_auth/core.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from blazeutils import tolist
import arrow
import flask
import flask_login
from keg.db import db
from keg.signals import db_init_post
import jinja2
import sqlalchemy as sa
import six
import arrow
from blazeutils import tolist
from keg.db import db
from keg.signals import db_init_post

import keg_auth.cli
from keg_auth.libs.authenticators import KegAuthenticator
from keg_auth import model

from keg_auth.libs.authenticators import KegAuthenticator

DEFAULT_CRYPTO_SCHEMES = ('bcrypt', 'pbkdf2_sha256',)

Expand Down Expand Up @@ -223,7 +221,7 @@ def url_for(self, ident, **kwargs):

def user_loader(self, session_key):
user_class = self.entity_registry.user_cls
return user_class.get_by(session_key=six.text_type(session_key))
return user_class.get_by(session_key=str(session_key))

def user_by_id(self, user_id):
user_class = self.entity_registry.user_cls
Expand Down
3 changes: 1 addition & 2 deletions keg_auth/extensions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import flask
import six

MORPHI_PACKAGE_NAME = 'keg_auth'

Expand Down Expand Up @@ -43,4 +42,4 @@ def ngettext(singular, plural, num, **variables):


def flash(message, category):
flask.flash(six.text_type(message), category)
flask.flash(str(message), category)
15 changes: 6 additions & 9 deletions keg_auth/libs/authenticators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from urllib.parse import urljoin, urlparse

import flask
import flask_login
import six
from six.moves import urllib

from keg_auth import forms
from keg_auth.extensions import (
flash,
lazy_gettext as _
)
from keg_auth.extensions import flash, lazy_gettext as _
from keg_auth.model import get_username_key

try:
Expand Down Expand Up @@ -70,7 +67,7 @@ def __init__(self, app):
self.init_responders()

def init_responders(self):
for key, cls in six.iteritems(self.responder_cls):
for key, cls in self.responder_cls.items():
self.responders[key] = cls(self)

def get_responder(self, key):
Expand Down Expand Up @@ -153,8 +150,8 @@ class LoginResponderMixin(UserResponderMixin):
def is_safe_url(target):
"""Returns `True` if the target is a valid URL for redirect"""
# from http://flask.pocoo.org/snippets/62/
ref_url = urllib.parse.urlparse(flask.request.host_url)
test_url = urllib.parse.urlparse(urllib.parse.urljoin(flask.request.host_url, target))
ref_url = urlparse(flask.request.host_url)
test_url = urlparse(urljoin(flask.request.host_url, target))
return (
test_url.scheme in ('http', 'https')
and ref_url.netloc == test_url.netloc
Expand Down
3 changes: 1 addition & 2 deletions keg_auth/libs/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from blazeutils.strings import simplify_string
import flask
import flask_login
import six

from keg_auth.extensions import lazy_gettext as _
from keg_auth.model.utils import has_permissions
Expand Down Expand Up @@ -132,7 +131,7 @@ class NavItemType(object):

def __init__(self, *args, nav_group=None, icon_class=None):
self.label = None
if len(args) and (isinstance(args[0], six.string_types) or is_lazy_string(args[0])):
if len(args) and (isinstance(args[0], str) or is_lazy_string(args[0])):
self.label = args[0]
args = args[1:]
self.route = None
Expand Down
7 changes: 3 additions & 4 deletions keg_auth/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import passlib.hash
import passlib.pwd
import shortuuid
import six
import sqlalchemy as sa
import sqlalchemy.orm as sa_orm
import sqlalchemy.sql as sa_sql
Expand Down Expand Up @@ -36,7 +35,7 @@ def _create_cryptcontext_kwargs(**column_kwargs):


def _generate_session_key():
return six.text_type(shortuuid.uuid())
return str(shortuuid.uuid())


class InvalidToken(Exception):
Expand Down Expand Up @@ -246,7 +245,7 @@ def token_verify(self, token):
"""
if not token:
return False
if isinstance(token, six.text_type):
if isinstance(token, str):
token = token.encode()

serializer = self.get_token_serializer(None)
Expand Down Expand Up @@ -297,7 +296,7 @@ def get_user_for_api_token(cls, api_token):
if api_token is None:
return

if isinstance(api_token, six.binary_type):
if isinstance(api_token, bytes):
api_token = api_token.decode()

if len(api_token.split('.')) != 2:
Expand Down
19 changes: 8 additions & 11 deletions keg_auth/testing.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# Using unicode_literals instead of adding 'u' prefix to all stings that go to SA.
from __future__ import unicode_literals

try:
from unittest import mock
except ImportError:
import mock
from urllib.parse import urlparse
from unittest import mock
from urllib.parse import quote, urlparse

from blazeutils import tolist
from blazeutils.containers import LazyDict
from six.moves import urllib
import flask
import flask_webtest
import passlib
import wrapt
from blazeutils import tolist
from blazeutils.containers import LazyDict


class AuthTests(object):
Expand Down Expand Up @@ -134,9 +130,10 @@ def test_next_parameter_not_open_redirect(self):

# quoted next parameter
client = flask_webtest.TestApp(flask.current_app)
resp = client.get('{}?next={}'.format(
flask.url_for(flask.current_app.auth_manager.endpoint('login')),
urllib.parse.quote(next)
resp = client.get(
'{}?next={}'.format(
flask.url_for(flask.current_app.auth_manager.endpoint('login')),
quote(next)
)
)

Expand Down
3 changes: 1 addition & 2 deletions keg_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import flask_login
import inflect
import keg.web
import six
import sqlalchemy as sa
from blazeutils.strings import case_cw2dash
from keg.db import db
Expand Down Expand Up @@ -76,7 +75,7 @@ def object_name_plural(self):
return self._inflect.plural(
self.object_name
if not is_lazy_string(self.object_name)
else six.text_type(self.object_name)
else str(self.object_name)
)

def page_title(self, action):
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
'inflect',
'passlib',
'shortuuid',
'six',
'webgrid',
],
# List additional groups of dependencies here (e.g. development
Expand Down

0 comments on commit 477a415

Please sign in to comment.