本文整理汇总了Python中splunklib.searchcommands.decorators.Option.fix_up方法的典型用法代码示例。如果您正苦于以下问题:Python Option.fix_up方法的具体用法?Python Option.fix_up怎么用?Python Option.fix_up使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类splunklib.searchcommands.decorators.Option
的用法示例。
在下文中一共展示了Option.fix_up方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from splunklib.searchcommands.decorators import Option [as 别名]
# 或者: from splunklib.searchcommands.decorators.Option import fix_up [as 别名]
def __call__(self, o):
if isfunction(o):
# We must wait to finalize configuration as the class containing this function is under construction
# at the time this call to decorate a member function. This will be handled in the call to
# o.ConfigurationSettings.fix_up(o) in the elif clause of this code block.
o._settings = self.settings
elif isclass(o):
# Set command name
name = o.__name__
if name.endswith(b'Command'):
name = name[:-len(b'Command')]
o.name = unicode(name.lower())
# Construct ConfigurationSettings instance for the command class
o.ConfigurationSettings = ConfigurationSettingsType(
module=o.__module__ + b'.' + o.__name__,
name=b'ConfigurationSettings',
bases=(o.ConfigurationSettings,))
ConfigurationSetting.fix_up(o.ConfigurationSettings, self.settings)
o.ConfigurationSettings.fix_up(o)
Option.fix_up(o)
else:
raise TypeError('Incorrect usage: Configuration decorator applied to {0}'.format(type(o), o.__name__))
return o
示例2: fix_up
# 需要导入模块: from splunklib.searchcommands.decorators import Option [as 别名]
# 或者: from splunklib.searchcommands.decorators.Option import fix_up [as 别名]
def fix_up(cls, command_class):
is_option = lambda attribute: isinstance(attribute, Option)
definitions = getmembers(command_class, is_option)
validate_option_name = OptionName()
i = 0
for name, option in definitions:
if option.name is None:
option.name = name # no validation required
else:
validate_option_name(option.name)
if option.fget is None and option.fset is None and option.fdel is None:
backing_field_name = '_' + name
def fget(bfn):
return lambda this: getattr(this, bfn, None)
option = option.getter(fget(backing_field_name))
def fset(bfn, validate):
if validate is None:
return lambda this, value: setattr(this, bfn, value)
return lambda this, value: setattr(this, bfn, validate(value))
option = option.setter(fset(backing_field_name, option.validate))
setattr(command_class, name, option)
elif option.validate is not None:
def fset(function, validate):
return lambda this, value: function(this, validate(value))
option = option.setter(fset(option.fset, option.validate))
setattr(command_class, name, option)
definitions[i] = name, option
i += 1
command_class.option_definitions = definitions