从一个已经存在的 dict 中复制所有的值。

        :param adict: 被复制的 dict。
        :type adict: dict
        :param parent:  复制到哪个父对象。
                        若为 None 则复制到 self 。
        :type parent: rookout.PYConf
979085
def copy_from_dict(self, adict, parent=None):
        
        if not parent:
            parent = self
        for k,v in adict.items():
            if isinstance(v, dict):
                vDict = PYConf(v)
                self.copy_from_dict(v, vDict)
                parent[k] = vDict
            else:
                parent[k] = v
1116448
def _broadcast_and_set_attrs(self, local_dict):
        
        del local_dict['self']
        self.remove_axis = False
        max_length = 0
        for key in local_dict:
            try:
                length = len(local_dict[key])
                if length > max_length:
                    max_length = length

            except TypeError:
                pass

        if max_length == 0:
            self.remove_axis = True
            for key in local_dict:
                setattr(self, key, np.array([local_dict[key]]))

        # check for bad length arrays
        else:
            for key in local_dict:
                try:
                    if len(local_dict[key]) < max_length and len(local_dict[key]) > 1:
                        raise ValueError("Casting parameters not correct."
                                         + " Need all at a maximum shape and the rest being"
                                         + "len-1 arrays or scalars")
                except TypeError:
                    pass

            # broadcast arrays
            for key in local_dict:
                try:
                    if len(local_dict[key]) == max_length:
                        setattr(self, key, local_dict[key])
                    elif len(local_dict[key]) == 1:
                        setattr(self, key, np.full((max_length,), local_dict[key][0]))
                except TypeError:
                    setattr(self, key, np.full((max_length,), local_dict[key]))
        return
1219704
def dict(
        self, *, include: 'SetStr' = None, exclude: 'SetStr' = None, by_alias: bool = False, skip_defaults: bool = False
    ) -> 'DictStrAny':
        
        get_key = self._get_key_factory(by_alias)
        get_key = partial(get_key, self.fields)

        return_keys = self._calculate_keys(include=include, exclude=exclude, skip_defaults=skip_defaults)
        if return_keys is None:
            return {get_key(k): v for k, v in self._iter(by_alias=by_alias, skip_defaults=skip_defaults)}
        else:
            return {
                get_key(k): v for k, v in self._iter(by_alias=by_alias, skip_defaults=skip_defaults) if k in return_keys
            }
904567
def parse_from_parent(
            self,
            parent,  # type: ET.Element
            state  # type: _ProcessorState
    ):
        # type: (...) -> Any
        """"""
        parsed_dict = self._dictionary.parse_from_parent(parent, state)
        return self._converter.from_dict(parsed_dict)
351968
def toDict(self):
		

		# Init the dictionary we will return
		dRet = {
			"__name__": self._name
		}

		# Get the parents dict and add it to the return
		dRet.update(super(Tree,self).toDict())

		# Return
		return dRet
459871
def dict(self):
        
        odict = {}
        for arg in _arg_names:
            value = getattr(self, arg)
            # Do not attempt to store preset option values in presets
            if arg in ('add_preset', 'del_preset', 'desc', 'note'):
                value = None
            odict[arg] = value
        return odict
765085
def cisco_conf_parse_parents(parent, child, config):
    
    if type(config) == str:
        config = config.splitlines()
    parse = CiscoConfParse(config)
    cfg_obj = parse.find_parents_w_child(parent, child)
    return cfg_obj
674620
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'dialog_node' in _dict:
            args['dialog_node'] = _dict.get('dialog_node')
        else:
            raise ValueError(
                'Required property \'dialog_node\' not present in DialogNode JSON'
            )
        if 'description' in _dict:
            args['description'] = _dict.get('description')
        if 'conditions' in _dict:
            args['conditions'] = _dict.get('conditions')
        if 'parent' in _dict:
            args['parent'] = _dict.get('parent')
        if 'previous_sibling' in _dict:
            args['previous_sibling'] = _dict.get('previous_sibling')
        if 'output' in _dict:
            args['output'] = DialogNodeOutput._from_dict(_dict.get('output'))
        if 'context' in _dict:
            args['context'] = _dict.get('context')
        if 'metadata' in _dict:
            args['metadata'] = _dict.get('metadata')
        if 'next_step' in _dict:
            args['next_step'] = DialogNodeNextStep._from_dict(
                _dict.get('next_step'))
        if 'title' in _dict:
            args['title'] = _dict.get('title')
        if 'type' in _dict or 'node_type' in _dict:
            args['node_type'] = _dict.get('type') or _dict.get('node_type')
        if 'event_name' in _dict:
            args['event_name'] = _dict.get('event_name')
        if 'variable' in _dict:
            args['variable'] = _dict.get('variable')
        if 'actions' in _dict:
            args['actions'] = [
                DialogNodeAction._from_dict(x) for x in (_dict.get('actions'))
            ]
        if 'digress_in' in _dict:
            args['digress_in'] = _dict.get('digress_in')
        if 'digress_out' in _dict:
            args['digress_out'] = _dict.get('digress_out')
        if 'digress_out_slots' in _dict:
            args['digress_out_slots'] = _dict.get('digress_out_slots')
        if 'user_label' in _dict:
            args['user_label'] = _dict.get('user_label')
        if 'disabled' in _dict:
            args['disabled'] = _dict.get('disabled')
        if 'created' in _dict:
            args['created'] = string_to_datetime(_dict.get('created'))
        if 'updated' in _dict:
            args['updated'] = string_to_datetime(_dict.get('updated'))
        return cls(**args)
