当前位置: 首页>>代码示例>>Python>>正文


Python AttributeDict.__init__方法代码示例

本文整理汇总了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), ))
开发者ID:Stamped,项目名称:stamped-bootstrap,代码行数:71,代码来源:resource.py


注:本文中的utils.AttributeDict.__init__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。