summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-22 00:21:48 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-22 00:21:48 +0200
commit82f13b6240a5a0e92f68291d90bef7e75d82a3ee (patch)
treed412337af5252289ca2d9c1ee1ef46d3896cf2a1
parent1dd31fde1a4edc7fd2f66a738125231ba5c176ae (diff)
downloadpaste-82f13b6240a5a0e92f68291d90bef7e75d82a3ee.tar.gz
Fix grantip on Python 3
-rw-r--r--paste/auth/grantip.py2
-rw-r--r--tests/test_grantip.py19
2 files changed, 12 insertions, 9 deletions
diff --git a/paste/auth/grantip.py b/paste/auth/grantip.py
index 2ee9bcf..3fe6e1c 100644
--- a/paste/auth/grantip.py
+++ b/paste/auth/grantip.py
@@ -62,7 +62,7 @@ class GrantIPMiddleware(object):
def _set_roles(self, environ, roles):
cur_roles = environ.get('REMOTE_USER_TOKENS', '').split(',')
# Get rid of empty roles:
- cur_roles = filter(None, cur_roles)
+ cur_roles = list(filter(None, cur_roles))
remove_roles = []
for role in roles:
if role.startswith('-'):
diff --git a/tests/test_grantip.py b/tests/test_grantip.py
index 8d74280..2ddf7f1 100644
--- a/tests/test_grantip.py
+++ b/tests/test_grantip.py
@@ -4,11 +4,14 @@ from paste.fixture import *
def test_make_app():
def application(environ, start_response):
start_response('200 OK', [('content-type', 'text/plain')])
- return [
+ lines = [
str(environ.get('REMOTE_USER')),
':',
str(environ.get('REMOTE_USER_TOKENS')),
]
+ if six.PY3:
+ lines = [line.encode('utf8') for line in lines]
+ return lines
ip_map = {
'127.0.0.1': (None, 'system'),
'192.168.0.0/16': (None, 'worker'),
@@ -24,11 +27,11 @@ def test_req():
def doit(remote_addr):
res = app.get('/', extra_environ={'REMOTE_ADDR': remote_addr})
return res.body
- assert doit('127.0.0.1') == 'None:system'
- assert doit('192.168.15.12') == 'None:worker'
- assert doit('192.168.0.4') == 'None:worker'
+ assert doit('127.0.0.1') == b'None:system'
+ assert doit('192.168.15.12') == b'None:worker'
+ assert doit('192.168.0.4') == b'None:worker'
result = doit('192.168.0.5')
- assert result.startswith('bob:')
- assert 'editor' in result and 'worker' in result
- assert result.count(',') == 1
- assert doit('192.168.0.8') == 'None:editor'
+ assert result.startswith(b'bob:')
+ assert b'editor' in result and b'worker' in result
+ assert result.count(b',') == 1
+ assert doit('192.168.0.8') == b'None:editor'