regobj.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:keypirinha-plugins 作者: EhsanKia 项目源码 文件源码
def set_subkey(self,name,value=None):
        """Create the named subkey and set its value.

        There are several different ways to specify the new contents of
        the named subkey:

          * if 'value' is the Key class, a subclass thereof, or None, then
            the subkey is created but not populated with any data.
          * if 'value' is a key instance,  the data from that key will be
            copied into the new subkey.
          * if 'value' is a dictionary, the dict's keys are interpreted as
            key or value names and the corresponding entries are created
            within the new subkey - nested dicts create further subkeys,
            while scalar values create values on the subkey.
          * any other value will be converted to a Value object and assigned
            to the default value for the new subkey.

        """
        self.sam |= KEY_CREATE_SUB_KEY
        subkey = Key(name,self)
        try:
            subkey = self.get_subkey(name)
        except AttributeError:
            _winreg.CreateKey(self.hkey,name)
            subkey = self.get_subkey(name)
        if value is None:
            pass
        elif issubclass(type(value),type) and issubclass(value,Key):
            pass
        elif isinstance(value,Key):
            for v in value.values():
                subkey[v.name] = v
            for k in value.subkeys():
                subkey.set_subkey(k.name,k)
        elif isinstance(value,dict):
            for (nm,val) in value.items():
                if isinstance(val,dict):
                    subkey.set_subkey(nm,val)
                elif isinstance(val,Key):
                    subkey.set_subkey(nm,val)
                elif issubclass(type(val),type) and issubclass(val,Key):
                    subkey.set_subkey(nm,val)
                else:
                    subkey[nm] = val
        else:
            if not isinstance(value,Value):
                value = Value(value)
            subkey[value.name] = value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号