(self, value, metadata=None, parent=None, clear=True)
return element
Serializes a raw value or class into an XML Element that can be sent
        over to the remote host.

        :param value: The value to serialize
        :param metadata: Any extra metadata to control how to serialize the
            value, if None then the value will be inferred by the type
        :param parent: Whether to append the element onto a parent element
        :param clear: Whether to clear the Obj and TN reference map, this
            should only be True when initially calling serialize
        :return: The XML Element from the serializied value
Serializes a raw value or class into an XML Element that can be sent
        over to the remote host.
Serializes a raw value or class into an XML Element that can be sent over to the remote host .
def serialize(self, value, metadata=None, parent=None, clear=True):
        """
        Serializes a raw value or class into an XML Element that can be sent
        over to the remote host.

        :param value: The value to serialize
        :param metadata: Any extra metadata to control how to serialize the
            value, if None then the value will be inferred by the type
        :param parent: Whether to append the element onto a parent element
        :param clear: Whether to clear the Obj and TN reference map, this
            should only be True when initially calling serialize
        :return: The XML Element from the serializied value
        """
        if clear:
            self._clear()

        if isinstance(value, ET.Element):
            if metadata is not None and metadata.name is not None:
                value.attrib['N'] = metadata.name

            if parent is not None:
                parent.append(value)

            return value

        metadata = metadata or ObjectMeta()
        if metadata.tag == "*":
            if isinstance(value, TaggedValue):
                metadata.tag = value.tag
                value = value.value
            else:
                metadata.tag = self._get_tag_from_value(value)

        pack_function = {
            # primitive types
            'S': lambda m, d: self._serialize_string(d),
            'ToString': lambda d: self._serialize_string(d),
            'C': lambda m, d: str(ord(d)),
            'B': lambda m, d: str(d).lower(),
            'DT': lambda m, d: None,
            'TS': lambda m, d: str(d),
            'By': lambda m, d: str(d),
            'SB': lambda m, d: str(d),
            'U16': lambda m, d: str(d),
            'I16': lambda m, d: str(d),
            'U32': lambda m, d: str(d),
            'I32': lambda m, d: str(d),
            'U64': lambda m, d: str(d),
            'I64': lambda m, d: str(d),
            'Sg': lambda m, d: str(d),
            'Db': lambda m, d: str(d),
            'D': lambda m, d: str(d),
            'BA': lambda m, d: to_string(base64.b64encode(d)),
            'G': lambda m, d: str(d),
            'URI': lambda m, d: self._serialize_string(d),
            'Version': lambda m, d: str(d),
            'XD': lambda m, d: self._serialize_string(d),
            'SBK': lambda m, d: self._serialize_string(d),
            'SS': lambda m, d: self._serialize_secure_string(d),
            'Obj': self._serialize_obj,
            "ObjDynamic": self._serialize_dynamic_obj,
            'LST': self._serialize_lst,
            'IE': self._serialize_ie,
            'QUE': self._serialize_que,
            'STK': self._serialize_stk,
            'DCT': self._serialize_dct
        }[metadata.tag]

        if value is None:
            if metadata.optional:
                return
            element = ET.Element("Nil")
        else:
            element_value = pack_function(metadata, value)
            if isinstance(element_value, str):
                element = ET.Element(metadata.tag)
                element.text = element_value
            else:
                element = element_value

        if metadata.name is not None:
            element.attrib['N'] = metadata.name

        if parent is not None:
            parent.append(element)

        return element
def serialize ( self , value , metadata = None , parent = None , clear = True ) : if clear : self . _clear ( ) if isinstance ( value , ET . Element ) : if metadata is not None and metadata . name is not None : value . attrib [ 'N' ] = metadata . name if parent is not None : parent . append ( value ) return value metadata = metadata or ObjectMeta ( ) if metadata . tag == "*" : if isinstance ( value , TaggedValue ) : metadata . tag = value . tag value = value . value else : metadata . tag = self . _get_tag_from_value ( value ) pack_function = { # primitive types 'S' : lambda m , d : self . _serialize_string ( d ) , 'ToString' : lambda d : self . _serialize_string ( d ) , 'C' : lambda m , d : str ( ord ( d ) ) , 'B' : lambda m , d : str ( d ) . lower ( ) , 'DT' : lambda m , d : None , 'TS' : lambda m , d : str ( d ) , 'By' : lambda m , d : str ( d ) , 'SB' : lambda m , d : str ( d ) , 'U16' : lambda m , d : str ( d ) , 'I16' : lambda m , d : str ( d ) , 'U32' : lambda m , d : str ( d ) , 'I32' : lambda m , d : str ( d ) , 'U64' : lambda m , d : str ( d ) , 'I64' : lambda m , d : str ( d ) , 'Sg' : lambda m , d : str ( d ) , 'Db' : lambda m , d : str ( d ) , 'D' : lambda m , d : str ( d ) , 'BA' : lambda m , d : to_string ( base64 . b64encode ( d ) ) , 'G' : lambda m , d : str ( d ) , 'URI' : lambda m , d : self . _serialize_string ( d ) , 'Version' : lambda m , d : str ( d ) , 'XD' : lambda m , d : self . _serialize_string ( d ) , 'SBK' : lambda m , d : self . _serialize_string ( d ) , 'SS' : lambda m , d : self . _serialize_secure_string ( d ) , 'Obj' : self . _serialize_obj , "ObjDynamic" : self . _serialize_dynamic_obj , 'LST' : self . _serialize_lst , 'IE' : self . _serialize_ie , 'QUE' : self . _serialize_que , 'STK' : self . _serialize_stk , 'DCT' : self . _serialize_dct } [ metadata . tag ] if value is None : if metadata . optional : return element = ET . Element ( "Nil" ) else : element_value = pack_function ( metadata , value ) if isinstance ( element_value , str ) : element = ET . Element ( metadata . tag ) element . text = element_value else : element = element_value if metadata . name is not None : element . attrib [ 'N' ] = metadata . name if parent is not None : parent . append ( element ) return element