[Zope3-checkins]
SVN: Zope3/branches/srichter-blow-services/src/zope/app/module/
Starting to fix persistent modules.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Jan 10 16:58:02 EST 2005
Log message for revision 28776:
Starting to fix persistent modules.
Changed:
U Zope3/branches/srichter-blow-services/src/zope/app/module/__init__.py
U Zope3/branches/srichter-blow-services/src/zope/app/module/browser/__init__.py
D Zope3/branches/srichter-blow-services/src/zope/app/module/browser/add_module.pt
U Zope3/branches/srichter-blow-services/src/zope/app/module/browser/browse_module.pt
U Zope3/branches/srichter-blow-services/src/zope/app/module/browser/configure.zcml
D Zope3/branches/srichter-blow-services/src/zope/app/module/browser/edit_module.pt
U Zope3/branches/srichter-blow-services/src/zope/app/module/configure.zcml
D Zope3/branches/srichter-blow-services/src/zope/app/module/xxx_tests/
-=-
Modified: Zope3/branches/srichter-blow-services/src/zope/app/module/__init__.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/module/__init__.py 2005-01-10 16:06:39 UTC (rev 28775)
+++ Zope3/branches/srichter-blow-services/src/zope/app/module/__init__.py 2005-01-10 21:58:02 UTC (rev 28776)
@@ -17,106 +17,45 @@
"""
__docformat__ = 'restructuredtext'
import sys
-from persistent import Persistent
-from zodbcode.module import PersistentModule, compileModule
+import zodbcode.interfaces
from zope.interface import implements
-from zope.security.proxy import removeSecurityProxy
-
from zope.app import zapi
-from zope.app.annotation.interfaces import IAttributeAnnotatable
-from zope.app.filerepresentation.interfaces import IFileFactory
from zope.app.module.interfaces import IModuleManager
-from zope.app.container.contained import Contained
-class Manager(Persistent, Contained):
- implements(IModuleManager, IAttributeAnnotatable)
+class ZopeModuleRegistry(object):
+ """ """
+ implements(zodbcode.interfaces.IPersistentModuleImportRegistry)
- def __init__(self, name, source):
- self.name = name
- self._source = None
- self.source = source
+ def findModule(self, name):
+ """See zodbcode.interfaces.IPersistentModuleImportRegistry"""
+ return zapi.getUtility(IModuleManager, name)
- def __setstate__(self, state):
- manager = state.get('_manager')
- if manager is None:
- return Persistent.__setstate__(self, state)
+ def modules(self):
+ """See zodbcode.interfaces.IPersistentModuleImportRegistry"""
+ return [name
+ for name, modulemgr in zapi.getUtilitiesFor(IModuleManager)]
- # We need to convert an old-style manager
- self._module = manager._module
- self.name = manager.name
- self._source = manager.source
- self._recompile = False
+# Make Zope Module Registry a singelton
+ZopeModuleRegistry = ZopeModuleRegistry()
- def execute(self):
- try:
- mod = self._module
- except AttributeError:
- mod = self._module = PersistentModule(self.name)
+def findModule(name, context=None):
+ """Find the module matching the provided name."""
+ module = ZopeModuleRegistry.findModule(name)
+ return module or sys.modules.get(name)
- folder = self.__parent__
+def resolve(name, context=None):
+ """Resolve a dotted name to a Python object."""
+ pos = name.rfind('.')
+ mod = findModule(name[:pos], context)
+ return getattr(mod, name[pos+1:])
- # TODO:
- # We are currently only supporting trusted code.
- # We don't want the folder to be proxied because, if it is, then
- # the modules will be proxied.
- # When we do support untrusted code, we're going to have to do
- # something different.
- folder = removeSecurityProxy(folder)
- compileModule(mod, folder, self.source)
- self._recompile = False
-
- def getModule(self):
- if self._recompile:
- self.execute()
- return self._module
-
-
- def _get_source(self):
- return self._source
- def _set_source(self, source):
- if self._source != source:
- self._source = source
- self._recompile = True
- source = property(_get_source, _set_source)
-
-
-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(name, data)
- m.__parent__ = self.context
- m.execute()
- return m
-
-
# Installer function that can be called from ZCML.
# This installs an import hook necessary to support persistent modules.
def installPersistentModuleImporter(event):
from zodbcode.module import PersistentModuleImporter
PersistentModuleImporter().install()
-
-
-def findModule(name, context=None):
- util = zapi.queryUtility(IModuleManager, name, context=context)
- if util is not None:
- return util.getModule()
- return sys.modules.get(name)
-
-
-def resolve(name, context=None):
- pos = name.rfind('.')
- mod = findModule(name[:pos], context)
- return getattr(mod, name[pos+1:])
-
Modified: Zope3/branches/srichter-blow-services/src/zope/app/module/browser/__init__.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/module/browser/__init__.py 2005-01-10 16:06:39 UTC (rev 28775)
+++ Zope3/branches/srichter-blow-services/src/zope/app/module/browser/__init__.py 2005-01-10 21:58:02 UTC (rev 28776)
@@ -51,7 +51,7 @@
class ViewModule(BrowserView):
- def getModuleName(self):
+ def getModuleObjects(self):
module = removeAllProxies(self.context.getModule())
remove_keys = ['__name__', '__builtins__', '_p_serial']
@@ -63,9 +63,12 @@
if id not in remove_keys]
L.sort()
- l_dict = [{"name": name, "doc": doc, "objtype": objtype} for name, doc, objtype in L]
+ l_dict = [{"name": name, "doc": doc, "objtype": objtype}
+ for name, doc, objtype in L]
for dic in l_dict:
- if dic['objtype'].find('Class') != -1: dic['objtype'] = 'Class'
- if dic['objtype'].find('Function') != -1: dic['objtype'] = 'Function'
+ if dic['objtype'].find('Class') != -1:
+ dic['objtype'] = 'Class'
+ if dic['objtype'].find('Function') != -1:
+ dic['objtype'] = 'Function'
return l_dict
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/module/browser/add_module.pt
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/module/browser/add_module.pt 2005-01-10 16:06:39 UTC (rev 28775)
+++ Zope3/branches/srichter-blow-services/src/zope/app/module/browser/add_module.pt 2005-01-10 21:58:02 UTC (rev 28776)
@@ -1,18 +0,0 @@
-<html metal:use-macro="context/@@standard_macros/page">
-<head>
- <title metal:fill-slot="title" i18n:translate="">Add a Module</title>
-</head>
-<body>
- <div metal:fill-slot="body">
-
- <p i18n:translate="">Enter the module source code.</p>
-
- <form action="action.html">
- <textarea name="source:text" cols="65" rows="25"></textarea>
- <input type="submit" value="Add module"
- i18n:attributes="value add-module-button"/>
- </form>
-
-</div>
-</body>
-</html>
Modified: Zope3/branches/srichter-blow-services/src/zope/app/module/browser/browse_module.pt
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/module/browser/browse_module.pt 2005-01-10 16:06:39 UTC (rev 28775)
+++ Zope3/branches/srichter-blow-services/src/zope/app/module/browser/browse_module.pt 2005-01-10 21:58:02 UTC (rev 28776)
@@ -3,25 +3,26 @@
<title metal:fill-slot="title" i18n:translate="">View Module Names</title>
</head>
<body>
- <div metal:fill-slot="body">
- <table class="listingdescription" summary="Module Listing"
- cellspacing="0" >
- <thead>
- <th>Name</th>
- <th>Type</th>
- <th>Description</th>
- </thead>
- <tal:repeat tal:repeat="dict view/getModuleName">
- <tr tal:define="oddrow repeat/dict/odd;"
- tal:attributes="class python:oddrow and 'even' or 'odd'">
- <td tal:content="dict/name">An name</td>
- <td tal:content="dict/objtype">Type</td>
- <td tal:content="dict/doc">DocString</td>
- </tr>
+<div metal:fill-slot="body">
+
+ <table class="listingdescription" summary="Module Listing"
+ cellspacing="0" >
+ <thead>
+ <th>Name</th>
+ <th>Type</th>
+ <th>Description</th>
+ </thead>
+ <tal:repeat tal:repeat="object view/getModuleObjects">
+ <tr tal:define="oddrow repeat/object/odd;"
+ tal:attributes="class python:oddrow and 'even' or 'odd'">
+ <td tal:content="object/name">An name</td>
+ <td tal:content="object/objtype">Type</td>
+ <td tal:content="object/doc">DocString</td>
+ </tr>
</tal:repeat>
-
- </table>
+ </table>
+
</div>
</body>
</html>
Modified: Zope3/branches/srichter-blow-services/src/zope/app/module/browser/configure.zcml
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/module/browser/configure.zcml 2005-01-10 16:06:39 UTC (rev 28775)
+++ Zope3/branches/srichter-blow-services/src/zope/app/module/browser/configure.zcml 2005-01-10 21:58:02 UTC (rev 28776)
@@ -3,38 +3,43 @@
xmlns="http://namespaces.zope.org/browser"
>
- <page
- name="edit.html"
- for="zope.app.module.interfaces.IModuleManager"
- menu="zmi_views" title="Edit"
- class=".EditModule"
- template="edit_module.pt"
- permission="zope.ManageServices"
+ <tool
+ interface="..interfaces.IModuleManager"
+ title="Persistent Python Modules"
+ description="Persistent Python Modules allow you to develop new Python
+ through-the-Web and store them in the ZODB."
/>
- <view for="zope.app.container.interfaces.IAdding"
- name="Module"
- class=".AddModule"
- permission="zope.ManageServices"
- >
- <page name="index.html" template="add_module.pt" />
- <page name="action.html" attribute="action" />
- </view>
+ <addform
+ name="AddModule.html"
+ schema="..interfaces.IModuleManager"
+ label="Add Permission"
+ content_factory="..manager.ModuleManager"
+ fields="source"
+ permission="zope.ManageSite"
+ />
+
+ <addMenuItem
+ title="Module"
+ description="A Persistent Python Module"
+ class="..manager.ModuleManager"
+ view="AddModule.html"
+ permission="zope.ManageSite"
+ />
+
+ <editform
+ name="edit.html"
+ schema="..interfaces.IModuleManager"
+ label="Edit Module"
+ permission="zope.ManageSite"
+ menu="zmi_views" title="Edit" />
<page
name="browse.html"
for="zope.app.module.interfaces.IModuleManager"
- menu="zmi_views" title="Browse"
- permission="zope.ManageServices"
class=".ViewModule"
template="browse_module.pt"
+ permission="zope.ManageSite"
+ menu="zmi_views" title="Browse"
/>
-
- <menuItem
- menu="add_component"
- for="zope.app.container.interfaces.IAdding"
- action="Module"
- title="Module"
- />
-
</zope:configure>
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/module/browser/edit_module.pt
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/module/browser/edit_module.pt 2005-01-10 16:06:39 UTC (rev 28775)
+++ Zope3/branches/srichter-blow-services/src/zope/app/module/browser/edit_module.pt 2005-01-10 21:58:02 UTC (rev 28776)
@@ -1,21 +0,0 @@
-<html metal:use-macro="context/@@standard_macros/view">
-<head>
- <title metal:fill-slot="title" i18n:translate="">Edit a Module</title>
-</head>
-<body>
-<div metal:fill-slot="body">
-
- <p i18n:translate="">Enter the module source code.</p>
-
- <form action="edit.html">
- <span tal:replace="view/update"></span>
- <textarea name="source:text" cols="65" rows="25"
- tal:content="context/source"></textarea>
- <br />
- <input type="submit" value="Save Changes"
- i18n:attributes="value edit-button"/>
- </form>
-
-</div>
-</body>
-</html>
Modified: Zope3/branches/srichter-blow-services/src/zope/app/module/configure.zcml
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/module/configure.zcml 2005-01-10 16:06:39 UTC (rev 28775)
+++ Zope3/branches/srichter-blow-services/src/zope/app/module/configure.zcml 2005-01-10 21:58:02 UTC (rev 28776)
@@ -1,13 +1,23 @@
<configure xmlns="http://namespaces.zope.org/zope">
- <content class=".Manager">
+ <localUtility class=".ModuleManager">
<require
permission="zope.ManageCode"
interface=".interfaces.IModuleManager"
set_schema=".interfaces.IModuleManager"
/>
- </content>
+ </localUtility>
+ <subscriber
+ for="..component.interfaces.registration.IRegistrationActivatedEvent"
+ factory=".manager.setNameOnActivation"
+ />
+
+ <subscriber
+ for="..component.interfaces.registration.IRegistrationDeactivatedEvent"
+ factory=".manager.unsetNameOnDeactivation"
+ />
+
<adapter
for="zope.app.site.interfaces.ISiteManagementFolder"
provides="zope.app.filerepresentation.interfaces.IFileFactory"
More information about the Zope3-Checkins
mailing list