Skip to content

Commit

Permalink
Fix a couple more tests under Py3.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed May 2, 2017
1 parent ec1a4de commit ae0c96c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/AccessControl/AccessControl.txt
Expand Up @@ -205,7 +205,7 @@ Example:

__ac_types__=(

('Full Access', map(lambda x: x[0], __ac_permissions__)),
('Full Access', tuple(map(lambda x: x[0], __ac_permissions__))),
('Change', ['Add Objects', 'Add Properties', 'Change Properties']),

)
Expand Down
8 changes: 4 additions & 4 deletions src/AccessControl/rolemanager.py
Expand Up @@ -105,13 +105,13 @@ def permission_settings(self, permission=None):
d={'name': name,
'hashed_name': _string_hash(name),
'acquire': isinstance(roles, list) and 'CHECKED' or '',
'roles': map(
'roles': tuple(map(
lambda ir, roles=roles, valid=valid, ip=ip:
{
'name': "permission_%srole_%s" % (_string_hash(permission_name), _string_hash(valid[ir])),
'checked': (valid[ir] in roles) and 'CHECKED' or '',
},
indexes)
indexes))
}
ip = ip + 1
result.append(d)
Expand Down Expand Up @@ -243,12 +243,12 @@ def rolesOfPermission(self, permission):
if name==permission:
p = Permission(name, value, self)
roles = p.getRoles()
return map(
return tuple(map(
lambda role, roles=roles:
{'name': role,
'selected': role in roles and 'SELECTED' or '',
},
valid_roles)
valid_roles))

raise ValueError(
"The permission <em>%s</em> is invalid." % escape(permission))
Expand Down
24 changes: 18 additions & 6 deletions src/AccessControl/tainted.py
Expand Up @@ -19,8 +19,12 @@
"""

from cgi import escape
from functools import total_ordering

import six


@total_ordering
class TaintedString:

def __init__(self, value):
Expand All @@ -32,8 +36,15 @@ def __str__(self):
def __repr__(self):
return repr(self.quoted())

def __cmp__(self, o):
return cmp(self._value, o)
if six.PY2:
def __cmp__(self, o):
return cmp(self._value, o) # NOQA

def __eq__(self, o):
return self._value == o

def __lt__(self, o):
return self._value < o

def __hash__(self):
return hash(self._value)
Expand Down Expand Up @@ -76,8 +87,9 @@ def __int__(self):
def __float__(self):
return float(self._value)

def __long__(self):
return long(self._value)
if six.PY2:
def __long__(self):
return long(self._value) # NOQA

def __getstate__(self):
# If an object tries to store a TaintedString, it obviously wasn't
Expand Down Expand Up @@ -108,11 +120,11 @@ def replace(self, *args):

def split(self, *args):
r = self._value.split(*args)
return map(lambda v, c=self.__class__: '<' in v and c(v) or v, r)
return list(map(lambda v, c=self.__class__: '<' in v and c(v) or v, r))

def splitlines(self, *args):
r = self._value.splitlines(*args)
return map(lambda v, c=self.__class__: '<' in v and c(v) or v, r)
return list(map(lambda v, c=self.__class__: '<' in v and c(v) or v, r))

def translate(self, *args):
v = self._value.translate(*args)
Expand Down
16 changes: 10 additions & 6 deletions src/AccessControl/tests/test_tainted.py
Expand Up @@ -15,6 +15,8 @@

import unittest

import six


class TestTaintedString(unittest.TestCase):

Expand All @@ -34,9 +36,9 @@ def testRepr(self):
self.assertEquals(repr(self.tainted), repr(self.quoted))

def testCmp(self):
self.assertEquals(cmp(self.tainted, self.unquoted), 0)
self.assertEquals(cmp(self.tainted, 'a'), -1)
self.assertEquals(cmp(self.tainted, '.'), 1)
self.assertTrue(self.tainted == self.unquoted)
self.assertTrue(self.tainted < 'a')
self.assertTrue(self.tainted > '.')

def testHash(self):
hash = {}
Expand Down Expand Up @@ -147,9 +149,11 @@ def testStringMethods(self):
unquoted.translate(transtable))
self.assert_(isinstance(self._getClass()('<').translate(transtable),
self._getClass()))
self.failIf(isinstance(self._getClass()('<').translate(transtable,
'<'),
self._getClass()))
if six.PY2:
# Translate no longer supports a second argument
self.failIf(isinstance(self._getClass()('<').translate(transtable,
'<'),
self._getClass()))

def testQuoted(self):
self.assertEquals(self.tainted.quoted(), self.quoted)

0 comments on commit ae0c96c

Please sign in to comment.