Load this tree from a dumb data object for serialisation.

        The object must have attributes tree_size:int and hashes:list.
335062
def load(self, other: merkle_tree.MerkleTree):
        
        self._update(other.tree_size, other.hashes)
828627
def load_attributes_from_response(response)
      if (response['Transfer-Encoding'] == 'chunked' || (!response['Content-Length'].blank? && response['Content-Length'] != "0")) && !response.body.nil? && response.body.strip.size > 0
        load( self.class.format.decode(response.body)[self.class.element_name] )
        #fix double nested items .. active resource SUCKS soooo bad
        if self.respond_to?(:items)
          new_items = []
          self.items.each { |item| new_items << item.attributes.first[1] }
          self.items = new_items
        end
        @persisted = true
      end
    end
279761
def serialize_tree(tree, feature_names, outfile):
        

        tree_ = tree.tree_
        feature_name = [feature_names[i] if i != _tree.TREE_UNDEFINED else 'n/a' for i in tree_.feature]

        def traverse(node, depth, outfile):
            if tree_.feature[node] != _tree.TREE_UNDEFINED:
                name = feature_name[node]
                threshold = tree_.threshold[node]

                # Define internal node for serialization
                internal_node = {
                    'type': 'internal',
                    'split': {
                        'type': 'continuous',
                        'featureIndex': feature_names.index(name),
                        'threshold': threshold
                    }
                }

                # Serialize the internal Node
                json.dump(internal_node, outfile)
                outfile.write('\n')

                # Traverse Left
                traverse(tree_.children_left[node], depth + 1, outfile)

                # Traverse Rigiht
                traverse(tree_.children_right[node], depth + 1, outfile)
            else:
                leaf_node = {
                    'type': 'leaf',
                    'values': tree_.value[node].tolist()[0]
                }

                # Serialize the leaf node
                json.dump(leaf_node, outfile)
                outfile.write('\n')

        traverse(0, 1, outfile)
1344145
def loads(cls, str):
        
        d = json.loads(str)
        return cls.create(d)
1056542
def get_tree(cls, parent=None):
        
        if parent:
            depth = parent.get_depth() + 1
            results = [parent]
        else:
            depth = 1
            results = []
        cls._get_tree_recursively(results, parent, depth)
        return results
502581
def data_object(data)
      data = data.keys.first if data.is_a?(Hash) && data.keys.size == 1
      data = @_object.__send__(data) if data.is_a?(Symbol) && defined?(@_object) && @_object && @_object.respond_to?(data)
      data
    end
993306
def hash_full_tree(self, leaves):
        """"""
        root_hash, hashes = self._hash_full(leaves, 0, len(leaves))
        assert len(hashes) == count_bits_set(len(leaves))
        assert (self._hash_fold(hashes) == root_hash if hashes else
                root_hash == self.hash_empty())
        return root_hash
28912
def load_all(self, key, default=None):
        '''
        
        '''
        value = getattr(self, key)
        if default is not None:
            def loader(path): return self.load_path_with_default(path, default)
        else:
            loader = self.load_path
        if isinstance(value, dict):
            return {key: loader(value) for key, value in value.items()}
        elif isinstance(value, list):
            return [loader(value) for value in value]
        else:
            raise ValueError('load_all must be list or dict')
893540
def loads(self, s):
        
        io = six.StringIO()
        io.write(s)
        io.seek(0)
        self.load(io)
        self.validate()
1245639
def load_from_object(self, object_name):
        
        for key in dir(object_name):
            if key.isupper():
                self[key] = getattr(object_name, key)
150726
def load(cls, path, base=None):
        ''''''
        obj = cls()
        obj.read(path, base)
        return obj
1334770
def from_dict(cls, dictionary, root=False):
        

        def create_tree(value):
            if isinstance(value, dict):
                res = ConfigTree(root=root)
                for key, child_value in value.items():
                    res.put(key, create_tree(child_value))
                return res
            if isinstance(value, list):
                return [create_tree(v) for v in value]
            else:
                return value

        return create_tree(dictionary)
