[Checkins] SVN: Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/ PEP8
Hanno Schlichting
hannosch at hannosch.eu
Sun Jul 11 14:19:18 EDT 2010
Log message for revision 114613:
PEP8
Changed:
U Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py
U Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/RAMCacheManager.py
U Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/subscribers.py
U Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/tests/test_AcceleratedHTTPCacheManager.py
U Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py
-=-
Modified: Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py
===================================================================
--- Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py 2010-07-11 18:13:46 UTC (rev 114612)
+++ Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py 2010-07-11 18:19:17 UTC (rev 114613)
@@ -35,6 +35,7 @@
logger = logging.getLogger('Zope.AcceleratedHTTPCacheManager')
+
class AcceleratedHTTPCache (Cache):
# Note the need to take thread safety into account.
# Also note that objects of this class are not persistent,
@@ -66,12 +67,12 @@
# documented. (pot! kettle! black!)
phys_path = ob.getPhysicalPath()
- if self.hit_counts.has_key(phys_path):
+ if phys_path in self.hit_counts:
del self.hit_counts[phys_path]
purge_paths = (ob.absolute_url_path(), quote('/'.join(phys_path)))
# Don't purge the same path twice.
if purge_paths[0] == purge_paths[1]:
- purge_paths = purge_paths[:1]
+ purge_paths = purge_paths[:1]
results = []
for url in self.notify_urls:
if not url.strip():
@@ -81,8 +82,8 @@
u = url
else:
u = 'http://' + url
- (scheme, host, path, params, query, fragment
- ) = urlparse.urlparse(u)
+ (scheme, host, path, params, query,
+ fragment) = urlparse.urlparse(u)
if path.lower().startswith('/http://'):
path = path.lstrip('/')
for ob_path in purge_paths:
@@ -122,10 +123,10 @@
if u.getUserName() != 'Anonymous User':
anon = 0
phys_path = ob.getPhysicalPath()
- if self.hit_counts.has_key(phys_path):
+ if phys_path in self.hit_counts:
hits = self.hit_counts[phys_path]
else:
- self.hit_counts[phys_path] = hits = [0,0]
+ self.hit_counts[phys_path] = hits = [0, 0]
if anon:
hits[0] = hits[0] + 1
else:
@@ -136,7 +137,7 @@
# Set HTTP Expires and Cache-Control headers
seconds=self.interval
expires=rfc1123_date(time.time() + seconds)
- RESPONSE.setHeader('Last-Modified',rfc1123_date(time.time()))
+ RESPONSE.setHeader('Last-Modified', rfc1123_date(time.time()))
RESPONSE.setHeader('Cache-Control', 'max-age=%d' % seconds)
RESPONSE.setHeader('Expires', expires)
@@ -144,17 +145,18 @@
caches = {}
PRODUCT_DIR = __name__.split('.')[-2]
+
class AcceleratedHTTPCacheManager (CacheManager, SimpleItem):
' '
security = ClassSecurityInfo()
- security.setPermissionDefault('Change cache managers', ('Manager',))
+ security.setPermissionDefault('Change cache managers', ('Manager', ))
manage_options = (
- {'label':'Properties', 'action':'manage_main',
- 'help':(PRODUCT_DIR, 'Accel.stx'),},
- {'label':'Statistics', 'action':'manage_stats',
- 'help':(PRODUCT_DIR, 'Accel.stx'),},
+ {'label': 'Properties', 'action': 'manage_main',
+ 'help': (PRODUCT_DIR, 'Accel.stx')},
+ {'label': 'Statistics', 'action': 'manage_stats',
+ 'help': (PRODUCT_DIR, 'Accel.stx')},
) + CacheManager.manage_options + SimpleItem.manage_options
meta_type = 'Accelerated HTTP Cache Manager'
@@ -162,9 +164,9 @@
def __init__(self, ob_id):
self.id = ob_id
self.title = ''
- self._settings = {'anonymous_only':1,
- 'interval':3600,
- 'notify_urls':()}
+ self._settings = {'anonymous_only': 1,
+ 'interval': 3600,
+ 'notify_urls': ()}
self._resetCacheId()
def getId(self):
@@ -205,9 +207,9 @@
settings = REQUEST
self.title = str(title)
self._settings = {
- 'anonymous_only':settings.get('anonymous_only') and 1 or 0,
- 'interval':int(settings['interval']),
- 'notify_urls':tuple(settings['notify_urls']),}
+ 'anonymous_only': settings.get('anonymous_only') and 1 or 0,
+ 'interval': int(settings['interval']),
+ 'notify_urls': tuple(settings['notify_urls'])}
cache = self.ZCacheManager_getCache()
cache.initSettings(self._settings)
if REQUEST is not None:
@@ -268,10 +270,9 @@
manage_addAcceleratedHTTPCacheManagerForm = DTMLFile('dtml/addAccel',
globals())
+
def manage_addAcceleratedHTTPCacheManager(self, id, REQUEST=None):
' '
self._setObject(id, AcceleratedHTTPCacheManager(id))
if REQUEST is not None:
return self.manage_main(self, REQUEST)
-
-# FYI good resource: http://www.web-caching.com/proxy-caches.html
Modified: Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/RAMCacheManager.py
===================================================================
--- Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/RAMCacheManager.py 2010-07-11 18:13:46 UTC (rev 114612)
+++ Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/RAMCacheManager.py 2010-07-11 18:19:17 UTC (rev 114613)
@@ -122,8 +122,10 @@
self.entries[index] = CacheEntry(index, data, view_name)
def delEntry(self, index):
- try: del self.entries[index]
- except KeyError: pass
+ try:
+ del self.entries[index]
+ except KeyError:
+ pass
class RAMCache (Cache):
@@ -263,7 +265,7 @@
'size': size,
'counter': ac,
'views': views,
- 'entries': len(oc.entries)
+ 'entries': len(oc.entries),
}
rval.append(info)
return rval
@@ -333,32 +335,33 @@
caches = {}
PRODUCT_DIR = __name__.split('.')[-2]
+
class RAMCacheManager (CacheManager, SimpleItem):
- """Manage a RAMCache, which stores rendered data in RAM.
+ """Manage a RAMCache, which stores rendered data in RAM.
This is intended to be used as a low-level cache for
expensive Python code, not for objects published
under their own URLs such as web pages.
RAMCacheManager *can* be used to cache complete publishable
- pages, such as DTMLMethods/Documents and Page Templates,
+ pages, such as DTMLMethods/Documents and Page Templates,
but this is not advised: such objects typically do not attempt
to cache important out-of-band data such as 3xx HTTP responses,
and the client would get an erroneous 200 response.
- Such objects should instead be cached with an
- AcceleratedHTTPCacheManager and/or downstream
+ Such objects should instead be cached with an
+ AcceleratedHTTPCacheManager and/or downstream
caching.
"""
security = ClassSecurityInfo()
- security.setPermissionDefault('Change cache managers', ('Manager',))
+ security.setPermissionDefault('Change cache managers', ('Manager', ))
manage_options = (
- {'label':'Properties', 'action':'manage_main',
- 'help':(PRODUCT_DIR, 'RAM.stx'),},
- {'label':'Statistics', 'action':'manage_stats',
- 'help':(PRODUCT_DIR, 'RAM.stx'),},
+ {'label': 'Properties', 'action': 'manage_main',
+ 'help': (PRODUCT_DIR, 'RAM.stx')},
+ {'label': 'Statistics', 'action': 'manage_stats',
+ 'help': (PRODUCT_DIR, 'RAM.stx')},
) + CacheManager.manage_options + SimpleItem.manage_options
meta_type = 'RAM Cache Manager'
@@ -369,7 +372,7 @@
self._settings = {
'threshold': 1000,
'cleanup_interval': 300,
- 'request_vars': ('AUTHENTICATED_USER',),
+ 'request_vars': ('AUTHENTICATED_USER', ),
'max_age': 3600,
}
self._resetCacheId()
@@ -401,7 +404,7 @@
def getSettings(self):
'Returns the current cache settings.'
res = self._settings.copy()
- if not res.has_key('max_age'):
+ if 'max_age' not in res:
res['max_age'] = 0
return res
@@ -500,6 +503,7 @@
manage_addRAMCacheManagerForm = DTMLFile('dtml/addRCM', globals())
+
def manage_addRAMCacheManager(self, id, REQUEST=None):
'Adds a RAM cache manager to the folder.'
self._setObject(id, RAMCacheManager(id))
Modified: Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/subscribers.py
===================================================================
--- Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/subscribers.py 2010-07-11 18:13:46 UTC (rev 114612)
+++ Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/subscribers.py 2010-07-11 18:19:17 UTC (rev 114613)
@@ -19,8 +19,9 @@
"""
Reset the Id of the module level cache so the clone gets a different cache
than its source object
- """
+ """
obj._resetCacheId()
+
def removed(obj, event):
obj._remove_data()
Modified: Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/tests/test_AcceleratedHTTPCacheManager.py
===================================================================
--- Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/tests/test_AcceleratedHTTPCacheManager.py 2010-07-11 18:13:46 UTC (rev 114612)
+++ Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/tests/test_AcceleratedHTTPCacheManager.py 2010-07-11 18:19:17 UTC (rev 114613)
@@ -34,10 +34,12 @@
def absolute_url_path(self):
return self.urlpath
+
class MockResponse:
status = '200'
reason = "who knows, I'm just a mock"
+
def MockConnectionClassFactory():
# Returns both a class that mocks an HTTPConnection,
# and a reference to a data structure where it logs requests.
@@ -50,9 +52,9 @@
self.request_log = request_log
def request(self, method, path):
- self.request_log.append({'method':method,
- 'host':self.host,
- 'path':path,})
+ self.request_log.append({'method': method,
+ 'host': self.host,
+ 'path': path})
def getresponse(self):
return MockResponse()
@@ -117,7 +119,7 @@
def _makeContext(self):
from OFS.Folder import Folder
root = Folder()
- root.getPhysicalPath = lambda: ('', 'some_path',)
+ root.getPhysicalPath = lambda: ('', 'some_path', )
cm_id = 'http_cache'
manager = self._makeOne(cm_id)
root._setObject(cm_id, manager)
Modified: Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py
===================================================================
--- Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py 2010-07-11 18:13:46 UTC (rev 114612)
+++ Products.StandardCacheManagers/trunk/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py 2010-07-11 18:19:17 UTC (rev 114613)
@@ -39,9 +39,9 @@
action='unused_constructor_name',
permission="Add %ss" % instance_class.meta_type)
for instance_class in (RAMCacheManager,
- AcceleratedHTTPCacheManager)
- )
+ AcceleratedHTTPCacheManager))
+
class CacheManagerLocationTests(CopySupportTestBase):
_targetClass = None
@@ -49,7 +49,7 @@
def _makeOne(self, *args, **kw):
return self._targetClass(*args, **kw)
- def setUp( self ):
+ def setUp(self):
componenttesting.setUp()
eventtesting.setUp()
zcml.load_config('meta.zcml', zope.component)
@@ -63,7 +63,7 @@
self.folder2 = folder2
self.policy = UnitTestSecurityPolicy()
- self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
+ self.oldPolicy = SecurityManager.setSecurityPolicy(self.policy)
cm_id = 'cache'
manager = self._makeOne(cm_id)
@@ -71,14 +71,14 @@
self.cachemanager = self.folder1[cm_id]
transaction.savepoint(optimistic=True)
- newSecurityManager( None, UnitTestUser().__of__( self.root ) )
+ newSecurityManager(None, UnitTestUser().__of__(self.root))
CopySupportTestBase.setUp(self)
- def tearDown( self ):
+ def tearDown(self):
noSecurityManager()
- SecurityManager.setSecurityPolicy( self.oldPolicy )
+ SecurityManager.setSecurityPolicy(self.oldPolicy)
del self.oldPolicy
del self.policy
del self.folder2
@@ -115,14 +115,17 @@
new_cache = self.cachemanager.ZCacheManager_getCache()
self.assertNotEqual(old_cache, new_cache)
+
class AcceleratedHTTPCacheManagerLocationTests(CacheManagerLocationTests):
_targetClass = AcceleratedHTTPCacheManager
+
class RamCacheManagerLocationTests(CacheManagerLocationTests):
_targetClass = RAMCacheManager
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(AcceleratedHTTPCacheManagerLocationTests))
More information about the checkins
mailing list