[Checkins] SVN: grok/branches/brandon-grokcore.component/src/grok/ Somehow made Grok depend on "grokcore.component" instead of doing all

Brandon Rhodes brandon at rhodesmill.org
Wed Mar 19 16:27:15 EDT 2008


Log message for revision 84792:
  Somehow made Grok depend on "grokcore.component" instead of doing all
  of the component stuff itself.  Also, removed some redundant tests
  that now live in grokcore (but only the ones that are now actually
  broken if they continued living in Grok).  After two hours of all the
  tests being broken, it's amazing to arrive back at the point where
  they all work.  Here's hoping I didn't accidentally turn them all into
  no-op's or something.
  

Changed:
  U   grok/branches/brandon-grokcore.component/src/grok/__init__.py
  U   grok/branches/brandon-grokcore.component/src/grok/components.py
  U   grok/branches/brandon-grokcore.component/src/grok/configure.zcml
  U   grok/branches/brandon-grokcore.component/src/grok/decorators.py
  U   grok/branches/brandon-grokcore.component/src/grok/directive.py
  U   grok/branches/brandon-grokcore.component/src/grok/meta.py
  U   grok/branches/brandon-grokcore.component/src/grok/meta.zcml
  U   grok/branches/brandon-grokcore.component/src/grok/testing.py
  D   grok/branches/brandon-grokcore.component/src/grok/tests/directive/multipletimes.py
  D   grok/branches/brandon-grokcore.component/src/grok/tests/order/arg_orderdirective.py
  D   grok/branches/brandon-grokcore.component/src/grok/tests/order/combined_orderdirective.py
  D   grok/branches/brandon-grokcore.component/src/grok/tests/order/combinednoorder_orderdirective.py
  D   grok/branches/brandon-grokcore.component/src/grok/tests/order/inter1.py
  D   grok/branches/brandon-grokcore.component/src/grok/tests/order/noarg_orderdirective.py
  D   grok/branches/brandon-grokcore.component/src/grok/tests/order/nodirective.py
  D   grok/branches/brandon-grokcore.component/src/grok/tests/util/public_methods_from_class.py
  U   grok/branches/brandon-grokcore.component/src/grok/util.py
  D   grok/branches/brandon-grokcore.component/src/grok/zcml.py

-=-
Modified: grok/branches/brandon-grokcore.component/src/grok/__init__.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/__init__.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/__init__.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -43,11 +43,13 @@
 from grok.interfaces import IRESTSkinType
 from grok.components import ViewletManager, Viewlet
 
-from grok.directive import (context, name, title, template, templatedir,
-                            provides, baseclass, global_utility, local_utility,
-                            permissions, require, site, layer, direct, viewletmanager,
-                            view, order)
-from grok.decorators import subscribe, adapter, implementer
+from grokcore.component.directive import (
+    context, name, title, provides, baseclass, global_utility, direct, order)
+from grok.directive import (
+    template, templatedir, local_utility, permissions, require, site,
+    layer, viewletmanager, view)
+from grokcore.component.decorators import adapter, implementer
+from grok.decorators import subscribe
 from martian.error import GrokError, GrokImportError
 
 # BBB These two functions are meant for test fixtures and should be

Modified: grok/branches/brandon-grokcore.component/src/grok/components.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/components.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/components.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -52,17 +52,19 @@
 import z3c.flashmessage.interfaces
 
 import martian.util
+from grokcore.component import Context
+from grokcore.component import util as gcutil
 from grok import interfaces, formlib, util
 
 
-class Model(Contained, persistent.Persistent):
+class Model(Context, Contained, persistent.Persistent):
     # XXX Inheritance order is important here. If we reverse this,
     # then containers can't be models anymore because no unambigous MRO
     # can be established.
     interface.implements(IAttributeAnnotatable)
 
 
-class Container(BTreeContainer):
+class Container(Context, BTreeContainer):
     interface.implements(IAttributeAnnotatable)
 
 
@@ -617,7 +619,7 @@
         if self.template:
             return self.template.render(self) 
         else:
-            viewlets = util.sort_components(self.viewlets)
+            viewlets = gcutil.sort_components(self.viewlets)
             return u'\n'.join([viewlet.render() for viewlet in viewlets])
 
     def namespace(self):

