summaryrefslogtreecommitdiff
path: root/tests
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
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')
-rw-r--r--tests/test_auth/test_auth_cookie.py10
-rw-r--r--tests/test_auth/test_auth_digest.py7
-rw-r--r--tests/test_fileapp.py11
-rw-r--r--tests/test_gzipper.py5
-rw-r--r--tests/test_multidict.py4
-rw-r--r--tests/test_request_form.py3
6 files changed, 29 insertions, 11 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()
diff --git a/tests/test_fileapp.py b/tests/test_fileapp.py
index edb4e4c..c0013fb 100644
--- a/tests/test_fileapp.py
+++ b/tests/test_fileapp.py
@@ -1,10 +1,17 @@
# (c) 2005 Ian Bicking, Clark C. Evans and contributors
# 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 string
+import time
+try:
+ # Python 3
+ from email.utils import parsedate_tz, mktime_tz
+except ImportError:
+ # Python 2
+ from rfc822 import parsedate_tz, mktime_tz
+
from paste.fileapp import *
from paste.fixture import *
-from rfc822 import parsedate_tz, mktime_tz
-import time, string
def test_data():
harness = TestApp(DataApp('mycontent'))
diff --git a/tests/test_gzipper.py b/tests/test_gzipper.py
index 0832700..4f929b0 100644
--- a/tests/test_gzipper.py
+++ b/tests/test_gzipper.py
@@ -1,6 +1,7 @@
from paste.fixture import TestApp
from paste.gzipper import middleware
-import gzip, cStringIO
+import gzip
+from six.moves import cStringIO as StringIO
def simple_app(environ, start_response):
start_response('200 OK', [('content-type', 'text/plain')])
@@ -14,5 +15,5 @@ def test_gzip():
'/', extra_environ=dict(HTTP_ACCEPT_ENCODING='gzip'))
assert int(res.header('content-length')) == len(res.body)
assert res.body != 'this is a test'
- actual = gzip.GzipFile(fileobj=cStringIO.StringIO(res.body)).read()
+ actual = gzip.GzipFile(fileobj=StringIO(res.body)).read()
assert actual == 'this is a test'
diff --git a/tests/test_multidict.py b/tests/test_multidict.py
index c99b10f..893bfcd 100644
--- a/tests/test_multidict.py
+++ b/tests/test_multidict.py
@@ -2,8 +2,10 @@
# (c) 2007 Ian Bicking and Philip Jenvey; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
import cgi
+from six.moves import StringIO
+
from nose.tools import assert_raises
-from StringIO import StringIO
+
from paste.fixture import TestApp
from paste.wsgiwrappers import WSGIRequest
from paste.util.multidict import MultiDict, UnicodeMultiDict
diff --git a/tests/test_request_form.py b/tests/test_request_form.py
index 321b3b0..036da3e 100644
--- a/tests/test_request_form.py
+++ b/tests/test_request_form.py
@@ -1,5 +1,6 @@
import cgi
-from cStringIO import StringIO
+from six.moves import cStringIO as StringIO
+
from paste.request import *
from paste.util.multidict import MultiDict