/usr/share/pyshared/Pyblosxom/cache/base.py is in pyblosxom 1.5.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | #######################################################################
# This file is part of Pyblosxom.
#
# Copyright (C) 2003-2011 by the Pyblosxom team. See AUTHORS.
#
# Pyblosxom is distributed under the MIT license. See the file
# LICENSE for distribution details.
#######################################################################
"""
The cache base class. Subclasses of this class provide caching for
blog entry data in Pyblosxom.
"""
class BlosxomCacheBase:
"""
Base Class for Caching stories in pyblosxom.
A cache is a disposable piece of data that gets updated when an entry
is in a fresh state.
Drivers are to subclass this object, overriding methods defined in
this class. If there is an error in creating cache data, be as quite
as possible, document how a user could check whether his cache works.
Driver should expect empty caches and should attempt to create them from
scratch.
@ivar _config: String containing config on where to store the cache.
The value of config is derived from C{py['cacheConfig']} in config.py.
@type _config: string
"""
def __init__(self, req, config):
"""
Constructor - setup and load up the cache
@param req: the request object
@type req: Request
@param config: String containing config on where to store the cache
@type config: string
"""
self._request = req
self._config = config
self._entryid = ""
self._entrydata = {}
def load(self, entryid):
"""
Try to load up the cache with entryid (a unique key for the entry)
@param entryid: The key identifier for your cache
@type entryid: string
"""
self._entryid = entryid # The filename of the entry
self._entrydata = {} # The data of the entry
def getEntry(self):
"""
Gets the data from the cache, returns a dict or an empty dict.
"""
return self._entrydata
def isCached(self):
"""
Returns 0 or 1 based on whether there is cached data, returns 0 is
cache data is stale
@returns: 0 or 1 based on cache
@rtype: boolean
"""
return 0
def saveEntry(self, entrydata):
"""
Store entrydata in cache
@param entrydata: The payload, usually a dict
@type entrydata: dict
"""
pass
def rmEntry(self):
"""
Remove cache entry: This is not used by pyblosxom, but used by
utilities.
"""
pass
def close(self):
"""
Override this to close your cache if necessary.
"""
pass
def __getitem__(self, key):
"""
Convenience function to make this class look like a dict.
"""
self.load(key)
if not self.has_key(key):
raise KeyError
return self.getEntry()
def __setitem__(self, key, value):
"""
Synonymous to L{saveEntry}
"""
self.load(key)
self.saveEntry(value)
def __delitem__(self, key):
"""
Convenience function to make this look more like a dict.
"""
self.load(key)
self.rmEntry()
def has_key(self, key):
"""
Convenience function to make this look more like a dict.
"""
self.load(key)
return self.isCached()
def keys(self):
"""
List out a list of keys for the cache, to be overridden by a subclass
if a full dict interface is required.
"""
return []
def get(self, key, default=None):
"""
Convenience function to make this look more like a dict.
"""
try:
return self.__getitem__(key)
except KeyError:
return default
class BlosxomCache(BlosxomCacheBase):
"""
A null cache.
"""
pass
|