Modified: grok/branches/brandon-grokcore.component/src/grok/configure.zcml
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/configure.zcml	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/configure.zcml	2008-03-19 20:27:14 UTC (rev 84792)
@@ -7,6 +7,7 @@
   <include package="zope.i18n" file="meta.zcml" />
   <include package="zope.securitypolicy" file="meta.zcml" />
   <include package="zope.app.zcmlfiles" file="meta.zcml" />
+  <include package="grokcore.component" file="meta.zcml" />
   <include package="grok" file="meta.zcml" />
 
   <include package="zope.annotation" />

Modified: grok/branches/brandon-grokcore.component/src/grok/decorators.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/decorators.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/decorators.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -14,9 +14,6 @@
 """Grok
 """
 import sys
-import types
-from zope.component._declaration import adapter as _adapter
-from zope.interface.declarations import implementer as _implementer
 from martian.util import frame_is_module
 from martian.error import GrokImportError
 
@@ -40,28 +37,3 @@
             frame.f_locals['__grok_subscribers__'] = subscribers = []
         subscribers.append((function, self.subscribed))
         return function
-
-class adapter(_adapter):
-
-    def __init__(self, *interfaces):
-        # Override the z.c.adapter decorator to force sanity checking
-        # and have better error reporting.
-        if not interfaces:
-            raise GrokImportError(
-                "@grok.adapter requires at least one argument.")
-        if type(interfaces[0]) is types.FunctionType:
-            raise GrokImportError(
-                "@grok.adapter requires at least one argument.")
-        self.interfaces = interfaces
-
-class implementer(_implementer):
-
-    def __call__(self, ob):
-        # XXX we do not have function grokkers (yet) so we put the annotation
-        # on the module.
-        frame = sys._getframe(1)
-        implementers = frame.f_locals.get('__implementers__', None)
-        if implementers is None:
-            frame.f_locals['__implementers__'] = implementers = []
-        implementers.append(ob)
-        return _implementer.__call__(self, ob)

Modified: grok/branches/brandon-grokcore.component/src/grok/directive.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/directive.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/directive.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -29,34 +29,8 @@
                                ClassDirectiveContext,
                                ClassOrModuleDirectiveContext)
 from martian import util
+from grokcore.component.directive import MultiValueOnceDirective
 
-class GlobalUtilityDirective(MultipleTimesDirective):
-    def check_arguments(self, factory, provides=None, name=u'',
-                        direct=False):
-        if provides is not None and not IInterface.providedBy(provides):
-            raise GrokImportError("You can only pass an interface to the "
-                                  "provides argument of %s." % self.name)
-
-    def value_factory(self, *args, **kw):
-        return GlobalUtilityInfo(*args, **kw)
-
-
-class GlobalUtilityInfo(object):
-    def __init__(self, factory, provides=None, name=u'', direct=None):
-        self.factory = factory
-        if direct is None:
-            direct = util.class_annotation(factory, 'grok.direct', False)
-        self.direct = direct
-
-        if provides is None:
-            provides = util.class_annotation(factory, 'grok.provides', None)
-        self.provides = provides
-
-        if name is u'':
-            name = util.class_annotation(factory, 'grok.name', u'')
-        self.name = name
-
-
 class LocalUtilityDirective(MultipleTimesDirective):
     def check_arguments(self, factory, provides=None, name=u'',
                         setup=None, public=False, name_in_container=None):
@@ -97,49 +71,18 @@
             return func
         return decorator
 
-class MultiValueOnceDirective(OnceDirective):
-
-    def check_arguments(self, *values):
-        pass
-
-    def value_factory(self, *args):
-        return args
-
-class OrderDirective(OptionalValueDirective, OnceDirective):
-
-    order = 0
-
-    def value_factory(self, value=None):
-        OrderDirective.order += 1
-        if value is not None:
-            return value, OrderDirective.order
-        return super(OrderDirective, self).value_factory(value)
-
-    def default_value(self):
-        return 0, OrderDirective.order
-
 # Define grok directives
-name = SingleTextDirective('grok.name', ClassDirectiveContext())
 template = SingleTextDirective('grok.template', ClassDirectiveContext())
-context = InterfaceOrClassDirective('grok.context',
-                                    ClassOrModuleDirectiveContext())
 templatedir = SingleTextDirective('grok.templatedir', ModuleDirectiveContext())
