[Checkins] SVN: grok/branches/grok-martian/ Martian is actually
used successfully by Grok - all the tests pass.
Martijn Faassen
faassen at infrae.com
Tue Jun 19 16:10:13 EDT 2007
Log message for revision 76813:
Martian is actually used successfully by Grok - all the tests pass.
Changed:
U grok/branches/grok-martian/buildout.cfg
U grok/branches/grok-martian/setup.py
U grok/branches/grok-martian/src/grok/__init__.py
U grok/branches/grok-martian/src/grok/_grok.py
U grok/branches/grok-martian/src/grok/grokker.py
U grok/branches/grok-martian/src/grok/meta.py
U grok/branches/grok-martian/src/grok/tests/grokker/continue_scanning.py
U grok/branches/grok-martian/src/grok/tests/grokker/onlyonce_fixture/_meta.py
U grok/branches/grok-martian/src/grok/tests/grokker/priority.py
-=-
Modified: grok/branches/grok-martian/buildout.cfg
===================================================================
--- grok/branches/grok-martian/buildout.cfg 2007-06-19 20:05:16 UTC (rev 76812)
+++ grok/branches/grok-martian/buildout.cfg 2007-06-19 20:10:13 UTC (rev 76813)
@@ -1,10 +1,11 @@
[buildout]
-develop = . grokwiki ldapaddressbook
-parts = zope3 data instance testdata testinstance test
+develop = . grokwiki ldapaddressbook martian
+parts = data instance testdata testinstance test
[zope3]
-recipe = zc.recipe.zope3checkout
-url = svn://svn.zope.org/repos/main/Zope3/branches/3.3
+#recipe = zc.recipe.zope3checkout
+#url = svn://svn.zope.org/repos/main/Zope3/branches/3.3
+location = /home/faassen/buildout/z331-lp
[data]
recipe = zc.recipe.filestorage
@@ -54,7 +55,7 @@
[test]
recipe = zc.recipe.testrunner
eggs = grok
-extra-paths = parts/zope3/src
+extra-paths = /home/faassen/buildout/z331-lp/lib/python
working-directory = parts/testinstance
defaults = ['--tests-pattern', '^f?tests$',
'-v'
Modified: grok/branches/grok-martian/setup.py
===================================================================
--- grok/branches/grok-martian/setup.py 2007-06-19 20:05:16 UTC (rev 76812)
+++ grok/branches/grok-martian/setup.py 2007-06-19 20:10:13 UTC (rev 76813)
@@ -16,5 +16,6 @@
include_package_data = True,
zip_safe=False,
install_requires=['setuptools',
+ 'martian',
'simplejson'],
)
Modified: grok/branches/grok-martian/src/grok/__init__.py
===================================================================
--- grok/branches/grok-martian/src/grok/__init__.py 2007-06-19 20:05:16 UTC (rev 76812)
+++ grok/branches/grok-martian/src/grok/__init__.py 2007-06-19 20:10:13 UTC (rev 76813)
@@ -29,7 +29,7 @@
IObjectRemovedEvent, ObjectRemovedEvent,
IContainerModifiedEvent, ContainerModifiedEvent)
-from grok.components import ClassGrokker, InstanceGrokker, ModuleGrokker
+from martian import ClassGrokker, InstanceGrokker, GlobalGrokker
from grok.components import Model, Adapter, MultiAdapter, View, XMLRPC, JSON
from grok.components import PageTemplate, PageTemplateFile, Container, Traverser
from grok.components import Site, GlobalUtility, LocalUtility, Annotation
Modified: grok/branches/grok-martian/src/grok/_grok.py
===================================================================
--- grok/branches/grok-martian/src/grok/_grok.py 2007-06-19 20:05:16 UTC (rev 76812)
+++ grok/branches/grok-martian/src/grok/_grok.py 2007-06-19 20:10:13 UTC (rev 76813)
@@ -25,10 +25,13 @@
import grok
-from grok import util, scan, components, grokker, meta
+from grok import util, components, meta
from grok.error import GrokError, GrokImportError
from grok.directive import frame_is_module
+from grok import templatereg
+import martian
+from martian import scan
_bootstrapped = False
def bootstrap():
@@ -48,8 +51,8 @@
addSiteHandler, adapts=(grok.Site, grok.IObjectAddedEvent))
# now grok the grokkers
- grokker.grokkerRegistry.grok(scan.module_info_from_module(meta))
-
+ martian.grok_module(scan.module_info_from_module(meta), the_module_grokker)
+
def addSiteHandler(site, event):
sitemanager = LocalSiteManager(site)
# LocalSiteManager creates the 'default' folder in its __init__.
@@ -63,7 +66,7 @@
def resetBootstrap():
global _bootstrapped
# we need to make sure that the grokker registry is clean again
- grokker.grokkerRegistry.clear()
+ the_module_grokker.clear()
_bootstrapped = False
from zope.testing.cleanup import addCleanUp
addCleanUp(resetBootstrap)
@@ -74,17 +77,37 @@
if not _bootstrapped:
bootstrap()
_bootstrapped = True
+ martian.grok_dotted_name(dotted_name, the_module_grokker)
- module_info = scan.module_info_from_dotted_name(dotted_name)
- grok_tree(module_info)
+def prepare_grok(name, module, kw):
+ module_info = scan.module_info_from_module(module)
+
+ # XXX hardcoded in here which base classes are possible contexts
+ # this should be made extensible
+ possible_contexts = martian.scan_for_classes(module, [grok.Model,
+ grok.LocalUtility,
+ grok.Container])
+ context = util.determine_module_context(module_info, possible_contexts)
+
+ kw['context'] = context
+ kw['module_info'] = module_info
+ kw['templates'] = templatereg.TemplateRegistry()
+def finalize_grok(name, module, kw):
+ module_info = kw['module_info']
+ templates = kw['templates']
+ unassociated = list(templates.listUnassociated())
+ if unassociated:
+ raise GrokError("Found the following unassociated template(s) when "
+ "grokking %r: %s. Define view classes inheriting "
+ "from grok.View to enable the template(s)."
+ % (module_info.dotted_name,
+ ', '.join(unassociated)), module_info)
-def grok_tree(module_info):
- grokker.grokkerRegistry.grok(module_info)
+the_module_grokker = martian.ModuleGrokker(martian.MetaMultiGrokker(),
+ prepare=prepare_grok,
+ finalize=finalize_grok)
- for sub_module_info in module_info.getSubModuleInfos():
- grok_tree(sub_module_info)
-
# decorators
class SubscribeDecorator:
Modified: grok/branches/grok-martian/src/grok/grokker.py
===================================================================
--- grok/branches/grok-martian/src/grok/grokker.py 2007-06-19 20:05:16 UTC (rev 76812)
+++ grok/branches/grok-martian/src/grok/grokker.py 2007-06-19 20:10:13 UTC (rev 76813)
@@ -104,19 +104,19 @@
# deep meta mode here - we define grokkers for grok.ClassGrokker,
# grok.InstanceGrokker, and grokker.ModuleGrokker.
-class MetaGrokker(grok.ClassGrokker):
- def register(self, context, name, factory, module_info, templates):
- grokkerRegistry.registerGrokker(factory())
+## class MetaGrokker(grok.ClassGrokker):
+## def register(self, context, name, factory, module_info, templates):
+## grokkerRegistry.registerGrokker(factory())
-class ClassGrokkerGrokker(MetaGrokker):
- component_class = grok.ClassGrokker
+## class ClassGrokkerGrokker(MetaGrokker):
+## component_class = grok.ClassGrokker
-class InstanceGrokkerGrokker(MetaGrokker):
- component_class = grok.InstanceGrokker
+## class InstanceGrokkerGrokker(MetaGrokker):
+## component_class = grok.InstanceGrokker
-class ModuleGrokkerGrokker(MetaGrokker):
- component_class = grok.ModuleGrokker
+## class ModuleGrokkerGrokker(MetaGrokker):
+## component_class = grok.ModuleGrokker
# the global grokker registry
-grokkerRegistry = GrokkerRegistry()
+#grokkerRegistry = GrokkerRegistry()
Modified: grok/branches/grok-martian/src/grok/meta.py
===================================================================
--- grok/branches/grok-martian/src/grok/meta.py 2007-06-19 20:05:16 UTC (rev 76812)
+++ grok/branches/grok-martian/src/grok/meta.py 2007-06-19 20:10:13 UTC (rev 76813)
@@ -26,15 +26,16 @@
from grok import util, components, formlib
from grok.error import GrokError
+import martian
-class ModelGrokker(grok.ClassGrokker):
+class ModelGrokker(martian.ClassGrokker):
component_class = grok.Model
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
for field in formlib.get_context_schema_fields(factory):
setattr(factory, field.__name__, field.default)
+ return True
-
class ContainerGrokker(ModelGrokker):
component_class = grok.Container
@@ -43,10 +44,10 @@
component_class = grok.LocalUtility
-class AdapterGrokker(grok.ClassGrokker):
+class AdapterGrokker(martian.ClassGrokker):
component_class = grok.Adapter
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
adapter_context = util.determine_class_context(factory, context)
provides = util.class_annotation(factory, 'grok.provides', None)
if provides is None:
@@ -55,35 +56,35 @@
component.provideAdapter(factory, adapts=(adapter_context,),
provides=provides,
name=name)
-
-
-class MultiAdapterGrokker(grok.ClassGrokker):
+ return True
+
+class MultiAdapterGrokker(martian.ClassGrokker):
component_class = grok.MultiAdapter
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
provides = util.class_annotation(factory, 'grok.provides', None)
if provides is None:
util.check_implements_one(factory)
util.check_adapts(factory)
name = util.class_annotation(factory, 'grok.name', '')
component.provideAdapter(factory, provides=provides, name=name)
+ return True
-
-class GlobalUtilityGrokker(grok.ClassGrokker):
+class GlobalUtilityGrokker(martian.ClassGrokker):
component_class = grok.GlobalUtility
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
provides = util.class_annotation(factory, 'grok.provides', None)
if provides is None:
util.check_implements_one(factory)
name = util.class_annotation(factory, 'grok.name', '')
component.provideUtility(factory(), provides=provides, name=name)
+ return True
-
-class XMLRPCGrokker(grok.ClassGrokker):
+class XMLRPCGrokker(martian.ClassGrokker):
component_class = grok.XMLRPC
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
view_context = util.determine_class_context(factory, context)
# XXX We should really not make __FOO__ methods available to
# the outside -- need to discuss how to restrict such things.
@@ -109,11 +110,12 @@
permission = getattr(method, '__grok_require__',
default_permission)
util.make_checker(factory, method_view, permission)
+ return True
-class ViewGrokker(grok.ClassGrokker):
+class ViewGrokker(martian.ClassGrokker):
component_class = grok.View
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
view_context = util.determine_class_context(factory, context)
factory.module_info = module_info
@@ -185,12 +187,13 @@
'method %r in view %r. It may only be used '
'for XML-RPC methods.'
% (method.__name__, factory), factory)
+ return True
+
-
-class JSONGrokker(grok.ClassGrokker):
+class JSONGrokker(martian.ClassGrokker):
component_class = grok.JSON
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
view_context = util.determine_class_context(factory, context)
methods = util.methods_from_class(factory)
@@ -215,57 +218,62 @@
permission = getattr(method, '__grok_require__',
default_permission)
util.make_checker(factory, method_view, permission)
-
-class TraverserGrokker(grok.ClassGrokker):
+ return True
+
+class TraverserGrokker(martian.ClassGrokker):
component_class = grok.Traverser
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
factory_context = util.determine_class_context(factory, context)
component.provideAdapter(factory,
adapts=(factory_context, IBrowserRequest),
provides=IBrowserPublisher)
-
-
-class ModulePageTemplateGrokker(grok.InstanceGrokker):
+ return True
+
+class ModulePageTemplateGrokker(martian.InstanceGrokker):
# this needs to happen before any other grokkers execute that actually
# use the templates
priority = 1000
- component_class = (grok.PageTemplate, grok.PageTemplateFile)
-
- def register(self, context, name, instance, module_info, templates):
+ component_class = grok.PageTemplate
+
+ def grok(self, name, instance, context, module_info, templates):
templates.register(name, instance)
instance._annotateGrokInfo(name, module_info.dotted_name)
+ return True
+class ModulePageTemplateFileGrokker(ModulePageTemplateGrokker):
+ priority = 1000
+ component_class = grok.PageTemplateFile
-class FilesystemPageTemplateGrokker(grok.ModuleGrokker):
+class FilesystemPageTemplateGrokker(martian.GlobalGrokker):
# do this early on, but after ModulePageTemplateGrokker, as
# findFilesystem depends on module-level templates to be
# already grokked for error reporting
priority = 999
- def register(self, context, module_info, templates):
+ def grok(self, name, module, context, module_info, templates):
templates.findFilesystem(module_info)
+ return True
+class SubscriberGrokker(martian.GlobalGrokker):
-class SubscriberGrokker(grok.ModuleGrokker):
-
- def register(self, context, module_info, templates):
+ def grok(self, name, module, context, module_info, templates):
subscribers = module_info.getAnnotation('grok.subscribers', [])
for factory, subscribed in subscribers:
component.provideHandler(factory, adapts=subscribed)
for iface in subscribed:
zope.component.interface.provideInterface('', iface)
+ return True
+class StaticResourcesGrokker(martian.GlobalGrokker):
-class StaticResourcesGrokker(grok.ModuleGrokker):
-
- def register(self, context, module_info, templates):
+ def grok(self, name, module, context, module_info, templates):
# we're only interested in static resources if this module
# happens to be a package
if not module_info.isPackage():
- return
+ return False
resource_path = module_info.getResourcePath('static')
if os.path.isdir(resource_path):
@@ -287,11 +295,11 @@
component.provideAdapter(
resource_factory, (IDefaultBrowserLayer,),
interface.Interface, name=module_info.dotted_name)
+ return True
+class GlobalUtilityDirectiveGrokker(martian.GlobalGrokker):
-class GlobalUtilityDirectiveGrokker(grok.ModuleGrokker):
-
- def register(self, context, module_info, templates):
+ def grok(self, name, module, context, module_info, templates):
infos = module_info.getAnnotation('grok.global_utility', [])
for info in infos:
@@ -304,17 +312,16 @@
component.provideUtility(obj,
provides=info.provides,
name=info.name)
+ return True
-
-class SiteGrokker(grok.ClassGrokker):
+class SiteGrokker(martian.ClassGrokker):
component_class = grok.Site
priority = 500
- continue_scanning = True
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
infos = util.class_annotation_list(factory, 'grok.local_utility', None)
if infos is None:
- return
+ return False
for info in infos:
if info.public and not IContainer.implementedBy(factory):
@@ -378,6 +385,7 @@
component.provideHandler(localUtilityRegistrationSubscriber,
adapts=(factory, grok.IObjectAddedEvent))
+ return True
def localUtilityRegistrationSubscriber(site, event):
"""A subscriber that fires to set up local utilities.
@@ -396,7 +404,6 @@
# do not register utilities anymore
site.__grok_utilities_installed__ = True
-
def setupUtility(site, utility, provides, name=u'',
name_in_container=None, public=False, setup=None):
"""Set up a utility in a site.
@@ -433,11 +440,11 @@
site_manager.registerUtility(utility, provided=provides,
name=name)
-class DefinePermissionGrokker(grok.ModuleGrokker):
+class DefinePermissionGrokker(martian.GlobalGrokker):
priority = 1500
- def register(self, context, module_info, templates):
+ def grok(self, name, module, context, module_info, templates):
permissions = module_info.getAnnotation('grok.define_permission', [])
for permission in permissions:
# IPermission.title says that permission ids (and titles,
@@ -449,11 +456,12 @@
component.provideUtility(Permission(permission, title=permission),
name=permission)
-
-class AnnotationGrokker(grok.ClassGrokker):
+ return True
+
+class AnnotationGrokker(martian.ClassGrokker):
component_class = grok.Annotation
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
adapter_context = util.determine_class_context(factory, context)
provides = util.class_annotation(factory, 'grok.provides', None)
if provides is None:
@@ -485,23 +493,24 @@
return contained_result
component.provideAdapter(getAnnotation)
+ return True
-
-class ApplicationGrokker(grok.ClassGrokker):
+class ApplicationGrokker(martian.ClassGrokker):
component_class = grok.Application
priority = 500
- continue_scanning = True
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
# XXX fail loudly if the same application name is used twice.
zope.component.provideUtility(factory,
provides=grok.interfaces.IApplication,
name='%s.%s' % (module_info.dotted_name,
name))
-class IndexesGrokker(grok.InstanceGrokker):
+ return True
+
+class IndexesGrokker(martian.InstanceGrokker):
component_class = components.IndexesClass
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
site = util.class_annotation(factory, 'grok.site', None)
if site is None:
raise GrokError("No site specified for grok.Indexes "
@@ -510,7 +519,7 @@
factory)
indexes = util.class_annotation(factory, 'grok.indexes', None)
if indexes is None:
- return
+ return False
context = util.determine_class_context(factory, context)
catalog_name = util.class_annotation(factory, 'grok.name', u'')
zope.component.provideHandler(
@@ -518,7 +527,8 @@
context, module_info),
adapts=(site,
grok.IObjectAddedEvent))
-
+ return True
+
class IndexesSetupSubscriber(object):
def __init__(self, catalog_name, indexes, context, module_info):
self.catalog_name = catalog_name
Modified: grok/branches/grok-martian/src/grok/tests/grokker/continue_scanning.py
===================================================================
--- grok/branches/grok-martian/src/grok/tests/grokker/continue_scanning.py 2007-06-19 20:05:16 UTC (rev 76812)
+++ grok/branches/grok-martian/src/grok/tests/grokker/continue_scanning.py 2007-06-19 20:10:13 UTC (rev 76813)
@@ -26,15 +26,16 @@
class AlphaGrokker(grok.ClassGrokker):
component_class = Alpha
- continue_scanning = True
priority = 1 # we need to go before BetaGrokker
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
print "alpha"
+ return True
-
class BetaGrokker(grok.ClassGrokker):
component_class = Beta
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
print "beta"
+ return True
+
Modified: grok/branches/grok-martian/src/grok/tests/grokker/onlyonce_fixture/_meta.py
===================================================================
--- grok/branches/grok-martian/src/grok/tests/grokker/onlyonce_fixture/_meta.py 2007-06-19 20:05:16 UTC (rev 76812)
+++ grok/branches/grok-martian/src/grok/tests/grokker/onlyonce_fixture/_meta.py 2007-06-19 20:10:13 UTC (rev 76813)
@@ -1,8 +1,9 @@
-import grok
+import martian
from component import Alpha
-class AlphaGrokker(grok.ClassGrokker):
+class AlphaGrokker(martian.ClassGrokker):
component_class = Alpha
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
print "alpha"
+ return True
Modified: grok/branches/grok-martian/src/grok/tests/grokker/priority.py
===================================================================
--- grok/branches/grok-martian/src/grok/tests/grokker/priority.py 2007-06-19 20:05:16 UTC (rev 76812)
+++ grok/branches/grok-martian/src/grok/tests/grokker/priority.py 2007-06-19 20:10:13 UTC (rev 76813)
@@ -33,20 +33,22 @@
class AlphaGrokker(grok.ClassGrokker):
component_class = Alpha
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
print "alpha"
+ return True
-
class BetaGrokker(grok.ClassGrokker):
component_class = Beta
priority = 1
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
print "beta"
-
+ return True
+
class GammaGrokker(grok.ClassGrokker):
component_class = Gamma
priority = -1
- def register(self, context, name, factory, module_info, templates):
+ def grok(self, name, factory, context, module_info, templates):
print "gamma"
+ return True
More information about the Checkins
mailing list