diff --git a/easyLDAP/easyLDAP_class_cache.py b/easyLDAP/easyLDAP_class_cache.py index 5d09625052b9fd2bf671f3796dbd92dee0361f55..24ebf535da1df6a96aeca50aeef7e1b7feca3bdd 100644 --- a/easyLDAP/easyLDAP_class_cache.py +++ b/easyLDAP/easyLDAP_class_cache.py @@ -41,12 +41,22 @@ class easyLDAP_cache_history: self.push = self._push_cache_history - def __init__(self, use_cache_history=True, config_defaults=EASY_LDAP): + def __init__(self, use_cache_history=True, cache_history=None, config_defaults=EASY_LDAP): self._method_aliases() - self.ldap_cache_undo_history = [] - self.ldap_cache_redo_history = [] + if cache_history is None: + self.ldap_cache_undo_history = [] + self.ldap_cache_redo_history = [] + else: + if use_cache_history: + if is_valid_cache_history(cache_history): + self.ldap_cache_undo_history = cache_history[0] + self.ldap_cache_redo_history = cache_history[1] + else: + raise easyLDAP_exceptions.CACHEHISTORY_INVALID + else: + raise easyLDAP_exceptions.CACHEHISTORY_INACTIVE # if we cache an ldapobject we have to divert self.ldap_cachetree to self.ldap_cacheobject if self.ldap_cachetree is None: @@ -60,6 +70,9 @@ class easyLDAP_cache_history: else: self.ldap_cache_history_size = self._default_cache_history_size + # in case we injected an else-where stored cache history, make sure the size is correct + self.resize_cache_history() + self.CONFIG=config_defaults def __deepcopy__(self,memo): @@ -210,14 +223,14 @@ class easyLDAP_cacheobject(easyLDAP_cache_history): ldap_cacheobject = [ [ '', {}, ], ] ldap_cacheobject_dn = '' - def __init__(self, ldap_cacheobject, use_cache_history=True, config_defaults=EASY_LDAP): + def __init__(self, ldap_cacheobject, use_cache_history=True, cache_history=None, config_defaults=EASY_LDAP): + easyLDAP_cache_history.__init__(self, cache_history=cache_history, config_defaults=config_defaults, use_cache_history=use_cache_history) + if is_pyldapobject(ldap_cacheobject, strict=False): self.set_cacheobject(ldap_cacheobject=ldap_cacheobject) else: raise easyLDAP_exceptions.NOT_A_PYTHON_LDAPOBJECT - easyLDAP_cache_history.__init__(self, config_defaults=config_defaults, use_cache_history=use_cache_history) - self.CONFIG = config_defaults def __deepcopy__(self,memo): diff --git a/easyLDAP/easyLDAP_class_object_base.py b/easyLDAP/easyLDAP_class_object_base.py index 29758b29a596e686b9b9581a0387f3448835fc72..fb742b6164b9fd850f6a4a30c47d0d0d6b599130 100644 --- a/easyLDAP/easyLDAP_class_object_base.py +++ b/easyLDAP/easyLDAP_class_object_base.py @@ -56,7 +56,7 @@ class easyLDAP_object(easyLDAP): self.flush = self.flush_cache self.clear = self.clear_cache - def __init__(self, dn_or_cacheobject, bind_dn=None, bind_pw=None, config_defaults=EASY_LDAP, update_schema_cache=False, use_cache_history=True, ldapsession=None): + def __init__(self, dn_or_cacheobject, bind_dn=None, bind_pw=None, config_defaults=EASY_LDAP, update_schema_cache=False, use_cache_history=True, cache_history=None, ldapsession=None): easyLDAP.__init__(self, bind_dn=bind_dn, bind_pw=bind_pw, config_defaults=config_defaults, update_schema_cache=update_schema_cache, ldapsession=ldapsession) diff --git a/easyLDAP/easyLDAP_exceptions.py b/easyLDAP/easyLDAP_exceptions.py index 22b7644fdb3e43eecdbe70f1a0e365d2467d3419..d0a17c63e32f9feb9f573035dd9b1994aa0771a0 100644 --- a/easyLDAP/easyLDAP_exceptions.py +++ b/easyLDAP/easyLDAP_exceptions.py @@ -66,6 +66,8 @@ _easyLDAP_cache_exceptions = { 'CACHEOBJECT_IS_SUBTREE': 'The given LDAP cache object has children and cannot be deleted with this method...', 'NO_SUCH_OBJECT_IN_CACHETREE': 'The given object could not be found in the cachetree.', 'CACHEHISTORY_INACTIVE': 'The LDAP cache history functionality has been deactived on class object construction (use_cache_history is False).', + 'CACHEHISTORY_INVALID': 'The given data structure is not usable as LDAP cache history.', + 'CACHEOBJECT_INVALID': 'The given data structure is not usable as LDAP cache object.', } _easyLDAP_object_exceptions = { 'ATTRIBUTE_NEEDS_OBJECTCLASS': 'Attribute needs an additional objectClass.',