Skip to content

Commit

Permalink
Merge pull request #40 from zopefoundation/remove-im_self
Browse files Browse the repository at this point in the history
Replace deprecated and removed `im_self` with `__self__`.
  • Loading branch information
dataflake committed Apr 17, 2019
2 parents d465305 + 549e69f commit a5c5abf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Products/PluggableAuthService/PluggableAuthService.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,10 +884,10 @@ def _getObjectContext(self, v, request):
# this is not a method, we needn't treat it specially
c = innerparent

elif hasattr(v, 'im_self'):
elif hasattr(v, '__self__'):

# this is a method, we need to treat it specially
c = v.im_self
c = v.__self__
c = aq_inner(v)

# if pub's aq_parent or container is the request container, it
Expand Down
4 changes: 2 additions & 2 deletions Products/PluggableAuthService/PropertiedUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def getRolesInContext(self, object):
object = parent
continue

new = getattr(object, 'im_self', None)
new = getattr(object, '__self__', None)

if new is not None:

Expand Down Expand Up @@ -222,7 +222,7 @@ def allowed(self, object, object_roles=None):
inner_obj = parent
continue

new = getattr(inner_obj, 'im_self', None)
new = getattr(inner_obj, '__self__', None)

if new is not None:
inner_obj = aq_inner(new)
Expand Down
26 changes: 26 additions & 0 deletions Products/PluggableAuthService/tests/test_PluggableAuthService.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,32 @@ def test__getObjectContext_simple(self):
self.assertEqual(n, 'index_html')
self.assertEqual(v, published)

def test__getObjectContext_method(self):
"""It also works with a method on the object."""
zcuf = self._makeOne()

rc, root, folder, object = self._makeTree()

def faux_method(self):
pass

FauxObject.meth = faux_method
local_index = FauxObject('index_html').__of__(object)

request = self._makeRequest(
('folder', 'object', 'index_html', 'meth'),
RESPONSE=FauxResponse(),
PARENTS=[local_index, object, folder, root])

published = local_index.meth

a, c, n, v = zcuf._getObjectContext(published, request)

self.assertEqual(a, local_index)
self.assertEqual(c, published)
self.assertEqual(n, 'meth')
self.assertEqual(v, published)

def test__getObjectContext_acquired_from_folder(self):

zcuf = self._makeOne()
Expand Down
16 changes: 8 additions & 8 deletions Products/PluggableAuthService/tests/test_PropertiedUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
from .conformance import IPropertiedUser_conformance


class FauxMethod:
def faux_method(self, x):
"""Just a faux function object with local roles defined later."""
return None

def __init__(self, im_self, local_roles=()):

self.im_self = im_self
self.__ac_local_roles__ = local_roles
faux_method.__ac_local_roles__ = {'Group C': ('Manager', 'Owner')}


class FauxProtected(Implicit):
Expand Down Expand Up @@ -183,10 +183,10 @@ def test_getRolesInContext_weslayan(self):
user = self._makeOne()
user._addGroups(groups)

FauxProtected.method = faux_method
faux_self = FauxProtected({'Group A': ('Manager',)})
faux_method = FauxMethod(faux_self, {'Group C': ('Manager', 'Owner')})

local_roles = user.getRolesInContext(faux_method)
local_roles = user.getRolesInContext(faux_self.method)
self.assertEqual(len(local_roles), 1)
self.assertTrue('Manager' in local_roles)

Expand Down Expand Up @@ -271,10 +271,10 @@ def test_allowed_weslayan(self):
user = self._makeOne()
user._addGroups(groups)

FauxProtected.method = faux_method
faux_self = FauxProtected({'Group A': ('Manager',)})
faux_method = FauxMethod(faux_self, {'Group C': ('Manager', 'Owner')})

self.assertTrue(user.allowed(faux_method, ('Manager',)))
self.assertTrue(user.allowed(faux_self.method, ('Manager',)))


if __name__ == '__main__':
Expand Down

0 comments on commit a5c5abf

Please sign in to comment.