示例#1
0
 def get_xml_threaded(self):
     threads=[]
     container=etree.Element('container')
     _get_xml(threads,self,container)
     for t in threads:
         t.join()
     return container[0]
示例#2
0
    def get_xml_element(self, e):
        """Generate xml element from jsonml AttrDict

        Recursively generates xml element from jsonml AttrDict.

        :param e: jsonml AttrDict
        :return: xml element
        """

        # create element
        element = etree.Element(e.tagname)
        # set element attributes
        for attribute, value in sorted(e.attributes.items()):
            # filter 'None' values
            if value is not None:
                value = self.value_to_string(value)
                if value:  # just add not empty attributes
                    element.set(attribute, value)
        # store the last xml sibling, because we may need to add
        # text to it's tail. This is to support the tagged text
        # style ("<tspan>a<tspan>b</tspan>c</tspan>")
        last = None
        for c in e.element_list:
            if isinstance(c, string_types):
                # Strings need special treatment for insertion
                # as those are not elements
                if last is None:
                    # No non-text element seen so far
                    if element.text is None:
                        # No other element seen so far
                        element.text = c
                    else:
                        # Append to other texts
                        element.text += c
                else:
                    # There was an element already
                    if last.tail is None:
                        # No text after that so far
                        last.tail = c
                    else:
                        # Append to other text
                        last.tail += c
            else:
                # Recurse
                last = self.get_xml_element(self.extract_element(c))
                element.append(last)

        return element
示例#3
0
    def get_xml(self):
        """ Get the XML representation as `ElementTree` object.

        :return: XML `ElementTree` of this object and all its subelements

        """
        xml = etree.Element(self.elementname)
        if self.debug:
            self.validator.check_all_svg_attribute_values(self.elementname, self.attribs)
        for attribute, value in self.attribs.items():
            # filter 'None' values
            if value is not None:
                value = self.value_to_string(value)
                if value:  # just add not empty attributes
                    xml.set(attribute, value)

        for element in self.elements:
            xml.append(element.get_xml())
        return xml
示例#4
0
 def __init__(self, xmldata):
     """
     :param xmldata: an xml.etree.ElementTree - Element() object.
     """
     self.xml = etree.Element('metadata')
     self.xml.append(xmldata)
示例#5
0
 def __init__(self, text):
     self.xml = etree.Element(self.elementname)
     self.xml.text = to_unicode(text)
示例#6
0
 def __init__(self, text):
     self.xml = etree.Element(self.elementname)
     self.xml.text = str(text)
示例#7
0
from svgwrite.etree import etree

import copy

from svgwrite.params import Parameter
from svgwrite.utils import AutoID, to_unicode, PYTHON3

from multiprocessing import Process,Queue
from threading import Thread
def _get_xml(threads,self,parent):
        """ Get the XML representation as `ElementTree` object.

        :return: XML `ElementTree` of this object and all its subelements

        """
    xml = etree.Element(self.elementname)
    for attribute, value in self.attribs.items():
        # filter 'None' values
        if value is not None:
            value = self.value_to_string(value)
            if value:  # just add not empty attributes
                xml.set(attribute, value)

    for element in self.elements:
            t=Thread(target=_get_xml,args=(threads,element,xml))
            t=Process(target=_get_xml,args=(threads,element,xml))
            
            threads.append(t)#threadsafety!
            t.start()
    parent.append(xml)#also needs to be threadsafe
class BaseElement(object):