def parse_stylesheet(self, etree):
        """
        Parses stylesheet from getree
        """

        stylesheet = ""
        stylesheet_elem = etree.find("{%s}stylesheet" % self.namespaces[0])
        if stylesheet_elem != None:
            stylesheet = ElementTree.tostring(stylesheet_elem)
        return stylesheet
def write_element_tempfile(element, tempfile):
    """
    Writes element to temp file
    """
    if element != None and ElementTree.iselement(element):

        try:
            tempfile.write(ElementTree.tostring(element))
        except Exception, e:
            raise exceptions.ConeException(
                'Cannot write Element to file (%s). Exception: %s' %
                (tempfile, e))
def dumps(obj, indent=True):
    etree = ConfmlWriter().dumps(obj)
    if indent:
        persistence.indent(etree)
    result = ElementTree.tostring(etree)
    
    # To make the output the same in linux and windows
    # (needed to make testing easier)
    if os.linesep != '\r\n':
        result = result.replace(os.linesep, '\r\n')
    
    return result
    def post_process_flattening(self, element):
        """
        Pick just data element and build document out of it
        """

        data_element = element.find("data")
        if data_element == None:
            self.logger.warning('No data to generate!!')
            new_doc = "<?xml version=\"1.0\"?><configuration>" + "</configuration>"
        else:
            new_doc = "<?xml version=\"1.0\"?><configuration>" + ElementTree.tostring(
                data_element) + "</configuration>"
        return ElementTree.fromstring(new_doc)
def write_element(element, output, linesep=os.linesep):
    """
    """
    if element != None and ElementTree.iselement(element):
        enc = None

        try:
            out_file = open(output, 'w')
            out_string = ElementTree.tostring(element)
            out_string = out_string.replace('\r\n', linesep)
            out_string = out_string.replace('\n', linesep)
            out_file.write(out_string)
            out_file.close()
        except Exception, e:
            raise exceptions.ConeException(
                'Cannot write Element to file (%s). Exception: %s' %
                (output, e))
def write_element_enc(element, output, enc, linesep=os.linesep):
    """
    Writes element to file
    """
    if element != None and ElementTree.iselement(element):
        enc = None

        try:
            remove_namespace(element, 'http://www.s60.com/xml/genconfml/1')

            out_file = codecs.open(output, 'w', enc)
            output_string = ElementTree.tostring(element)
            output_string = output_string.replace('\r\n', linesep)
            output_string = output_string.replace('\n', linesep)
            out_file.write(output_string)
            out_file.close()
        except Exception, e:
            raise exceptions.ConeException(
                'Cannot write Element to file (%s). Exception: %s' %
                (output, e))