Transform an Element to a list of entities recursively.
489546
def element_to_objects(payload: Dict) -> List:
    
    entities = []
    cls = MAPPINGS.get(payload.get('type'))
    if not cls:
        return []

    transformed = transform_attributes(payload, cls)
    entity = cls(**transformed)

    if hasattr(entity, "post_receive"):
        entity.post_receive()

    entities.append(entity)

    return entities
815980
def to_element(self, root_name=None):
        """"""
        if not root_name:
            root_name = self.nodename
        elem = ElementTreeBuilder.Element(root_name)
        for attrname in self.serializable_attributes():
            # Only use values that have been loaded into the internal
            # __dict__. For retrieved objects we look into the XML response at
            # access time, so the internal __dict__ contains only the elements
            # that have been set on the client side.
            try:
                value = self.__dict__[attrname]
            except KeyError:
                continue

            if attrname in self.xml_attribute_attributes:
                elem.attrib[attrname] = six.text_type(value)
            else:
                sub_elem = self.element_for_value(attrname, value)
                elem.append(sub_elem)

        return elem
1028604
def flatten(listish):
    
    for elem in listish:
        if (isinstance(elem, collections.Iterable)
                and not isinstance(elem, basestring)):
            for subelem in flatten(elem):
                yield subelem
        else:
            yield elem
1077140
def object_to_items(data_structure):
    """"""
    items = []
    # Get all items from dict
    try:
        items = list(data_structure.__dict__.items())
    except:
        pass
    # Get all slots
    hierarchy = [data_structure]
    try:
        hierarchy += inspect.getmro(data_structure)
    except:
        pass
    slots = []
    try:
        for b in hierarchy:
            try:
                slots += b.__slots__
            except:  # pragma: no cover
                pass
    except:  # pragma: no cover
        pass
    # Get attrs from slots
    for x in slots:
        items.append((x, getattr(data_structure, x)))
    return items
1174986
def _element_to_dict(data, position, obj_end, opts):
    """"""
    element_type = data[position:position + 1]
    position += 1
    element_name, position = _get_c_string(data, position, opts)
    try:
        value, position = _ELEMENT_GETTER[element_type](data, position,
                                                        obj_end, opts,
                                                        element_name)
    except KeyError:
        _raise_unknown_type(element_type, element_name)

    if opts.type_registry._decoder_map:
        custom_decoder = opts.type_registry._decoder_map.get(type(value))
        if custom_decoder is not None:
            value = custom_decoder(value)

    return element_name, value, position
900632
def _xml_convert(self, element):
        

        children = list(element)

        if len(children) == 0:
            return self._type_convert(element.text)
        else:
            # if the fist child tag is list-item means all children are list-item
            if children[0].tag == "list-item":
                data = []
                for child in children:
                    data.append(self._xml_convert(child))
            else:
                data = {}
                for child in children:
                    data[child.tag] = self._xml_convert(child)

            return data
396398
function transform( nodes ) {
	var out;
	var i;

	out = new Array( nodes.length );
	for ( i = 0; i < nodes.length; i++ ) {
		out[ i ] = filter( nodes[ i ] );
	}
	return out;
}
855506
def _elements_to_dict(data, position, obj_end, opts, result=None):
    """"""
    if result is None:
        result = opts.document_class()
    end = obj_end - 1
    while position < end:
        key, value, position = _element_to_dict(data, position, obj_end, opts)
        result[key] = value
    if position != obj_end:
        raise InvalidBSON('bad object or element length')
    return result
252782
def transform(self, attrs):
        """"""
        self.collect(attrs)
        self.add_missing_implementations()
        self.fill_attrs(attrs)
785949
function convertElement (el, self) {
  if (el instanceof Schema) {
    return el.toObject(self);
  }

  if (isObject(el)) {
    return convertObject(el, self);
  }

  if (Array.isArray(el)) {
    return el.map(function (item) {
      return convertElement(item, self);
    })
  }

  return el;
}
202032
def to_entity(entity_type, value, fields):
    
    e = entity_type(value)
    for k, v in fields.items():
        e.fields[k] = Field(k, v)
    return e
527485
def flatten(l: Iterable) -> List:
    
    rval = []
    for e in l:
        if not isinstance(e, str) and isinstance(e, Iterable):
            if len(list(e)):
                rval += flatten(e)
        else:
            rval.append(e)
    return rval
1185549
def _elements_to_dict(data, position, obj_end, opts, subdocument=None):
    """"""
    if type(opts.document_class) == tuple:
        result = opts.document_class[0](**opts.document_class[1]) if not subdocument else dict()
    else:
        result = opts.document_class() if not subdocument else dict()
    end = obj_end - 1
    while position < end:
        (key, value, position) = _element_to_dict(data, position, obj_end, opts)
        result[key] = value
    return result
1096473
def _convertToElementList(elements_list):
    
    elements = []
    current_element = []
    for node_index in elements_list:
        if node_index == -1:
            elements.append(current_element)
            current_element = []
        else:
            current_element.append(node_index)

    return elements
1355274
def node_from_elem(elem, nodefactory=Node, lazy=()):
    
    children = list(elem)
    lineno = getattr(elem, 'lineno', None)
    if not children:
        return nodefactory(elem.tag, dict(elem.attrib), elem.text,
                           lineno=lineno)
    if striptag(elem.tag) in lazy:
        nodes = (node_from_elem(ch, nodefactory, lazy) for ch in children)
    else:
        nodes = [node_from_elem(ch, nodefactory, lazy) for ch in children]
    return nodefactory(elem.tag, dict(elem.attrib), nodes=nodes, lineno=lineno)
863157
static function processElementTransformationList( $tpl, &$node, $elements, &$privateData )
    {
        $useComments = $privateData['use-comments'];
        $php =& $privateData['php-creator'];
        $resourceData =& $privateData['resource-data'];
        $elementTree = $elements;
        $newElements = eZTemplateCompiler::processElementTransformationChild( $useComments, $php, $tpl, $node,
                                                                              $elementTree, $elements, $resourceData );
        if ( $newElements )
            return $newElements;
        return $elements;
    }
1090234
def get_elements(nodelist):
    

    element_list = []
    for node in nodelist:
        if node.nodeType == Node.ELEMENT_NODE:
            element_list.append(node)

    return element_list