本文整理汇总了Python中utils.AttributeDict.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python AttributeDict.__init__方法的具体用法?Python AttributeDict.__init__怎么用?Python AttributeDict.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.AttributeDict
的用法示例。
在下文中一共展示了AttributeDict.__init__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from utils import AttributeDict [as 别名]
# 或者: from utils.AttributeDict import __init__ [as 别名]
def __init__(self, *args, **kwargs):
AttributeDict.__init__(self)
self.env = Environment.getInstance()
self.resourceType = self.__class__.__name__
self.isUpdated = False
seen = set()
if not hasattr(self, '_schema'):
raise Fail("Resource failed to define a valid _schema")
# union global schema with local schema
schema = copy.deepcopy(self._schema)
for key in self.s_globalSchema:
if not key in schema:
schema[key] = self.s_globalSchema[key]
resolvedArgs = { }
keys = schema.keys()
keysLen = len(keys)
index = 0
# resolve unnamed arguments with names corresponding to the order
# they were passed to Resource's ctor and their relative definitions
# in the subclass' ResourceArgumentSchema (which is an OrderedDict,
# so as to retain this ordering information).
for arg in args:
if index < keysLen:
key = keys[index]
resolvedArgs[keys[index]] = arg
else:
raise InvalidArgument("Invalid unnamed argument %s provided to resource %s" % (arg, str(self)))
index += 1
for arg in kwargs:
if arg in resolvedArgs:
raise InvalidArgument("Invalid mixture of named and unnamed arguments provided to resource %s, possibly around argument %s" % (str(self), arg))
else:
resolvedArgs[arg] = kwargs[arg]
utils.log("Initializing resource '%s' with args: %s" % (self.resourceType, resolvedArgs))
# validate resource arguments
output = schema.validate(resolvedArgs)
for key in output:
self[key] = output[key]
self.subscriptions = {
'immediate' : set(),
'delayed' : set()
}
for sub in self.subscribes:
if len(sub) == 2:
action, resource = sub
immediate = False
else:
action, resource, immediate = sub
resource.subscribe(action, self, immediate)
for sub in self.notifies:
self.subscribe(*sub)
self._validate()
self._register()
utils.log("Added new resource '%s'" % (str(self), ))