-provides = InterfaceDirective('grok.provides', ClassDirectiveContext())
-baseclass = MarkerDirective('grok.baseclass', ClassDirectiveContext())
-global_utility = GlobalUtilityDirective('grok.global_utility',
-                                        ModuleDirectiveContext())
 local_utility = LocalUtilityDirective('grok.local_utility',
                                       ClassDirectiveContext())
 require = RequireDirective('grok.require', ClassDirectiveContext())
 site = InterfaceOrClassDirective('grok.site',
                                  ClassDirectiveContext())
-title = SingleTextDirective('grok.title', ClassDirectiveContext())
 permissions = MultiValueOnceDirective(
     'grok.permissions', ClassDirectiveContext())
 layer = InterfaceOrClassDirective('grok.layer',
                            ClassOrModuleDirectiveContext())
-order = OrderDirective('grok.order', ClassDirectiveContext())
-direct = MarkerDirective('grok.direct', ClassDirectiveContext())
 viewletmanager = InterfaceOrClassDirective('grok.viewletmanager',
                                            ClassOrModuleDirectiveContext())
 view = InterfaceOrClassDirective('grok.view',

Modified: grok/branches/brandon-grokcore.component/src/grok/meta.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/meta.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/meta.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -48,44 +48,19 @@
 
 import grok
 from grok import components, formlib, templatereg
-from grok.util import check_adapts, get_default_permission, make_checker
-from grok.util import check_module_component, determine_module_component
-from grok.util import determine_class_component
-from grok.util import determine_class_directive, public_methods_from_class
+from grokcore.component.meta import get_context, get_name, get_name_classname
+from grokcore.component.util import (
+    determine_class_directive, public_methods_from_class,
+    determine_module_component, determine_class_component,
+    )
+from grok.util import get_default_permission, make_checker
 from grok.rest import RestPublisher
 from grok.interfaces import IRESTSkinType
 
-def get_context(module_info, factory):
-    return determine_class_component(module_info, factory,
-                                     'context', 'grok.context')
-
 def get_viewletmanager(module_info, factory):
     return determine_class_component(module_info, factory,
                                      'viewletmanager', 'grok.viewletmanager')
 
-def get_name_classname(factory):
-    return get_name(factory, factory.__name__.lower())
-
-def get_name(factory, default=''):
-    return grok.util.class_annotation(factory, 'grok.name', default)
-
-def get_provides(factory):
-    provides = util.class_annotation(factory, 'grok.provides', None)
-    if provides is None:
-        util.check_implements_one(factory)
-    return provides
-
-class ContextGrokker(martian.GlobalGrokker):
-
-    priority = 1001
-
-    def grok(self, name, module, module_info, config, **kw):
-        context = determine_module_component(module_info, 'grok.context',
-                                             [grok.Model, grok.Container])
-        module.__grok_context__ = context
-        return True
-
-
 class ViewletManagerContextGrokker(martian.GlobalGrokker):
 
     priority = 1001
@@ -97,62 +72,6 @@
         module.__grok_viewletmanager__ = viewletmanager
         return True
     
-class AdapterGrokker(martian.ClassGrokker):
-    component_class = grok.Adapter
-
-    def grok(self, name, factory, module_info, config, **kw):
-        adapter_context = get_context(module_info, factory)
-        provides = get_provides(factory)
-        name = get_name(factory)
-        
-        config.action(
-            discriminator=('adapter', adapter_context, provides, name),
-            callable=component.provideAdapter,
-            args=(factory, (adapter_context,), provides, name),
-            )
-        return True
-
-class MultiAdapterGrokker(martian.ClassGrokker):
-    component_class = grok.MultiAdapter
-
-    def grok(self, name, factory, module_info, config, **kw):
-        provides = get_provides(factory)
-        name = get_name(factory)
-        
-        check_adapts(factory)
-        for_ = component.adaptedBy(factory)
-
-        config.action(
-            discriminator=('adapter', for_, provides, name),
-            callable=component.provideAdapter,
-            args=(factory, None, provides, name),
-            )
-        return True
-
-
-class GlobalUtilityGrokker(martian.ClassGrokker):
-    component_class = grok.GlobalUtility
-
-    # This needs to happen before the FilesystemPageTemplateGrokker grokker
-    # happens, since it relies on the ITemplateFileFactories being grokked.
-    priority = 1100
-
-    def grok(self, name, factory, module_info, config, **kw):
-        provides = get_provides(factory)
-        name = get_name(factory)
-
-        direct = util.class_annotation(factory, 'grok.direct', False)
-        if not direct:
-            factory = factory()
-
-        config.action(
-            discriminator=('utility', provides, name),
-            callable=component.provideUtility,
-            args=(factory, provides, name),
-            )
-        return True
-
-
 class XMLRPCGrokker(martian.ClassGrokker):
     component_class = grok.XMLRPC
 
@@ -464,28 +383,6 @@
         return True
 
 
-class AdapterDecoratorGrokker(martian.GlobalGrokker):
-
-    def grok(self, name, module, module_info, config, **kw):
-        context = module_info.getAnnotation('grok.context', None)
-        implementers = module_info.getAnnotation('implementers', [])
-        for function in implementers:
-            interfaces = getattr(function, '__component_adapts__', None)
-            if interfaces is None:
-                # There's no explicit interfaces defined, so we assume the
-                # module context to be the thing adapted.
-                check_module_component(module_info.getModule(), context,
-                                       'context', 'grok.context')
-                interfaces = (context, )
-
-            config.action(
-                discriminator=('adapter', interfaces, function.__implemented__),
-                callable=component.provideAdapter,
-                args=(function, interfaces, function.__implemented__),
-                )
-        return True
-
-
 class StaticResourcesGrokker(martian.GlobalGrokker):
 
     def grok(self, name, module, module_info, config, **kw):
@@ -522,24 +419,6 @@
         return True
 
 
-class GlobalUtilityDirectiveGrokker(martian.GlobalGrokker):
-
-    def grok(self, name, module, module_info, config, **kw):
-        infos = module_info.getAnnotation('grok.global_utility', [])
-
-        for info in infos:
-            if info.provides is None:
-                util.check_implements_one(info.factory)
-            if info.direct:
-                obj = info.factory
-            else:
-                obj = info.factory()
-            component.provideUtility(obj,
-                                     provides=info.provides,
-                                     name=info.name)
-        return True
-
-
 class SiteGrokker(martian.ClassGrokker):
     component_class = grok.Site
     priority = 500

Modified: grok/branches/brandon-grokcore.component/src/grok/meta.zcml
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/meta.zcml	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/meta.zcml	2008-03-19 20:27:14 UTC (rev 84792)
@@ -3,17 +3,8 @@
     xmlns:meta="http://namespaces.zope.org/meta"
     xmlns:grok="http://namespaces.zope.org/grok">
 
-  <include package="z3c.autoinclude" file="meta.zcml" />
-
-  <meta:directives namespace="http://namespaces.zope.org/grok">
-    <meta:directive
-        name="grok"
-        schema=".zcml.IGrokDirective"
-        handler=".zcml.grokDirective"
-        />
-  </meta:directives>
-
   <!-- Load the grokkers -->
+  <include package="grokcore.component" file="meta.zcml" />
   <grok:grok package=".meta" />
 
 </configure>

Modified: grok/branches/brandon-grokcore.component/src/grok/testing.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/testing.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/testing.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -15,7 +15,7 @@
 """
 from zope.configuration.config import ConfigurationMachine
 from martian import scan
-from grok import zcml
+from grokcore.component import zcml
 
 import unittest
 from os import listdir
@@ -222,6 +222,7 @@
 
 def grok(module_name):
     config = ConfigurationMachine()
+    zcml.do_grok('grokcore.component.meta', config)
     zcml.do_grok('grok.meta', config)
     zcml.do_grok('grok.templatereg', config)
     zcml.do_grok(module_name, config)

Deleted: grok/branches/brandon-grokcore.component/src/grok/tests/directive/multipletimes.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/tests/directive/multipletimes.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/tests/directive/multipletimes.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -1,42 +0,0 @@
-"""
-Since grok.global_utility is a MultipleTimesDirective, there is a list of
-GlobalUtilityInfo objects annotated on the module.
-
-  >>> from martian import scan
-  >>> from grok.tests.directive import multipletimes
-  >>> module_info = scan.module_info_from_module(multipletimes)
-  >>> guis = module_info.getAnnotation('grok.global_utility', None)
-  >>> guis
-  [<grok.directive.GlobalUtilityInfo object at 0x...>,
-  <grok.directive.GlobalUtilityInfo object at 0x...>]
-  >>> guis[0].factory
-  <class 'grok.tests.directive.multipletimes.Club'>
-  >>> guis[0].provides
-  <InterfaceClass grok.tests.directive.multipletimes.IClub>
-  >>> guis[0].name
-  'foo'
-  >>> guis[1].factory
-  <class 'grok.tests.directive.multipletimes.Cave'>
-  >>> guis[1].provides is None
-  True
-  >>> guis[1].name
-  u''
-  
-"""
-import grok
-from zope import interface
-
-class IClub(interface.Interface):
-    pass
-
-class ICave(interface.Interface):
-    pass
-
-class Club(object):
-    grok.implements(IClub)
-
-class Cave(object):
-    grok.implements(ICave)
-
-grok.global_utility(Club, provides=IClub, name='foo')
-grok.global_utility(Cave)

Deleted: grok/branches/brandon-grokcore.component/src/grok/tests/order/arg_orderdirective.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/tests/order/arg_orderdirective.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/tests/order/arg_orderdirective.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -1,33 +0,0 @@
-"""
-
-If the grok.order directive is present with arguments, sorting will be
-done by the order specified.
-
-  >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
-
-  >>> from grok.util import sort_components
-  >>> sort_components(components)
-  [<...Fifth object at ...>,
-   <...Fourth object at ...>,
-   <...Third object at ...>,
-   <...Second object at ...>,
-   <...First object at ...>]
-
-"""
-
-import grok
-
-class First(object):
-    grok.order(5)
-
-class Second(object):
-    grok.order(4)
-
-class Third(object):
-    grok.order(3)
-
-class Fourth(object):
-    grok.order(2)
-
-class Fifth(object):
-    grok.order(1)

Deleted: grok/branches/brandon-grokcore.component/src/grok/tests/order/combined_orderdirective.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/tests/order/combined_orderdirective.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/tests/order/combined_orderdirective.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -1,34 +0,0 @@
-"""
-
-If the grok.order directive is specified with other classes that don't
-have the order specified, then the order will be determined by first
-sorting on the order specified, and then by the definition order.
-
-  >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
-
-  >>> from grok.util import sort_components
-  >>> sort_components(components)
-  [<...Third object at ...>,
-   <...Fourth object at ...>,
-   <...Second object at ...>,
-   <...Fifth object at ...>,
-   <...First object at ...>]
-
-"""
-
-import grok
-
-class First(object):
-    grok.order(2)
-
-class Second(object):
-    grok.order(1)
-
-class Third(object):
-    grok.order()
-
-class Fourth(object):
-    grok.order()
-
-class Fifth(object):
-    grok.order(1)

Deleted: grok/branches/brandon-grokcore.component/src/grok/tests/order/combinednoorder_orderdirective.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/tests/order/combinednoorder_orderdirective.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/tests/order/combinednoorder_orderdirective.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -1,34 +0,0 @@
-"""
-
-If the grok.order directive is specified with other classes that don't
-have the order specified, then the order will be determined by first
-sorting on the order specified, and then by the definition order.
-
-  >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
-
-  >>> from grok.util import sort_components
-  >>> sort_components(components)
-  [<...Fifth object at ...>,
-   <...Third object at ...>,
-   <...First object at ...>,
-   <...Fourth object at ...>,
-   <...Second object at ...>]
-
-"""
-
-import grok
-
-class First(object):
-    grok.order()
-
-class Second(object):
-    grok.order(1)
-
-class Third(object):
-    pass
-
-class Fourth(object):
-    grok.order()
-
-class Fifth(object):
-    pass

Deleted: grok/branches/brandon-grokcore.component/src/grok/tests/order/inter1.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/tests/order/inter1.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/tests/order/inter1.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -1,35 +0,0 @@
-"""
-
-The ordering works like so:
-1. Objects with explicit ordering
-   (if combined with objects with no ordering not specified, then the orderless
-    objects come first)
-2. Objects with same ordering get grouped by module import order
-3. Internal order within module
-4. If no ordering is specified by any objects, then objects are sorted
-   alphabetically by class name
-
-  >>> from inter2 import Four, Five, Six
-  >>> components = [One(), Two(), Three(), Four(), Five(), Six()]
-
-  >>> from grok.util import sort_components
-  >>> sort_components(components)
-  [<...Three object at ...>,
-   <...One object at ...>,
-   <...Five object at ...>,
-   <...Six object at ...>,
-   <...Four object at ...>,
-   <...Two object at ...>]
-
-"""
-
-import grok
-
-class One(object):
-    grok.order()
-
-class Two(object):
-    grok.order(2)
-
-class Three(object):
-    pass

Deleted: grok/branches/brandon-grokcore.component/src/grok/tests/order/noarg_orderdirective.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/tests/order/noarg_orderdirective.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/tests/order/noarg_orderdirective.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -1,33 +0,0 @@
-"""
-
-If the grok.order directive is present with no arguments, sorting will
-be done by definition order.
-
-  >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
-
-  >>> from grok.util import sort_components
-  >>> sort_components(components)
-  [<...First object at ...>,
-   <...Second object at ...>,
-   <...Third object at ...>,
-   <...Fourth object at ...>,
-   <...Fifth object at ...>]
-
-"""
-
-import grok
-
-class First(object):
-    grok.order()
-
-class Second(object):
-    grok.order()
-
-class Third(object):
-    grok.order()
-
-class Fourth(object):
-    grok.order()
-
-class Fifth(object):
-    grok.order()

Deleted: grok/branches/brandon-grokcore.component/src/grok/tests/order/nodirective.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/tests/order/nodirective.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/tests/order/nodirective.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -1,31 +0,0 @@
-"""
-
-If the grok.order directive is absent, sorting will be done by class
-name.
-
-  >>> components = [First(), Second(), Third(), Fourth(), Fifth()]
-
-  >>> from grok.util import sort_components
-  >>> sort_components(components)
-  [<...Fifth object at ...>,
-   <...First object at ...>,
-   <...Fourth object at ...>,
-   <...Second object at ...>,
-   <...Third object at ...>]
-
-"""
-
-class First(object):
-    pass
-
-class Second(object):
-    pass
-
-class Third(object):
-    pass
-
-class Fourth(object):
-    pass
-
-class Fifth(object):
-    pass

Deleted: grok/branches/brandon-grokcore.component/src/grok/tests/util/public_methods_from_class.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/tests/util/public_methods_from_class.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/tests/util/public_methods_from_class.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -1,28 +0,0 @@
-"""
-  >>> methods = grok.util.public_methods_from_class(A)
-  >>> sorted([m.__name__ for m in methods])
-  ['should_also_be_public', 'should_be_public']
-
-"""
-import grok
-import grok.util
-
-class A(object):
-
-    def __init__(self):
-        pass # this method is ignored
-
-    def __call__(self):
-        pass # this method is ignored
-
-    def __double_underscored(self):
-        pass # this method is ignored
-
-    def _single_underscored(self):
-        pass # this method is ignored
-
-    def should_be_public(self):
-        pass # this method is found
-
-    def should_also_be_public(self):
-        pass # this method is found

Modified: grok/branches/brandon-grokcore.component/src/grok/util.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/util.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/util.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -24,15 +24,9 @@
 from zope.security.checker import NamesChecker, defineChecker
 from zope.security.interfaces import IPermission
 
-from martian.error import GrokError, GrokImportError
-from martian.util import class_annotation, methods_from_class, scan_for_classes
+from martian.error import GrokError
+from martian.util import class_annotation
 
-def check_adapts(class_):
-    if component.adaptedBy(class_) is None:
-        raise GrokError("%r must specify which contexts it adapts "
-                        "(use grok.adapts to specify)."
-                        % class_, class_)
-
 def make_checker(factory, view_factory, permission, method_names=None):
     """Make a checker for a view_factory associated with factory.
 
@@ -98,93 +92,3 @@
         return obj
     # This either sets __parent__ or wraps 'obj' in a LocationProxy
     return zope.location.location.located(obj, parent, name)
-
-def determine_class_directive(directive_name, factory, module_info,
-                              default=None):
-    directive = class_annotation(factory, directive_name, None)
-    if directive is None:
-        directive = module_info.getAnnotation(directive_name, None)
-    if directive is not None:
-        return directive
-    return default
-
-def public_methods_from_class(factory):
-    return [m for m in methods_from_class(factory) if \
-            not m.__name__.startswith('_')]
-
-def _sort_key(component):
-    explicit_order, implicit_order = class_annotation(component,
-                                                      'grok.order',
-                                                      (0,0))
-    return (explicit_order,
-            component.__module__,
-            implicit_order,
-            component.__class__.__name__)
-
-def sort_components(components):
-    # if components have a grok.order directive, sort by that
-    return sorted(components, key=_sort_key)
-
-AMBIGUOUS_COMPONENT = object()
-def check_module_component(factory, component,
-                           component_name, component_directive):
-    """Raise error if module-level component cannot be determined.
-
-    If the module-level component is None, it's never been specified;
-    raise error telling developer to specify.
-
-    if the module-level component is AMBIGUOUS_COMPONENT, raise
-    an error telling developer to specify which one to use.
-    """
-    if component is None:
-        raise GrokError("No module-level %s for %r, please use "
-                        "%s." % (component_name, factory, component_directive),
-                        factory)
-    elif component is AMBIGUOUS_COMPONENT:
-        raise GrokError("Multiple possible %ss for %r, please use "
-                        "%s." % (component_name, factory, component_directive),
-                        factory)
-    
-def determine_module_component(module_info, annotation, classes):
-    """Determine module-level component.
-
-    The module-level component can be set explicitly using the
-    annotation (such as grok.context).
-
-    If there is no annotation, the module-level component is determined
-    by scanning for subclasses of any in the list of classes.
-
-    If there is no module-level component, the module-level component is
-    None.
-
-    If there is one module-level component, it is returned.
-
-    If there are more than one module-level component, AMBIGUOUS_COMPONENT
-    is returned.
-    """
-    components = scan_for_classes(module_info.getModule(), classes)
-    if len(components) == 0:
-        component = None
-    elif len(components) == 1:
-        component = components[0]
-    else:
-        component= AMBIGUOUS_COMPONENT
-        
-    module_component = module_info.getAnnotation(annotation, None)
-    if module_component:
-        component = module_component
-    return component
-
-
-def determine_class_component(module_info, class_,
-                              component_name, component_directive):
-    """Determine component for a class.
-
-    Determine a component for a class. If no class-specific component exists,
-    try falling back on module-level component.
-    """
-    module_component = module_info.getAnnotation(component_directive, None)
-    component = class_annotation(class_, component_directive, module_component)
-    check_module_component(class_, component,
-                           component_name, component_directive)
-    return component

Deleted: grok/branches/brandon-grokcore.component/src/grok/zcml.py
===================================================================
--- grok/branches/brandon-grokcore.component/src/grok/zcml.py	2008-03-19 19:13:45 UTC (rev 84791)
+++ grok/branches/brandon-grokcore.component/src/grok/zcml.py	2008-03-19 20:27:14 UTC (rev 84792)
@@ -1,54 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006-2007 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Grok ZCML directives."""
-
-from zope.interface import Interface
-from zope.configuration.fields import GlobalObject
-from zope.configuration.config import ConfigurationMachine
-
-import martian
-from martian import scan
-from martian.error import GrokError
-
-class IGrokDirective(Interface):
-    """Grok a package or module."""
-
-    package = GlobalObject(
-        title=u"Package",
-        description=u"The package or module to be analyzed by grok.",
-        required=False,
-        )
-
-# add a cleanup hook so that grok will bootstrap itself again whenever
-# the Component Architecture is torn down.
-def resetBootstrap():
-    # we need to make sure that the grokker registry is clean again
-    the_module_grokker.clear()
-from zope.testing.cleanup import addCleanUp
-addCleanUp(resetBootstrap)
-
-the_multi_grokker = martian.MetaMultiGrokker()
-the_module_grokker = martian.ModuleGrokker(the_multi_grokker)
-
-def skip_tests(name):
-    return name in ['tests', 'ftests']
-
-def grokDirective(_context, package):
-    do_grok(package.__name__, _context)
-
-def do_grok(dotted_name, config):
-    martian.grok_dotted_name(
-        dotted_name, the_module_grokker, exclude_filter=skip_tests,
-        config=config
-        )



More information about the Checkins mailing list