本文整理汇总了Python中zope.dottedname.resolve.resolve函数的典型用法代码示例。如果您正苦于以下问题:Python resolve函数的具体用法?Python resolve怎么用?Python resolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_root_site_manager
def check_root_site_manager(tool):
"""2.0.x to 2.1.0 upgrade step checker
"""
portal = aq_parent(aq_inner(tool))
try:
# We have to call setSite to make sure we have a site with a proper
# acquisition context.
setSite(portal)
sm = portal.getSiteManager()
if sm.utilities.LookupClass != FiveVerifyingAdapterLookup:
return True
except ComponentLookupError:
return True
for tool_interface in _BAD_UTILITIES:
try:
iface = resolve(tool_interface)
except ImportError:
continue
if sm.queryUtility(iface) is not None:
return True
for tool_id, tool_interface in _TOOL_UTILITIES:
tool_obj = getToolByName(portal, tool_id, default=None)
try:
iface = resolve(tool_interface)
except ImportError:
continue
if tool_obj is not None and sm.queryUtility(iface) is None:
return True
return False
示例2: getProtobuf
def getProtobuf(self, protobuf_name):
"""
Get a protobuf class from the identifier supplied.
"""
# Initialize mapping of protobuf full name to protobuf class
if self._protobuf_full_name_to_class is None:
self._protobuf_full_name_to_class = {}
for contentType in self._content_types.values():
try:
cls = resolve(contentType.python_class)
self._protobuf_full_name_to_class[cls.DESCRIPTOR.full_name] = cls
except ImportError:
log.exception('Failed to resolve protobuf: %s', protobuf_name)
if protobuf_name in self._protobuf_full_name_to_class:
cls = self._protobuf_full_name_to_class[protobuf_name]
else:
try:
config = self.getContentType(protobuf_name)
except KeyError:
raise SchemaException('Could not find protobuf "%s"' % protobuf_name)
try:
cls = resolve(config.python_class)
except ImportError:
raise ImportError('Could not find protobuf python class "%s"' % config.python_class)
return cls
示例3: setData
def setData(self, interfacedata, metadata):
"""
Sets a list of properties on a object.
Warning: all currently set properties which are not in the
properties-list wille be removed!
@param object: Plone-Object to set the properties on
@type object: Plone-Object
@param properties: list of propertes.
See ftw.publisher.sender.extractor
for format details.
@param type: list
@return: None
"""
self.logger.info('Updating interface data (UID %s)' %
(self.object.UID())
)
current_ifaces = set(self.adapted.getDirectlyProvidedNames())
desired_ifaces = set(interfacedata)
for iface_dotted in current_ifaces - desired_ifaces:
iface = resolve(iface_dotted)
noLongerProvides(self.object, iface)
for iface_dotted in desired_ifaces - current_ifaces:
iface = resolve(iface_dotted)
alsoProvides(self.object, iface)
示例4: register_new_custom_type
def register_new_custom_type(type_key, workflow_key, archetype_key):
"""Retrieve (create if needed) a domain interface and model for type_key,
and register as new entry on TYPE_REGISTER.
"""
# generate custom domain interface
domain_iface_name = naming.model_interface_name(type_key)
try:
domain_iface = resolve("%s.%s" % (INTERFACE_MODULE.__name__, domain_iface_name))
log.warn("Custom interface ALREADY EXISTS: %s" % (domain_iface))
except ImportError:
domain_iface = new_custom_domain_interface(type_key, domain_iface_name)
# generate custom domain_model
domain_model_name = naming.model_name(type_key)
try:
domain_model = resolve("%s.%s" % (MODEL_MODULE.__name__, domain_model_name))
log.warn("Custom domain model ALREADY EXISTS: %s" % (domain_model))
except ImportError:
domain_model = new_custom_domain_model(type_key, domain_iface, archetype_key)
# type_info entry
ti = TI(workflow_key, domain_iface, domain_model)
ti.custom = True
TYPE_REGISTRY.append((type_key, ti))
log.info("Registered custom type [%s]: %s" % (archetype_key, type_key))
return type_key, ti
示例5: load_modules
def load_modules(app, config):
# load up builtins and modules
app.modules = []
try:
_modules = [
m.strip() for
m in config['aio']['builtin'].strip('').split('\n')
if m.strip()]
for m in _modules:
app.modules.append(resolve(m))
except KeyError:
pass
try:
_modules = [
m.strip() for
m in config['aio']['modules'].strip('').split('\n')
if m.strip()]
for m in _modules:
app.modules.append(resolve(m))
except KeyError:
pass
app.modules = tuple(app.modules)
示例6: loadPlugins
def loadPlugins(self):
log.err("bit.core.plugins: loadPlugins")
config = getUtility(IConfiguration)
plugins = config.get("bit", "plugins")
snippet = "<include package='zope.component' />"
zcml = zcml_template % snippet
xmlconfig(StringIO(zcml))
if isinstance(plugins, str):
plugins = [plugins]
for plugin in plugins:
snippet = "<include package='%s' />" % plugin
zcml = zcml_template % snippet
zcml_path = os.path.join(resolve(plugin).__path__[0], "configure.zcml")
if os.path.exists(zcml_path):
xmlconfig(StringIO(zcml))
for plugin in plugins:
snippet = "<include package='%s' file='meta.zcml' />" % plugin
zcml = zcml_template % snippet
zcml_path = os.path.join(resolve(plugin).__path__[0], "meta.zcml")
if os.path.exists(zcml_path):
xmlconfig(StringIO(zcml))
for plugin in plugins:
snippet = "<include package='%s' file='plugin.zcml' />" % plugin
zcml = zcml_template % snippet
zcml_path = os.path.join(resolve(plugin).__path__[0], "plugin.zcml")
if os.path.exists(zcml_path):
xmlconfig(StringIO(zcml))
示例7: remove_old_contentleadimage
def remove_old_contentleadimage(context, logger=None):
if logger is None:
# Called as upgrade step: define our own logger.
logger = logging.getLogger('cpskin.policy remove_old_contentleadimage')
portal = api.portal.get()
sm = portal.getSiteManager()
utilities = {
'subscribers': sm.utilities._subscribers[0],
'adapters': sm.utilities._adapters[0],
# 'provided': sm.utilities._provided
}
util_klass = resolve('plone.browserlayer.interfaces.ILocalBrowserLayerType')
reg_klass = resolve('collective.contentleadimage.interfaces.ILeadImageSpecific')
for sm_type in utilities.keys():
utility_registrations = utilities[sm_type]
for x in utility_registrations.keys():
if x.__module__ == util_klass.__module__ and x == util_klass:
for name, klass in utility_registrations[x].items():
found = find_object_or_class(klass, reg_klass)
# if found:
# import pdb; pdb.set_trace()
if found:
if type(utility_registrations[x][name]) in \
[list, tuple, set]:
regs = list(utility_registrations[x][name])
regs.remove(found)
logger.info('{0} {1} removed'.format(sm_type, reg_klass))
utility_registrations[x][name] = tuple(regs)
else:
logger.info('{0} removed'.format(name))
del utility_registrations[x][name]
setattr(sm.utilities, '_' + sm_type, [utility_registrations])
示例8: load_object
def load_object(epstr):
"""Loads the object represented in entry-point syntax by the
specified string."""
if ':' in epstr:
module, attr = epstr.split(':')
module = resolve(module)
return getattr(module, attr)
return resolve(epstr)
示例9: _configure
def _configure(self=None,
set_up_packages=(),
features=('devmode', 'testmode'),
context=None,
package=None):
features = set(features) if features is not None else set()
# This is normally created by a slug, but tests may not always
# load the slug
if os.getenv('DATASERVER_DIR_IS_BUILDOUT'): # pragma: no cover
features.add('in-buildout')
# zope.component.globalregistry conveniently adds
# a zope.testing.cleanup.CleanUp to reset the globalSiteManager
if context is None and (features or package):
context = config.ConfigurationMachine()
context.package = package
xmlconfig.registerCommonDirectives(context)
for feature in features:
context.provideFeature(feature)
if set_up_packages:
logger.debug("Configuring %s with features %s", set_up_packages, features)
for i in set_up_packages:
__traceback_info__ = (i, self)
if isinstance(i, tuple):
filename = i[0]
package = i[1]
else:
filename = 'configure.zcml'
package = i
if isinstance(package, six.string_types):
package = dottedname.resolve(package)
try:
context = xmlconfig.file(filename, package=package, context=context)
except IOError as e:
# Did we pass in a test module (__name__) and there is no
# configuration in that package? In that case, we want to
# configure the parent package for sure
module_path = getattr(package, '__file__', '')
if (module_path
and 'tests' in module_path
and os.path.join(os.path.dirname(module_path), filename) == e.filename):
parent_package_name = '.'.join(package.__name__.split('.')[:-2])
package = dottedname.resolve(parent_package_name)
context = xmlconfig.file(filename, package=package, context=context)
else: # pragma: no cover
raise
return context
示例10: unmarshal
def unmarshal(self, mkey, func_name, marshalled_args, marshalled_kwargs):
"""Does the reverse operation of ``marshal``
"""
Marshaller = resolve(mkey)
marshaller = Marshaller()
func = resolve(func_name)
args, kwargs = marshaller.unmarshal(
*marshalled_args,
**marshalled_kwargs
)
return (func, args, kwargs)
示例11: __init__
def __init__(self, logger, data):
self.input_preparation_list = []
for plugin_data in data["application_configuration"]["pre_processing"]["plugin_list"]:
self.input_preparation_list.append(resolve(plugin_data["_class"])(logger, plugin_data))
self.output_preparation_list = []
for plugin_data in data["application_configuration"]["post_processing"]["plugin_list"]:
self.output_preparation_list.append(resolve(plugin_data["_class"])(logger, plugin_data))
plugin_data = data["application_configuration"]["processing_plugin"]
self.execution_plugin = resolve(plugin_data["_class"])(logger, plugin_data)
示例12: __init__
def __init__(self, logger, data):
self.input_preparation_list = []
for plugin_data in data['application_configuration']['pre_processing']['plugin_list']:
self.input_preparation_list.append(resolve(plugin_data['_class'])(logger, plugin_data))
self.output_preparation_list = []
for plugin_data in data['application_configuration']['post_processing']['plugin_list']:
self.output_preparation_list.append(resolve(plugin_data['_class'])(logger, plugin_data))
plugin_data = data['application_configuration']['processing_plugin']
self.execution_plugin = resolve(plugin_data['_class'])(logger, plugin_data)
示例13: sign
def sign(self, schema, usedottedname=False):
"""
sign the object with the signature of the schema used on it
"""
if usedottedname:
if schema.__module__ != '.'.join((PKGNAME, 'schema.generated')):
if isdottedname(schema.__identifier__):
resolve(schema.__identifier__) # ensure it can be imported
self.signature = schema.__identifier__
return
saver = queryUtility(ISchemaSaver)
#persist serialization of schema, get signature
self.signature = saver.add(schema)
示例14: is_operation_valid
def is_operation_valid(self, registry, operation):
# Check that the operation exists.
op_info = registry.get(operation)
if op_info is None:
logger.error("Operation %r is not defined.", operation)
return False
op_function_name = op_info.get("operation")
try:
resolve(op_function_name)
except ImportError:
logger.error("ImportError for operation %r: %s", operation, op_function_name)
return False
return True
示例15: resolve_plugin_class
def resolve_plugin_class(self, plugin_name):
try:
plugin_class = dottedname.resolve(plugin_name)
except ImportError as e:
full_plugin_name = 'replay.plugins.' + plugin_name
try:
plugin_class = dottedname.resolve(full_plugin_name)
except ImportError:
raise e
if not (inspect.isclass(plugin_class)
and issubclass(plugin_class, plugins.Plugin)):
raise ValueError('{} is not a Plugin'.format(plugin_name))
return plugin_class