diff --git a/django_cas/__init__.py b/django_cas/__init__.py index 87422ba..f66494d 100644 --- a/django_cas/__init__.py +++ b/django_cas/__init__.py @@ -1,6 +1,7 @@ """Django CAS 1.0/2.0 authentication backend""" from django.conf import settings +from six import iteritems __all__ = [] @@ -19,7 +20,7 @@ CAS_URI = 'http://www.yale.edu/tp/cas' CAS = '{%s}' % CAS_URI -for key, value in _DEFAULTS.iteritems(): +for key, value in iteritems(_DEFAULTS): try: getattr(settings, key) except AttributeError: diff --git a/django_cas/backends.py b/django_cas/backends.py index 09c4460..e4539d0 100644 --- a/django_cas/backends.py +++ b/django_cas/backends.py @@ -1,7 +1,6 @@ """CAS authentication backend""" - -import urllib -from urlparse import urljoin +from six.moves.urllib.request import urlopen +from six.moves.urllib.parse import urljoin, urlencode from django.conf import settings from django.core.exceptions import ObjectDoesNotExist @@ -56,9 +55,9 @@ def _verify_cas2(ticket, service): params = {'ticket': ticket, 'service': service} url = (urljoin(settings.CAS_SERVER_URL, 'proxyValidate') + '?' + - urllib.urlencode(params)) + urlencode(params)) - page = urllib.urlopen(url) + page = urlopen(url) response = page.read() tree = ElementTree.fromstring(response) page.close() diff --git a/django_cas/middleware.py b/django_cas/middleware.py index fd0dbb0..59cb620 100644 --- a/django_cas/middleware.py +++ b/django_cas/middleware.py @@ -1,6 +1,5 @@ """CAS authentication middleware""" - -from urllib import urlencode +from six.moves.urllib.parse import urlencode from django.http import HttpResponseRedirect, HttpResponseForbidden from django.conf import settings diff --git a/django_cas/models.py b/django_cas/models.py index 30d1c85..f569153 100644 --- a/django_cas/models.py +++ b/django_cas/models.py @@ -1,5 +1,6 @@ -from urlparse import urljoin -from urllib import urlencode, urlopen +from six.moves.urllib.request import urlopen +from six.moves.urllib.parse import urljoin, urlencode + from django.db import models from django.conf import settings from django.core.exceptions import ObjectDoesNotExist diff --git a/django_cas/urls.py b/django_cas/urls.py index 97e10c3..d06edc1 100644 --- a/django_cas/urls.py +++ b/django_cas/urls.py @@ -1,11 +1,14 @@ __author__ = 'sannies' -from django.conf.urls.defaults import patterns, url - - -urlpatterns = patterns('django_cas.views', - url(r'^login$', "login", name="cas_login"), - url(r'^logout$', "logout", name="cas_logout"), - url(r'^proxycallback$', "proxy_callback", name="cas_proxy_callback"), - -) +try: + from django.conf.urls.defaults import url +except ImportError: + from django.conf.urls import url + +from .views import login, logout, proxy_callback + +urlpatterns = [ + url(r'^login$', login, name="cas_login"), + url(r'^logout$', logout, name="cas_logout"), + url(r'^proxycallback$', proxy_callback, name="cas_proxy_callback"), +] diff --git a/django_cas/views.py b/django_cas/views.py index 11633d0..7d988ad 100644 --- a/django_cas/views.py +++ b/django_cas/views.py @@ -1,7 +1,7 @@ """CAS login/logout replacement views""" +from six.moves.urllib.parse import urljoin, urlencode + from datetime import datetime -from urllib import urlencode -from urlparse import urljoin from django.contrib import messages from django.http import HttpResponseRedirect, HttpResponseForbidden, HttpResponse from django.conf import settings @@ -129,4 +129,3 @@ def proxy_callback(request): return HttpResponse('PGT storage failed for %s' % str(request.GET), mimetype="text/plain") return HttpResponse('Success', mimetype="text/plain") - diff --git a/setup.py b/setup.py index 359509d..0255216 100755 --- a/setup.py +++ b/setup.py @@ -36,5 +36,5 @@ name='django-cas-hz', packages=['django_cas'], url='https://github.com/castlabs/django-cas', - version='2.1.2', + version='2.2.0', )