[Checkins] SVN: lovely.memcached/trunk/src/lovely/memcached/configurator.py make configurator configurable

Bernd Dorn bernd.dorn at lovelysystems.com
Tue Apr 3 03:37:00 EDT 2007


Log message for revision 73986:
  make configurator configurable

Changed:
  U   lovely.memcached/trunk/src/lovely/memcached/configurator.py

-=-
Modified: lovely.memcached/trunk/src/lovely/memcached/configurator.py
===================================================================
--- lovely.memcached/trunk/src/lovely/memcached/configurator.py	2007-04-03 00:22:22 UTC (rev 73985)
+++ lovely.memcached/trunk/src/lovely/memcached/configurator.py	2007-04-03 07:36:59 UTC (rev 73986)
@@ -19,20 +19,38 @@
 import interfaces
 import utility
 from zope import component
+from zope.interface.interfaces import IMethod
+from zope import schema
 from z3c.configurator import configurator
 from zope.app.component.interfaces import ISite
 from zope.lifecycleevent import ObjectCreatedEvent
 import zope.event
 from zope.security.proxy import removeSecurityProxy
 
-class SetUpMemcachedClient(configurator.ConfigurationPluginBase):
+class IMemcachedClientProperties(interfaces.IMemcachedClient):
+
+    name = schema.TextLine(title=u'Name',
+                           required=False,
+                           default=u'')
+    
+class SetUpMemcachedClient(configurator.SchemaConfigurationPluginBase):
     component.adapts(ISite)
+    schema = IMemcachedClientProperties
+    
+    def __call__(self, data):
 
-    def __call__(self, data):
+        for name in self.schema:
+            field = self.schema[name]
+            if IMethod.providedBy(field):
+                continue
+            if data.get(name) is None:
+                data[name] = self.schema[name].default
+        name = data.get('name')
         site = self.context
         # we just wanna have one
         util = component.queryUtility(interfaces.IMemcachedClient,
-                                      context=site)
+                                      context=site,
+                                      name=name)
         if util is not None:
             return
         # needed to be called TTW
@@ -40,5 +58,9 @@
         default = sm['default']
         util = utility.MemcachedClient()
         zope.event.notify(ObjectCreatedEvent(util))
-        default['memcachedclient'] = util
-        sm.registerUtility(util, interfaces.IMemcachedClient)
+        for attr in ['trackKeys', 'defaultNS', 'servers',
+                     'defaultLifetime']:
+            setattr(util, attr, data[attr])
+        default[u'memcachedclient_' + name] = util
+        sm.registerUtility(util, interfaces.IMemcachedClient,
+                           name=name)



More information about the Checkins mailing list