summaryrefslogtreecommitdiff
path: root/tests/test_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 /tests/test_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 'tests/test_auth')
-rw-r--r--tests/test_auth/test_auth_cookie.py10
-rw-r--r--tests/test_auth/test_auth_digest.py7
2 files changed, 12 insertions, 5 deletions
diff --git a/tests/test_auth/test_auth_cookie.py b/tests/test_auth/test_auth_cookie.py
index 1cf50c2..876f24f 100644
--- a/tests/test_auth/test_auth_cookie.py
+++ b/tests/test_auth/test_auth_cookie.py
@@ -2,12 +2,18 @@
# This module is part of the Python Paste Project and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
+import os
+try:
+ # Python 3
+ from http.cookies import SimpleCookie
+except ImportError:
+ # Python 2
+ from Cookie import SimpleCookie
+
from paste.auth import cookie
from paste.wsgilib import raw_interactive, dump_environ
from paste.response import header_value
from paste.httpexceptions import *
-from Cookie import SimpleCookie
-import urllib2, os
def build(application,setenv, *args, **kwargs):
def setter(environ, start_response):
diff --git a/tests/test_auth/test_auth_digest.py b/tests/test_auth/test_auth_digest.py
index 4721db3..55f953d 100644
--- a/tests/test_auth/test_auth_digest.py
+++ b/tests/test_auth/test_auth_digest.py
@@ -57,7 +57,8 @@ def test_digest():
#
if os.environ.get("TEST_SOCKET",""):
- import urllib2
+ from six.moves.urllib.error import HTTPError
+ from six.moves.urllib.request import build_opener, HTTPDigestAuthHandler
from paste.debug.testserver import serve
server = serve(application)
@@ -66,9 +67,9 @@ if os.environ.get("TEST_SOCKET",""):
import socket
socket.setdefaulttimeout(5)
uri = ("http://%s:%s" % server.server_address) + path
- auth = urllib2.HTTPDigestAuthHandler()
+ auth = HTTPDigestAuthHandler()
auth.add_password(realm,uri,username,password)
- opener = urllib2.build_opener(auth)
+ opener = build_opener(auth)
result = opener.open(uri)
return result.read()