From ba789863d00e4de54e5cabd77aec8341f1a825dd Mon Sep 17 00:00:00 2001 From: Dan Rodriguez Date: Thu, 16 Mar 2017 16:38:34 -0400 Subject: [PATCH 1/3] Add Python 3 compatibility --- django_cas/__init__.py | 3 ++- django_cas/backends.py | 9 ++++----- django_cas/middleware.py | 3 +-- django_cas/models.py | 5 +++-- django_cas/views.py | 5 ++--- 5 files changed, 12 insertions(+), 13 deletions(-) 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/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") - From ce001c8b61946d3dd4d36d1bf1c92a1e45b4778a Mon Sep 17 00:00:00 2001 From: Dan Rodriguez Date: Thu, 16 Mar 2017 16:39:00 -0400 Subject: [PATCH 2/3] Make url patterns Django 1.10+ compatible --- django_cas/urls.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) 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"), +] From b7bc7ddb4436cbc8ea5264153fc74e247c1fe16c Mon Sep 17 00:00:00 2001 From: Dan Rodriguez Date: Thu, 16 Mar 2017 17:09:41 -0400 Subject: [PATCH 3/3] Bump version to 2.2.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', )