[Checkins] SVN: grok/branches/snowsprint-viewlets2/src/grok/ Move
some functions back into Grok from Martian as we want to start
Martijn Faassen
faassen at infrae.com
Thu Jan 24 11:40:05 EST 2008
Log message for revision 83174:
Move some functions back into Grok from Martian as we want to start
refactoring them.
Changed:
U grok/branches/snowsprint-viewlets2/src/grok/meta.py
U grok/branches/snowsprint-viewlets2/src/grok/util.py
-=-
Modified: grok/branches/snowsprint-viewlets2/src/grok/meta.py
===================================================================
--- grok/branches/snowsprint-viewlets2/src/grok/meta.py 2008-01-24 16:38:57 UTC (rev 83173)
+++ grok/branches/snowsprint-viewlets2/src/grok/meta.py 2008-01-24 16:40:05 UTC (rev 83174)
@@ -49,13 +49,15 @@
import grok
from grok import components, formlib, templatereg
from grok.util import check_adapts, get_default_permission, make_checker
+from grok.util import check_context, determine_module_context
+from grok.util import determine_class_context
from grok.util import determine_class_directive, public_methods_from_class
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())
@@ -76,7 +78,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
@@ -452,7 +454,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/branches/snowsprint-viewlets2/src/grok/util.py
===================================================================
--- grok/branches/snowsprint-viewlets2/src/grok/util.py 2008-01-24 16:38:57 UTC (rev 83173)
+++ grok/branches/snowsprint-viewlets2/src/grok/util.py 2008-01-24 16:40:05 UTC (rev 83174)
@@ -124,3 +124,33 @@
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