def object2xml(self, data):
        r"""Convert python object to xml string.

        :param data: data for build xml. If don't provide the ``root`` option, type of ``data`` must be dict and ``len(data) == 1``.
        :rtype: str or unicode

        .. versionadded:: 1.2
        """
        if not self.__options['encoding']:
            self.set_options(encoding=self.__encoding)

        if self.__options['header_declare']:
            self.__tree.append(self.build_xml_header())

        root = self.__options['root']
        if not root:
            assert (isinstance(data, utils.DictTypes) and len(data) == 1), \
                'if root not specified, the data that dict object and length must be one required.'
            root, data = data.items()[0]

        self.build_tree(data, root)
        xml = unicode(''.join(self.__tree).strip())

        if self.__options['encoding'] != self.__encoding:
            xml = xml.encode(self.__options['encoding'], errors=self.__options['errors'])
        return xml
def object2xml ( self , data ) : if not self . __options [ 'encoding' ] : self . set_options ( encoding = self . __encoding ) if self . __options [ 'header_declare' ] : self . __tree . append ( self . build_xml_header ( ) ) root = self . __options [ 'root' ] if not root : assert ( isinstance ( data , utils . DictTypes ) and len ( data ) == 1 ) , 'if root not specified, the data that dict object and length must be one required.' root , data = data . items ( ) [ 0 ] self . build_tree ( data , root ) xml = unicode ( '' . join ( self . __tree ) . strip ( ) ) if self . __options [ 'encoding' ] != self . __encoding : xml = xml . encode ( self . __options [ 'encoding' ] , errors = self . __options [ 'errors' ] ) return xml
r"""Convert python object to xml string.

        :param data: data for build xml. If don't provide the ``root`` option, type of ``data`` must be dict and ``len(data) == 1``.
        :rtype: str or unicode

        .. versionadded:: 1.2