1337882
def parent(self, index):
        
        if not index.isValid():
            return QtCore.QModelIndex()

        childItem = index.internalPointer()
        # the only place where the parent item is queried
        parentItem = childItem.getParent()

        if parentItem == self.root:
            return QtCore.QModelIndex()

        return self.createIndex(parentItem.row(), 0, parentItem)
122453
def purge_dict(idict):
    
    odict = {}
    for key, val in idict.items():
        if is_null(val):
            continue
        odict[key] = val
    return odict
28865
def get_parent_data(tree, node, current):
        
        if not current:
            current = []

        parent = tree.parent(node.identifier)
        if parent.is_root():
            return current

        current.insert(0, (parent.tag, parent.data))
        return PlateManager.get_parent_data(tree, parent, current)
184994
def teal(theTask, parent=None, loadOnly=False, returnAs="dict",
         canExecute=True, strict=False, errorsToTerm=False,
         autoClose=True, defaults=False):
#        overrides=None):
    
    if loadOnly: # this forces returnAs="dict"
        obj = None
        try:
            obj = cfgpars.getObjectFromTaskArg(theTask, strict, defaults)
#           obj.strictUpdate(overrides) # ! would need to re-verify after this !
        except Exception as re: # catches RuntimeError and KeyError and ...
            # Since we are loadOnly, don't pop up the GUI for this
            if strict:
                raise
            else:
                print(re.message.replace('\n\n','\n'))
        return obj
    else:
        assert returnAs in ("dict", "status", None), \
               "Invalid value for returnAs arg: "+str(returnAs)
        dlg = None
        try:
            # if setting to all defaults, go ahead and load it here, pre-GUI
            if defaults:
                theTask = cfgpars.getObjectFromTaskArg(theTask, strict, True)
            # now create/run the dialog
            dlg = ConfigObjEparDialog(theTask, parent=parent,
                                      autoClose=autoClose,
                                      strict=strict,
                                      canExecute=canExecute)
#                                     overrides=overrides)
        except cfgpars.NoCfgFileError as ncf:
            log_last_error()
            if errorsToTerm:
                print(str(ncf).replace('\n\n','\n'))
            else:
                popUpErr(parent=parent,message=str(ncf),title="Unfound Task")
        except Exception as re: # catches RuntimeError and KeyError and ...
            log_last_error()
            if errorsToTerm:
                print(re.message.replace('\n\n','\n'))
            else:
                popUpErr(parent=parent, message=re.message,
                         title="Bad Parameters")

        # Return, depending on the mode in which we are operating
        if returnAs is None:
            return

        if returnAs == "dict":
            if dlg is None or dlg.canceled():
                return None
            else:
                return dlg.getTaskParsObj()

        # else, returnAs == "status"
        if dlg is None or dlg.canceled():
            return -1
        if dlg.executed():
            return 1
        return 0
273393
def parent(self, value):
        

        if value is not None:
            assert issubclass(value.__class__, AbstractNode), "'{0}' attribute: '{1}' is not a '{2}' subclass!".format(
                "parent", value, AbstractNode.__class__.__name__)
        self.__parent = value
409978
def _take_values(self, item: Node) -> DictBasicType:
        """"""

        values = super()._take_values(item)
        values['_parent'] = None
        return values
955362
def structure_attrs_fromdict(self, obj, cl):
        # type: (Mapping[str, Any], Type[T]) -> T
        """"""
        # For public use.
        conv_obj = {}  # Start with a fresh dict, to ignore extra keys.
        dispatch = self._structure_func.dispatch
        for a in cl.__attrs_attrs__:  # type: ignore
            # We detect the type by metadata.
            type_ = a.type
            name = a.name

            try:
                val = obj[name]
            except KeyError:
                continue

            if name[0] == "_":
                name = name[1:]

            conv_obj[name] = (
                dispatch(type_)(val, type_) if type_ is not None else val
            )

        return cl(**conv_obj)
351914
def _container_factory(self, **options):
        
        ac_dict = options.get("ac_dict", False)
        _dicts = [x for x in (options.get(o) for o in self.dict_options())
                  if x]

        if self.dict_options() and ac_dict and callable(ac_dict):
            return ac_dict  # Higher priority than ac_ordered.
        if _dicts and callable(_dicts[0]):
            return _dicts[0]
        if self.ordered() and options.get("ac_ordered", False):
            return anyconfig.compat.OrderedDict

        return dict
1001156
def get_parent_component(self, fc):
        
        if self.debug: print("Looking for parent of %s (%s)"%(fc.id, fc.parent_id)) 
        parent_comp = None
        for comp in self.components.values():
            if self.debug: print(" - Checking "+comp.id) 
            for child in comp.children:
                if parent_comp == None:
                    if child.id == fc.id and comp.id == fc.parent_id:
                        if self.debug: print("1) It is "+comp.id) 
                        parent_comp = comp
                    else:
                        for child2 in child.children:
                            if self.debug: print("    - Checking child: %s, %s"%(child.id,child2.id)) 
                            if parent_comp == None and child2.id == fc.id and child.id == fc.parent_id:
                                if self.debug: print("2) It is "+child.id) 
                                parent_comp = child
                                break
                            else:
                                if self.debug: print("No..."   )
        return parent_comp