[Checkins] SVN: grok/trunk/src/grok/ We moved various things from
martian into Grok (for refactoring them,
Martijn Faassen
faassen at infrae.com
Thu Jan 24 13:06:15 EST 2008
Log message for revision 83189:
We moved various things from martian into Grok (for refactoring them,
but that's on the viewlets2 branch).
Changed:
U grok/trunk/src/grok/meta.py
U grok/trunk/src/grok/util.py
-=-
Modified: grok/trunk/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py 2008-01-24 18:03:21 UTC (rev 83188)
+++ grok/trunk/src/grok/meta.py 2008-01-24 18:06:14 UTC (rev 83189)
@@ -48,12 +48,14 @@
from grok import components, formlib, templatereg
from grok.util import check_adapts, get_default_permission, make_checker
from grok.util import determine_class_directive, public_methods_from_class
+from grok.util import determine_module_context, determine_class_context
+from grok.util import check_context
from grok.rest import RestPublisher
from grok.interfaces import IRESTSkinType
def get_context(module_info, factory):
context = module_info.getAnnotation('grok.context', None)
- return util.determine_class_context(factory, context)
+ return determine_class_context(factory, context)
def get_name_classname(factory):
return get_name(factory, factory.__name__.lower())
@@ -74,7 +76,7 @@
def grok(self, name, module, module_info, config, **kw):
possible_contexts = martian.scan_for_classes(module, [grok.Model,
grok.Container])
- context = util.determine_module_context(module_info, possible_contexts)
+ context = determine_module_context(module_info, possible_contexts)
module.__grok_context__ = context
return True
@@ -450,7 +452,7 @@
if interfaces is None:
# There's no explicit interfaces defined, so we assume the
# module context to be the thing adapted.
- util.check_context(module_info.getModule(), context)
+ check_context(module_info.getModule(), context)
interfaces = (context, )
config.action(
Modified: grok/trunk/src/grok/util.py
===================================================================
--- grok/trunk/src/grok/util.py 2008-01-24 18:03:21 UTC (rev 83188)
+++ grok/trunk/src/grok/util.py 2008-01-24 18:06:14 UTC (rev 83189)
@@ -122,3 +122,32 @@
def sort_components(components):
# if components have a grok.order directive, sort by that
return sorted(components, key=_sort_key)
+
+AMBIGUOUS_CONTEXT = object()
+def check_context(component, context):
+ if context is None:
+ raise GrokError("No module-level context for %r, please use "
+ "grok.context." % component, component)
+ elif context is AMBIGUOUS_CONTEXT:
+ raise GrokError("Multiple possible contexts for %r, please use "
+ "grok.context." % component, component)
+
+def determine_module_context(module_info, models):
+ if len(models) == 0:
+ context = None
+ elif len(models) == 1:
+ context = models[0]
+ else:
+ context = AMBIGUOUS_CONTEXT
+
+ module_context = module_info.getAnnotation('grok.context', None)
+ if module_context:
+ context = module_context
+
+ return context
+
+
+def determine_class_context(class_, module_context):
+ context = class_annotation(class_, 'grok.context', module_context)
+ check_context(class_, context)
+ return context
More information about the Checkins
mailing list