134404
def load_object(self, obj):
        
        locator = self._make_locator()

        path = locator.find_object(obj, self.search_dirs)

        return self.read(path)
1249260
def _load(self, tree):
        
        filename = tree.load_file[0]
        if filename[0] in ['"', "'"]:
            filename = unwrap(filename)
        if not os.path.exists(filename):
            raise Exception("No such file %r" % filename)
        batch = self.connection.batch_write(tree.table)
        count = 0
        with batch:
            remainder, ext = os.path.splitext(filename)
            if ext.lower() in [".gz", ".gzip"]:
                ext = os.path.splitext(remainder)[1]
                opened = gzip.open(filename, "rb")
            else:
                opened = open(filename, "r")
            with opened as ifile:
                if ext.lower() == ".csv":
                    reader = csv.DictReader(ifile)
                    for row in reader:
                        batch.put(row)
                        count += 1
                elif ext.lower() == ".json":
                    for row in ifile:
                        batch.put(json.loads(row))
                        count += 1
                else:
                    try:
                        while True:
                            batch.put(pickle.load(ifile))
                            count += 1
                    except EOFError:
                        pass
        return count
930467
def load_numpy(self, hash_list):
        
        assert len(hash_list) == 1
        self._check_hashes(hash_list)
        with open(self.object_path(hash_list[0]), 'rb') as fd:
            return np.load(fd, allow_pickle=False)
405508
def tree_load(**kwargs):
            
            str_pathDiskRoot    = ''
            b_loadJSON          = True
            b_loadPickle        = False
            for key, val in kwargs.items():
                if key == 'pathDiskRoot':   str_pathDiskRoot    = val
                if key == 'loadJSON':       b_loadJSON          = val
                if key == 'loadPickle':     b_loadPickle        = val

            l_dir   = []
            l_file  = []
            for str_root, l_directories, l_filenames in os.walk(str_pathDiskRoot):
                for str_dir in l_directories:
                    l_dir.append(os.path.join(str_root, str_dir))
                for str_file in l_filenames:
                    l_file.append(os.path.join(str_root, str_file))
            stree_dirs  = [d.replace(str_pathDiskRoot, '') for d in l_dir]
            stree_files = [f.replace(str_pathDiskRoot, '') for f in l_file]

            # Create the tree
            rtree       = C_stree()
            # Build the directory structures
            for d in stree_dirs:
                # print(d)
                rtree.mkdir(d)
            # Now read any files
            for f in stree_files:
                dirname     = os.path.dirname(f)
                filename    = os.path.basename(f)
                # print(f)
                if b_loadJSON:
                    with open(str_pathDiskRoot + '/' + f, 'r') as fp:
                        contents = json.load(fp)
                        fp.close()
                if b_loadPickle:
                    with open(str_pathDiskRoot + '/' + f, 'rb') as fp:
                        contents = pickle.load(fp)
                        fp.close()

                if rtree.cd(dirname)['status']:
                    rtree.touch(filename, contents)

            return rtree
1138886
def etree(self, data, root=None):
        ''''''
        result = self.list() if root is None else root
        if isinstance(data, (self.dict, dict)):
            for key, value in data.items():
                if isinstance(value, (self.dict, dict)):
                    elem = self.element(key)
                    if elem is None:
                        continue
                    result.append(elem)

                    if 'attributes' in value:
                        for k, v in value['attributes'].items():
                            elem.set(k, self._tostring(v))
                    # else:
                    #     raise ValueError('Cobra requires "attributes" key for each element')

                    if 'children' in value:
                        for v in value['children']:
                            self.etree(v, root=elem)
                else:
                    elem = self.element(key)
                    if elem is None:
                        continue
                    elem.text = self._tostring(value)
                    result.append(elem)
        else:
            if root is not None:
                root.text = self._tostring(data)
            else:
                elem = self.element(self._tostring(data))
                if elem is not None:
                    result.append(elem)

        return result