[Zope3-checkins] CVS: Zope3/src/zope/app/services - configure.zcml:1.32 module.py:1.7

Guido van Rossum guido@python.org
Thu, 29 May 2003 17:53:31 -0400


Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv29317

Modified Files:
	configure.zcml module.py 
Log Message:
Add an IFileFactory factory for persistent modules.
You can now create a file "foo.bar.py" and it will become a persistent
module named "foo.bar".


=== Zope3/src/zope/app/services/configure.zcml 1.31 => 1.32 ===
--- Zope3/src/zope/app/services/configure.zcml:1.31	Thu May 29 17:33:08 2003
+++ Zope3/src/zope/app/services/configure.zcml	Thu May 29 17:53:31 2003
@@ -520,5 +520,13 @@
   permission="zope.ManageContent"
   />
 
+<adapter 
+  for="zope.app.interfaces.services.folder.ISiteManagementFolder"
+  provides="zope.app.interfaces.file.IFileFactory"
+  name=".py"
+  factory=".module.ModuleFactory"
+  permission="zope.ManageContent"
+  />
+
 
 </zopeConfigure>


=== Zope3/src/zope/app/services/module.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/services/module.py:1.6	Thu May 29 17:33:09 2003
+++ Zope3/src/zope/app/services/module.py	Thu May 29 17:53:31 2003
@@ -29,6 +29,8 @@
 
 from zope.app.fssync.classes import ObjectEntryAdapter, AttrMapping
 from zope.app.interfaces.fssync import IObjectFile
+from zope.app.interfaces.file import IFileFactory
+from zope.context import ContextWrapper
 
 
 class Registry:
@@ -107,7 +109,7 @@
 
 class ModuleAdapter(ObjectEntryAdapter):
 
-    __implements__ =  IObjectFile
+    implements(IObjectFile)
 
     def getBody(self):
         return self.context.source
@@ -117,3 +119,19 @@
 
     def extra(self):
         return AttrMapping(self.context, ("name",))
+
+
+class ModuleFactory(object):
+
+    implements(IFileFactory)
+
+    def __init__(self, context):
+        self.context = context
+
+    def __call__(self, name, content_type, data):
+        assert name.endswith(".py")
+        name = name[:-3]
+        m = Manager()
+        m = ContextWrapper(m, self.context)
+        m.new(name, data)
+        return m