summaryrefslogtreecommitdiff
path: root/paste/auth
diff options
context:
space:
mode:
authorCyril Roelandt <cyril.roelandt@enovance.com>2014-03-18 12:49:12 +0100
committerCyril Roelandt <cyril.roelandt@enovance.com>2014-03-18 12:49:12 +0100
commit674ae7718bc06a8b8c8b658075bf82c8198fb632 (patch)
tree0075bace24ead7f03ae7cb18935e4c707f71a860 /paste/auth
parent3cdb7e4227cbaad690b1c1557c03fa6da0decc36 (diff)
downloadpaste-674ae7718bc06a8b8c8b658075bf82c8198fb632.tar.gz
Python 3: use new names of standard library modules
Use "try/except ImportError" to try Python 2 and Python 3 names.
Diffstat (limited to 'paste/auth')
-rw-r--r--paste/auth/auth_tkt.py8
-rw-r--r--paste/auth/cas.py8
-rw-r--r--paste/auth/digest.py2
3 files changed, 11 insertions, 7 deletions
diff --git a/paste/auth/auth_tkt.py b/paste/auth/auth_tkt.py
index 280355b..e94f539 100644
--- a/paste/auth/auth_tkt.py
+++ b/paste/auth/auth_tkt.py
@@ -43,7 +43,11 @@ try:
except ImportError:
# mimic hashlib (will work for md5, fail for secure hashes)
import md5 as hashlib
-import Cookie
+try:
+ from http.cookies import SimpleCookie
+except ImportError:
+ # Python 2
+ from Cookie import SimpleCookie
from paste import request
from urllib import quote as url_quote
from urllib import unquote as url_unquote
@@ -123,7 +127,7 @@ class AuthTicket(object):
return v
def cookie(self):
- c = Cookie.SimpleCookie()
+ c = SimpleCookie()
c[self.cookie_name] = self.cookie_value().encode('base64').strip().replace('\n', '')
c[self.cookie_name]['path'] = '/'
if self.secure:
diff --git a/paste/auth/cas.py b/paste/auth/cas.py
index c3521a0..44e4e98 100644
--- a/paste/auth/cas.py
+++ b/paste/auth/cas.py
@@ -18,7 +18,7 @@ passed to the system so that it can be used as middleware at any stage
of processing. It has the secondary goal of allowing for other
authentication methods to be used concurrently.
"""
-import urllib
+from six.moves.urllib.parse import urlencode
from paste.request import construct_url
from paste.httpexceptions import HTTPSeeOther, HTTPForbidden
@@ -69,10 +69,10 @@ def AuthCASHandler(application, authority):
ticket = qs.pop().split("=", 1)[1]
environ['QUERY_STRING'] = "&".join(qs)
service = construct_url(environ)
- args = urllib.urlencode(
+ args = urlencode(
{'service': service,'ticket': ticket})
requrl = authority + "validate?" + args
- result = urllib.urlopen(requrl).read().split("\n")
+ result = urlopen(requrl).read().split("\n")
if 'yes' == result[0]:
environ['REMOTE_USER'] = result[1]
environ['AUTH_TYPE'] = 'cas'
@@ -80,7 +80,7 @@ def AuthCASHandler(application, authority):
exce = CASLoginFailure()
else:
service = construct_url(environ)
- args = urllib.urlencode({'service': service})
+ args = urlencode({'service': service})
location = authority + "login?" + args
exce = CASAuthenticate(location)
return exce.wsgi_application(environ, start_response)
diff --git a/paste/auth/digest.py b/paste/auth/digest.py
index 9b427aa..798f447 100644
--- a/paste/auth/digest.py
+++ b/paste/auth/digest.py
@@ -36,7 +36,7 @@ try:
except ImportError:
from md5 import md5
import time, random
-from urllib import quote as url_quote
+from six.moves.urllib.parse import quote as url_quote
def _split_auth_string(auth_string):
""" split a digest auth string into individual key=value strings """