本文整理汇总了Python中venusian.attach函数的典型用法代码示例。如果您正苦于以下问题:Python attach函数的具体用法?Python attach怎么用?Python attach使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了attach函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, wrapped):
def callback(scanner, name, ob):
if ob.classification_id not in CLASSIFICATIONS:
CLASSIFICATIONS[ob.classification_id] = ob
venusian.attach(wrapped, callback)
return wrapped
示例2: decorator
def decorator(wrapped):
def callback(scanner, name, ob):
scanner.registry.add(name, ob, internals, pass_msg)
venusian.attach(wrapped, callback)
return wrapped
示例3: method
def method(method_class):
"""Decorator to use to mark an API method.
When invoking L{Registry.scan} the classes marked with this decorator
will be added to the registry.
@param method_class: The L{Method} class to register.
"""
def callback(scanner, name, method_class):
if method_class.actions is not None:
actions = method_class.actions
else:
actions = [name]
if method_class.versions is not None:
versions = method_class.versions
else:
versions = [None]
for action in actions:
for version in versions:
scanner.registry.add(method_class,
action=action,
version=version)
from venusian import attach
attach(method_class, callback, category="method")
return method_class
示例4: __new__
def __new__(mcl, name, bases, d):
testing_config = d.get('testing_config')
d['registry'] = Registry(name, bases, testing_config,
d.get('variables', []))
result = super(AppMeta, mcl).__new__(mcl, name, bases, d)
venusian.attach(result, callback)
return result
示例5: _add_argument
def _add_argument(function, *args, **kwargs):
"""Add arguments to a function.
This adds a :mod:`venusian` callback to the given function in the
``serverstf:arguments`` category that, when scanned, will attempt to
add the given command line argument to the corresponding subcommand.
:param function: the function to add the callback to. This function must
be decorated by :func:`subcommand`.
:param args: passed to :meth:`argparse.ArgumentParser.add_argument`.
:param kwargs: passed to :meth:`argparse.ArgumentParser.add_argument`.
:return: the given ``function``.
"""
def callback(scanner, name, obj): # pylint: disable=unused-argument,missing-docstring
subcommands = getattr(obj, _SUBCOMMANDS, None)
if not subcommands:
raise CLIError("Can't set CLI arugments for "
"{} as it is not a subcommand".format(obj))
for command in subcommands:
command.arguments.append((args, kwargs))
# Depth 2 is required so that we can use this from within decorators.
venusian.attach(function, callback,
category=__package__ + ":arguments", depth=2)
return function
示例6: decorate
def decorate(factory):
def callback(scanner, factory_name, factory):
scanner.config.action(('location', name), set_location,
args=(scanner.config, name, factory),
order=PHASE2_CONFIG)
venusian.attach(factory, callback, category='pyramid')
return factory
示例7: __call__
def __call__(self, wrapped):
decorator = self
def callback(scanner, name, obj): #pylint: disable-msg=W0613
if hasattr(scanner, 'plugin_registry'):
scanner.plugin_registry.add('administration_link', decorator.link_text, PluginRegistryItem(decorator))
venusian.attach(wrapped, callback, category='pvs.plugins')
return wrapped
示例8: decorate
def decorate(checker):
def callback(scanner, factory_name, factory):
scanner.config.add_audit_checker(
checker, item_type, condition, frame)
venusian.attach(checker, callback, category='auditor')
return checker
示例9: __call__
def __call__(self, wrapped):
def callback(scanner, name, ob):
ob.name = self.name
ob.islocal = self.islocal
ob.superiors = list(ob.superiors)
ob.superiors.extend(self.superiors)
ob.superiors = list(set(ob.superiors))
def get_allsuperiors(role_ob):
superiors = list(role_ob.superiors)
for sup in role_ob.superiors:
superiors.extend(get_allsuperiors(sup))
return list(set(superiors))
ob.all_superiors = list(ob.all_superiors)
ob.all_superiors.extend(get_allsuperiors(ob))
ob.all_superiors = list(set(ob.all_superiors))
for role in ob.all_superiors:
role.lowers = list(set(getattr(role, 'lowers', [])))
role.lowers.append(ob)
role.lowers = list(set(role.lowers))
for role in getattr(ob, 'lowers', self.lowers):
role.superiors = list(role.superiors)
role.superiors.append(ob)
role.superiors = list(set(role.superiors))
role.all_superiors = list(role.all_superiors)
role.all_superiors.append(ob)
role.all_superiors.extend(ob.all_superiors)
role.all_superiors = list(set(role.all_superiors))
DACE_ROLES[ob.name] = ob
venusian.attach(wrapped, callback)
return wrapped
示例10: attach
def attach(self, action, cfg=None, depth=1):
action.info = self
if action.hash is None:
action.hash = self.hash
data = getattr(self.module, ATTACH_ATTR, None)
if data is None:
data = AttachData()
setattr(self.module, ATTACH_ATTR, data)
if cfg is None and action.hash in data:
raise TypeError(
"Directive registered twice: %s" % (action.discriminator,))
data[action.hash] = action
def callback(context, name, ob):
config = context.config.with_package(self.module)
config.info = action.info
config.action(
action.discriminator, self._runaction, (action, config),
introspectables=action.introspectables,
order=action.order)
venusian.attach(data, callback, category='ptah', depth=depth+1)
if cfg is not None:
cfg.action(
action.discriminator,
self._runaction, (action, cfg),
introspectables=action.introspectables, order=action.order)
示例11: __call__
def __call__(self, wrapped):
def callback(scanner, name, ob):
ob.component_id = self.component_id
ob.loading_component = self.loading_component
ob.on_demand = self.on_demand
ob.delegate = self.delegate
old_call = ob.update
def update(self):
if not self.params('load_view') or (self.on_demand and self.params('on_demand') != 'load'):
component = self.loading_component(
self.context, self.request,
component_id=self.component_id)
component.wrapper_template = ob.wrapper_template
component.title = ob.title
component.viewid = ob.viewid
component.view_icon = getattr(ob, 'view_icon', '')
component.counter_id = getattr(ob, 'counter_id', '')
component.css_class = ob.css_class + ' async-component-container'
component.container_css_class = ob.container_css_class + \
' async-component'
component.isactive = getattr(ob, 'isactive', False)
return component.update()
return old_call(self)
ob.update = update
ON_LOAD_VIEWS[self.component_id] = ob
venusian.attach(wrapped, callback, category='site_widget')
return wrapped
示例12: decorator
def decorator(wrapped):
def callback(scanner, name, obj):
for scheme in schemes:
scanner.config.registry.registerUtility(
obj, IStorageFactory, scheme)
venusian.attach(wrapped, callback)
return wrapped
示例13: __call__
def __call__(self, wrapped):
def callback(scanner, name, ob):
setattr(wrapped, '__meta__',
{'tablename': None,
'alias': 't{}'.format(self._counter),
'database': self.database,
'collation': self.collation,
'columns': None, # column name in the database
'attributes': None, # map col name to attribute name
# Populate on column descriptors
'primary_key': {},
'pkv': None,
'foreign_keys': {},
})
self.__class__._counter += 1
if not self.name:
self.name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2',
wrapped.__name__)
self.name = re.sub('([a-z0-9])([A-Z])', r'\1_\2',
self.name).lower()
wrapped.__meta__['tablename'] = self.name
meta.register(self.database, self.name, wrapped)
venusian.attach(wrapped, callback, category='aiorm')
return wrapped
示例14: wrapper
def wrapper(wrapped):
def callback(scanner, name, obj):
celery_app = scanner.config.registry.celery_app
celery_app.task(**kwargs)(obj)
venusian.attach(wrapped, callback)
return wrapped
示例15: conf_deco
def conf_deco(func):
def callback(venusian_scanner, *_):
"""This gets called by venusian at scan time."""
self.register(venusian_scanner, key, func)
venusian.attach(func, callback, category=self.category)
return func