/usr/share/pyshared/martian/context.py is in python-martian 0.14-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | from martian.directive import UnknownError
from martian.util import scan_for_classes
class GetDefaultComponentFactory(object):
def __init__(self, iface, component_name, directive_name):
"""Create a get_default_component function.
iface - the iface that the component to be associated implements.
for example: IContext
component_name - the name of the type of thing we are looking for.
for example: context
directive_name - the name of the directive in use.
for example: grok.context.
"""
self.iface = iface
self.component_name = component_name
self.directive_name = directive_name
def __call__(self, component, module, **data):
"""Determine module-level component.
Look for components in module.
iface determines the kind of module-level component to look for
(it will implement iface).
If there is no module-level component, raise an error.
If there is one module-level component, it is returned.
If there are more than one module-level component, raise
an error.
"""
components = list(scan_for_classes(module, self.iface))
if len(components) == 0:
raise UnknownError(
"No module-level %s for %r, please use the '%s' "
"directive."
% (self.component_name, component, self.directive_name),
component)
elif len(components) == 1:
return components[0]
else:
raise UnknownError(
"Multiple possible %ss for %r, please use the '%s' "
"directive."
% (self.component_name, component, self.directive_name),
component)
|