summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@slide.com>2009-05-15 10:17:45 -0700
committerR. Tyler Ballance <tyler@slide.com>2009-05-15 10:17:45 -0700
commit1b33fd6e5464ed3093e6d7e922883543450a58e9 (patch)
treeb972f17f370baef2ac195388f1465cf3bce0f0f0
parentbd63352d085c948d9482464c8e08ebf3f35b3488 (diff)
downloadpython-cheetah-1b33fd6e5464ed3093e6d7e922883543450a58e9.tar.gz
Update some of the Cache related objects to new-style objects
Signed-off-by: R. Tyler Ballance <tyler@slide.com>
-rw-r--r--src/CacheRegion.py41
-rw-r--r--src/CacheStore.py5
-rw-r--r--src/Template.py45
3 files changed, 40 insertions, 51 deletions
diff --git a/src/CacheRegion.py b/src/CacheRegion.py
index afcc9b1..dd0d099 100644
--- a/src/CacheRegion.py
+++ b/src/CacheRegion.py
@@ -1,5 +1,6 @@
# $Id: CacheRegion.py,v 1.3 2006/01/28 04:19:30 tavis_rudd Exp $
-"""Cache holder classes for Cheetah:
+'''
+Cache holder classes for Cheetah:
Cache regions are defined using the #cache Cheetah directive. Each
cache region can be viewed as a dictionary (keyed by cacheRegionID)
@@ -16,31 +17,24 @@ in the following example::
The code above will generate a CacheRegion and add new cacheItem for each value
of $getArticleID().
-
-Meta-Data
-================================================================================
-Author: Tavis Rudd <tavis@damnsimple.com> and Philippe Normand <phil@base-art.net>
-Version: $Revision: 1.3 $
-Start Date: 2005/06/20
-Last Revision Date: $Date: 2006/01/28 04:19:30 $
-"""
-__author__ = "Tavis Rudd <tavis@damnsimple.com> and Philippe Normand <phil@base-art.net>"
-__revision__ = "$Revision: 1.3 $"[11:-2]
+'''
try:
from hashlib import md5
except ImportError:
from md5 import md5
-from time import time as currentTime
-from Cheetah.CacheStore import MemoryCacheStore
-class CacheItem:
- """A CacheItem is a container storing:
+import time
+import Cheetah.CacheStore
+
+class CacheItem(object):
+ '''
+ A CacheItem is a container storing:
- cacheID (string)
- refreshTime (timestamp or None) : last time the cache was refreshed
- data (string) : the content of the cache
- """
+ '''
def __init__(self, cacheItemID, cacheStore):
self._cacheItemID = cacheItemID
@@ -49,7 +43,7 @@ class CacheItem:
self._expiryTime = 0
def hasExpired(self):
- return (self._expiryTime and currentTime() > self._expiryTime)
+ return (self._expiryTime and time.time() > self._expiryTime)
def setExpiryTime(self, time):
self._expiryTime = time
@@ -58,7 +52,7 @@ class CacheItem:
return self._expiryTime
def setData(self, data):
- self._refreshTime = currentTime()
+ self._refreshTime = time.time()
self._cacheStore.set(self._cacheItemID, data, self._expiryTime)
def getRefreshTime(self):
@@ -76,7 +70,7 @@ class CacheItem:
self._cacheStore.delete(self._cacheItemID)
self._refreshTime = None
-class _CacheDataStoreWrapper:
+class _CacheDataStoreWrapper(object):
def __init__(self, dataStore, keyPrefix):
self._dataStore = dataStore
self._keyPrefix = keyPrefix
@@ -90,8 +84,9 @@ class _CacheDataStoreWrapper:
def set(self, key, val, time=0):
self._dataStore.set(self._keyPrefix+key, val, time=time)
-class CacheRegion:
- """ A `CacheRegion` stores some `CacheItem` instances.
+class CacheRegion(object):
+ '''
+ A `CacheRegion` stores some `CacheItem` instances.
This implementation stores the data in the memory of the current process.
If you need a more advanced data store, create a cacheStore class that works
@@ -99,7 +94,7 @@ class CacheRegion:
to __init__. For example you could use
Cheetah.CacheStore.MemcachedCacheStore, a wrapper around the Python
memcached API (http://www.danga.com/memcached).
- """
+ '''
_cacheItemClass = CacheItem
def __init__(self, regionID, templateCacheIdPrefix='', cacheStore=None):
@@ -107,7 +102,7 @@ class CacheRegion:
self._regionID = regionID
self._templateCacheIdPrefix = templateCacheIdPrefix
if not cacheStore:
- cacheStore = MemoryCacheStore()
+ cacheStore = Cheetah.CacheStore.MemoryCacheStore()
self._cacheStore = cacheStore
self._wrappedCacheDataStore = _CacheDataStoreWrapper(
cacheStore, keyPrefix=templateCacheIdPrefix+':'+regionID+':')
diff --git a/src/CacheStore.py b/src/CacheStore.py
index 88863da..9c41656 100644
--- a/src/CacheStore.py
+++ b/src/CacheStore.py
@@ -1,4 +1,4 @@
-"""
+'''
Provides several CacheStore backends for Cheetah's caching framework. The
methods provided by these classes have the same semantics as those in the
python-memcached API, except for their return values:
@@ -13,8 +13,7 @@ get(key, val)
returns val or raises a KeyError
delete(key)
deletes or raises a KeyError
-
-"""
+'''
import time
from Cheetah.Utils.memcache import Client as MemcachedClient
diff --git a/src/Template.py b/src/Template.py
index 1e8577e..2d6b7d3 100644
--- a/src/Template.py
+++ b/src/Template.py
@@ -1,20 +1,9 @@
#!/usr/bin/env python
-# $Id: Template.py,v 1.186 2008/03/10 04:48:11 tavis_rudd Exp $
-"""Provides the core API for Cheetah.
+'''
+Provides the core API for Cheetah.
See the docstring in the Template class and the Users' Guide for more information
-
-Meta-Data
-================================================================================
-Author: Tavis Rudd <tavis@damnsimple.com>
-License: This software is released for unlimited distribution under the
- terms of the MIT license. See the LICENSE file.
-Version: $Revision: 1.186 $
-Start Date: 2001/03/30
-Last Revision Date: $Date: 2008/03/10 04:48:11 $
-"""
-__author__ = "Tavis Rudd <tavis@damnsimple.com>"
-__revision__ = "$Revision: 1.186 $"[11:-2]
+'''
################################################################################
## DEPENDENCIES
@@ -47,8 +36,10 @@ try:
from threading import Lock
except ImportError:
class Lock:
- def acquire(self): pass
- def release(self): pass
+ def acquire(self):
+ pass
+ def release(self):
+ pass
from Cheetah.Version import convertVersionStringToTuple, MinCompatibleVersionTuple
from Cheetah.Version import MinCompatibleVersion
@@ -123,8 +114,9 @@ _formUsedByWebInput = None
# used in Template.compile()
def valOrDefault(val, default):
- if val is not Unspecified: return val
- else: return default
+ if val is not Unspecified:
+ return val
+ return default
def updateLinecache(filename, src):
import linecache
@@ -134,16 +126,18 @@ def updateLinecache(filename, src):
fullname = filename
linecache.cache[filename] = size, mtime, lines, fullname
-class CompileCacheItem:
+class CompileCacheItem(object):
pass
-class TemplatePreprocessor:
- """This is used with the preprocessors argument to Template.compile().
+class TemplatePreprocessor(object):
+ '''
+ This is used with the preprocessors argument to Template.compile().
See the docstring for Template.compile
-
+
** Preprocessors are an advanced topic **
- """
+ '''
+
def __init__(self, settings):
self._settings = settings
@@ -179,7 +173,8 @@ class TemplatePreprocessor:
return outputSource, outputFile
class Template(Servlet):
- """This class provides a) methods used by templates at runtime and b)
+ '''
+ This class provides a) methods used by templates at runtime and b)
methods for compiling Cheetah source code into template classes.
This documentation assumes you already know Python and the basics of object
@@ -255,7 +250,7 @@ class Template(Servlet):
Instance attributes look like this:
klass._CHEETAH__globalSetVars (_CHEETAH__xxx with 2 underscores)
- """
+ '''
# this is used by ._addCheetahPlumbingCodeToClass()
_CHEETAH_requiredCheetahMethods = (