{{{
#!python
class IResourceMapper(Interface):
"""Map between Trac resources and their corresponding contexts."""
def get_resource_factories():
"""Generator yielding `(realm, resource_factory)` pairs.
The `resource_factory` is a function taking a `Context` and
returning an instance of a Resource subclass.
"""
def get_context_classes():
"""Generator yielding `(realm, context_subclass)` pairs."""
}}}
Example implementation:
{{{
#!python
# IResourceMapper methods
def get_resource_factories(self):
def wiki_page_factory(context):
from trac.wiki.model import WikiPage
assert context.resource == 'wiki'
return WikiPage(self.env, context.id)
# TODO: add `context.version` after blame integration
yield ('wiki', wiki_page_factory)
def get_context_classes(self):
return [] # base Context is OK so far, but could be:
# yield ('wiki', WikiContext)
}}}
More Context related changes:
- finish the s/resource/realm/ renaming started in r4552
- rename s/object/resource/
- `from_resource(req, resource)` doesn't need an env parameter,
as this is assumed to be available from the `resource`
- I think the above method is enough for getting a Context from a resource,
so I've reverted r4551
- fixed the `__call__` method and make it clearer
- documentation updates
In the !PermissionCache, effectively cache the results of the permission check. Ideally, those results should be cached at the Request level, I think.