Skip to content

Commit

Permalink
Merge pull request #2 from hzdg/python3_django1_11
Browse files Browse the repository at this point in the history
Add Python 3 and Django 1.10+ compatibility
  • Loading branch information
talebbits authored Mar 16, 2017
2 parents 6d5474f + b7bc7dd commit b07f751
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
3 changes: 2 additions & 1 deletion django_cas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Django CAS 1.0/2.0 authentication backend"""

from django.conf import settings
from six import iteritems

__all__ = []

Expand 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:
Expand Down
9 changes: 4 additions & 5 deletions django_cas/backends.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions django_cas/middleware.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions django_cas/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 12 additions & 9 deletions django_cas/urls.py
Original file line number Diff line number Diff line change
@@ -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"),
]
5 changes: 2 additions & 3 deletions django_cas/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)

0 comments on commit b07f751

Please sign in to comment.