How does this code work (IMO it doesn't), ldap2.py

    def find_entries(self, filter=None, attrs_list=None, base_dn=None,
                     scope=_ldap.SCOPE_SUBTREE, time_limit=None,
size_limit=None, search_refs=False, paged_search=False):

        def _get_limits():
            """Get configured global limits, caching them for more calls"""
            if not _lims:
                config = self.get_ipa_config()
_lims['time'] = int(config.get('ipasearchtimelimit', [None])[0]) _lims['size'] = int(config.get('ipasearchrecordslimit', [None])[0])
            return _lims
        _lims = {}

        if time_limit is None:
            time_limit = _get_limits()['time']
        if size_limit is None:
            size_limit = _get_limits()['size']

Code above is supposed to do caching, but it doesn't do it. This might work if _lims were self._lims.
I tried similar code to test this behavior:

class test:
    def __init__(self):
       pass

    def cached_call(self):
       """configured global limits"""
       _lims = {}
       def _get_limits():
           if not _lims:
               _lims['t']='oujeee'
               print 'getting limits'
           return _lims

       print "Limits:", _get_limits()['t']

t = test()
t.cached_call()
t.cached_call()
t.cached_call()
t.cached_call()

Output:
$ python testcaching.py
Limits: getting limits
oujeee
Limits: getting limits
oujeee
Limits: getting limits
oujeee
Limits: getting limits
oujeee

So it does not do caching, or am I wrong?
Martin^2

--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to