src/pyams_utils/cache.py
branchdev-tf
changeset 408 cf2304af0fab
parent 380 c062ab4db6cd
--- a/src/pyams_utils/cache.py	Wed Nov 20 19:26:23 2019 +0100
+++ b/src/pyams_utils/cache.py	Fri Nov 22 18:51:37 2019 +0100
@@ -21,8 +21,6 @@
 A TALES helper extension is also provided to get an object's cache key from a Chameleon template.
 """
 
-__docformat__ = 'restructuredtext'
-
 from persistent.interfaces import IPersistent
 from zope.interface import Interface
 
@@ -31,25 +29,32 @@
 from pyams_utils.interfaces.tales import ITALESExtension
 
 
+__docformat__ = 'restructuredtext'
+
+
 @adapter_config(context=object, provides=ICacheKeyValue)
 def object_cache_key_adapter(obj):
+    """Cache key adapter for any object"""
     return str(id(obj))
 
 
 @adapter_config(context=str, provides=ICacheKeyValue)
 def string_cache_key_adapter(obj):
+    """Cache key adapter for string value"""
     return obj
 
 
 @adapter_config(context=IPersistent, provides=ICacheKeyValue)
 def persistent_cache_key_adapter(obj):
+    """Cache key adapter for persistent object"""
+    # pylint: disable=protected-access
     if obj._p_oid:
         return str(int.from_bytes(obj._p_oid, byteorder='big'))
-    else:  # unsaved object
-        return str(id(obj))
+    return str(id(obj))
 
 
-@adapter_config(name='cache_key', context=(Interface, Interface, Interface), provides=ITALESExtension)
+@adapter_config(name='cache_key', context=(Interface, Interface, Interface),
+                provides=ITALESExtension)
 class CacheKeyTalesExtension(ContextRequestViewAdapter):
     """extension:cache_key(context) TALES extension
 
@@ -57,6 +62,7 @@
     """
 
     def render(self, context=None):
+        """Rendering of TALES extension"""
         if context is None:
             context = self.request.context
         return ICacheKeyValue(context)