Python xml.dom.minidom.getDOMImplementation() Examples

The following are 30 code examples of xml.dom.minidom.getDOMImplementation(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xml.dom.minidom , or try the search function .
Example #1
Source File: config.py    From pelisalacarta-ce with GNU General Public License v3.0 6 votes vote down vote up
def set_settings(JsonRespuesta):
    for Ajuste in JsonRespuesta:
      settings_dic[Ajuste]=JsonRespuesta[Ajuste].encode("utf8")
    from xml.dom import minidom
    #Crea un Nuevo XML vacio
    new_settings = minidom.getDOMImplementation().createDocument(None, "settings", None)
    new_settings_root = new_settings.documentElement
    
    for key in settings_dic:
      nodo = new_settings.createElement("setting")
      nodo.setAttribute("value",settings_dic[key])
      nodo.setAttribute("id",key)    
      new_settings_root.appendChild(nodo)
      
    fichero = open(configfilepath, "w")
    fichero.write(new_settings.toprettyxml(encoding='utf-8'))
    fichero.close()



# Fichero de configuraciĆ³n 
Example #2
Source File: xmlmanager.py    From aws-extender with MIT License 6 votes vote down vote up
def __init__(self, cls, db_name, db_user, db_passwd,
                 db_host, db_port, db_table, ddl_dir, enable_ssl):
        self.cls = cls
        if not db_name:
            db_name = cls.__name__.lower()
        self.db_name = db_name
        self.db_user = db_user
        self.db_passwd = db_passwd
        self.db_host = db_host
        self.db_port = db_port
        self.db_table = db_table
        self.ddl_dir = ddl_dir
        self.s3 = None
        self.converter = XMLConverter(self)
        self.impl = getDOMImplementation()
        self.doc = self.impl.createDocument(None, 'objects', None)

        self.connection = None
        self.enable_ssl = enable_ssl
        self.auth_header = None
        if self.db_user:
            base64string = encodebytes('%s:%s' % (self.db_user, self.db_passwd))[:-1]
            authheader = "Basic %s" % base64string
            self.auth_header = authheader 
Example #3
Source File: config.py    From addon with GNU General Public License v3.0 6 votes vote down vote up
def set_settings(JsonRespuesta):
    for Ajuste in JsonRespuesta:
        settings_dic[Ajuste] = JsonRespuesta[Ajuste].encode("utf8")
    from xml.dom import minidom
    # Crea un Nuevo XML vacio
    new_settings = minidom.getDOMImplementation().createDocument(None, "settings", None)
    new_settings_root = new_settings.documentElement

    for key in settings_dic:
        nodo = new_settings.createElement("setting")
        nodo.setAttribute("value", settings_dic[key])
        nodo.setAttribute("id", key)
        new_settings_root.appendChild(nodo)

    fichero = open(configfilepath, "w")
    fichero.write(new_settings.toprettyxml(encoding='utf-8'))
    fichero.close()


# Fichero de configuraciĆ³n 
Example #4
Source File: distrib.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def render_GET(self, request):
        """
        Render as HTML a listing of all known users with links to their
        personal resources.
        """

        domImpl = getDOMImplementation()
        newDoc = domImpl.createDocument(None, "ul", None)
        listing = newDoc.documentElement
        for link, text in self._users():
            linkElement = newDoc.createElement('a')
            linkElement.setAttribute('href', link + '/')
            textNode = newDoc.createTextNode(text)
            linkElement.appendChild(textNode)
            item = newDoc.createElement('li')
            item.appendChild(linkElement)
            listing.appendChild(item)

        htmlDoc = self.template % ({'users': listing.toxml()})
        return htmlDoc.encode("utf-8") 
Example #5
Source File: xmlmanager.py    From canvas with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, cls, db_name, db_user, db_passwd,
                 db_host, db_port, db_table, ddl_dir, enable_ssl):
        self.cls = cls
        if not db_name:
            db_name = cls.__name__.lower()
        self.db_name = db_name
        self.db_user = db_user
        self.db_passwd = db_passwd
        self.db_host = db_host
        self.db_port = db_port
        self.db_table = db_table
        self.ddl_dir = ddl_dir
        self.s3 = None
        self.converter = XMLConverter(self)
        self.impl = getDOMImplementation()
        self.doc = self.impl.createDocument(None, 'objects', None)

        self.connection = None
        self.enable_ssl = enable_ssl
        self.auth_header = None
        if self.db_user:
            import base64
            base64string = base64.encodestring('%s:%s' % (self.db_user, self.db_passwd))[:-1]
            authheader =  "Basic %s" % base64string
            self.auth_header = authheader 
Example #6
Source File: test_minidom.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def create_doc_without_doctype(doctype=None):
    return getDOMImplementation().createDocument(None, "doc", doctype) 
Example #7
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def dataToXml(self, data, xmlpath):
        impl = miniDom.getDOMImplementation()
        dom = impl.createDocument(None, u'Remote', None)
        root = dom.documentElement
        commentNode1 = dom.createComment(self.text.xmlComment1)
        dom.insertBefore(commentNode1, root)
        commentNode2 = dom.createComment(self.text.xmlComment2 % str(dt.now())[:19])
        dom.insertBefore(commentNode2, root)
        root.setAttribute(u'Name', unicode(data[0]))
        prefixNode = dom.createElement(u'Prefix')
        prefixText = dom.createTextNode(unicode(data[1]))
        prefixNode.appendChild(prefixText)
        root.appendChild(prefixNode)
        suffixesNode = dom.createElement(u'Suffixes')
        for item in data[2]:
            suffixNode = dom.createElement(u'Suffix')
            natSuffNode = dom.createElement(u'Native_event_suffix')
            natSuffText = dom.createTextNode(unicode(item[0]))
            natSuffNode.appendChild(natSuffText)
            suffixNode.appendChild(natSuffNode)
            labelNode = dom.createElement(u'Button_label')
            labelText = dom.createTextNode(unicode(item[1]))
            labelNode.appendChild(labelText)
            suffixNode.appendChild(labelNode)
            newSuffNode = dom.createElement(u'New_event_suffix')
            newSuffixText = dom.createTextNode(unicode(item[2]))
            newSuffNode.appendChild(newSuffixText)
            suffixNode.appendChild(newSuffNode)
            suffixesNode.appendChild(suffixNode)
        root.appendChild(suffixesNode)
        f = file(xmlpath, 'wb')
        writer = lookup('utf-8')[3](f)
        dom.writexml(writer, encoding = 'utf-8')
        f.close()
#=============================================================================== 
Example #8
Source File: test_minidom.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink() 
Example #9
Source File: test_minidom.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def create_nonempty_doctype():
    doctype = getDOMImplementation().createDocumentType("doc", None, None)
    doctype.entities._seq = []
    doctype.notations._seq = []
    notation = xml.dom.minidom.Notation("my-notation", None,
                                        "http://xml.python.org/notations/my")
    doctype.notations._seq.append(notation)
    entity = xml.dom.minidom.Entity("my-entity", None,
                                    "http://xml.python.org/entities/my",
                                    "my-notation")
    entity.version = "1.0"
    entity.encoding = "utf-8"
    entity.actualEncoding = "us-ascii"
    doctype.entities._seq.append(entity)
    return doctype 
Example #10
Source File: test_minidom.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def create_doc_without_doctype(doctype=None):
    return getDOMImplementation().createDocument(None, "doc", doctype) 
Example #11
Source File: report.py    From dials with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def as_xml(self):
        """
        Save the report as an xml file

        :return: The XML string
        """
        from xml.dom import minidom

        # Get the XML implementation
        impl = minidom.getDOMImplementation()

        # Create the XML document
        doc = impl.createDocument(None, None, None)

        # Create the document root
        root = doc.createElement("DIALS")

        # Function to process objects
        def process(root, obj):
            if isinstance(obj, dict):
                for key, value in obj.items():
                    root.appendChild(process(doc.createElement(key), value))
            elif isinstance(obj, list) or isinstance(obj, tuple):
                for i, value in enumerate(obj):
                    root.appendChild(process(doc.createElement("%d" % i), value))
            else:
                root.appendChild(doc.createTextNode(str(obj)))
            return root

        # Process the dictionary and append
        doc.appendChild(process(root, self.as_dict()))

        # Return the XML document
        return doc.toprettyxml(indent="  ") 
Example #12
Source File: test_minidom.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink() 
Example #13
Source File: test_minidom.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def create_nonempty_doctype():
    doctype = getDOMImplementation().createDocumentType("doc", None, None)
    doctype.entities._seq = []
    doctype.notations._seq = []
    notation = xml.dom.minidom.Notation("my-notation", None,
                                        "http://xml.python.org/notations/my")
    doctype.notations._seq.append(notation)
    entity = xml.dom.minidom.Entity("my-entity", None,
                                    "http://xml.python.org/entities/my",
                                    "my-notation")
    entity.version = "1.0"
    entity.encoding = "utf-8"
    entity.actualEncoding = "us-ascii"
    doctype.entities._seq.append(entity)
    return doctype 
Example #14
Source File: test_minidom.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def create_doc_without_doctype(doctype=None):
    return getDOMImplementation().createDocument(None, "doc", doctype) 
Example #15
Source File: test_minidom.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def create_nonempty_doctype():
    doctype = getDOMImplementation().createDocumentType("doc", None, None)
    doctype.entities._seq = []
    doctype.notations._seq = []
    notation = xml.dom.minidom.Notation("my-notation", None,
                                        "http://xml.python.org/notations/my")
    doctype.notations._seq.append(notation)
    entity = xml.dom.minidom.Entity("my-entity", None,
                                    "http://xml.python.org/entities/my",
                                    "my-notation")
    entity.version = "1.0"
    entity.encoding = "utf-8"
    entity.actualEncoding = "us-ascii"
    doctype.entities._seq.append(entity)
    return doctype 
Example #16
Source File: test_minidom.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink() 
Example #17
Source File: test_minidom.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def create_nonempty_doctype():
    doctype = getDOMImplementation().createDocumentType("doc", None, None)
    doctype.entities._seq = []
    doctype.notations._seq = []
    notation = xml.dom.minidom.Notation("my-notation", None,
                                        "http://xml.python.org/notations/my")
    doctype.notations._seq.append(notation)
    entity = xml.dom.minidom.Entity("my-entity", None,
                                    "http://xml.python.org/entities/my",
                                    "my-notation")
    entity.version = "1.0"
    entity.encoding = "utf-8"
    entity.actualEncoding = "us-ascii"
    doctype.entities._seq.append(entity)
    return doctype 
Example #18
Source File: test_minidom.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def create_doc_without_doctype(doctype=None):
    return getDOMImplementation().createDocument(None, "doc", doctype) 
Example #19
Source File: xml_tests.py    From pyxform with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_original_escape_escapes_more_than_necessary(self):
        """Should fail if the original is updated (the patch can be removed)."""
        text = "' \" & < >"
        expected = "<root>' &quot; &amp; &lt; &gt;</root>".format(text)
        document = getDOMImplementation().createDocument(None, "root", None)
        root = document.documentElement
        text_node = document.createTextNode(text)
        root.appendChild(text_node)
        observed = root.toprettyxml(indent="", newl="")
        self.assertEqual(expected, observed) 
Example #20
Source File: test_minidom.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink() 
Example #21
Source File: test_minidom.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def create_doc_without_doctype(doctype=None):
    return getDOMImplementation().createDocument(None, "doc", doctype) 
Example #22
Source File: test_minidom.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink() 
Example #23
Source File: test_minidom.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def create_nonempty_doctype():
    doctype = getDOMImplementation().createDocumentType("doc", None, None)
    doctype.entities._seq = []
    doctype.notations._seq = []
    notation = xml.dom.minidom.Notation("my-notation", None,
                                        "http://xml.python.org/notations/my")
    doctype.notations._seq.append(notation)
    entity = xml.dom.minidom.Entity("my-entity", None,
                                    "http://xml.python.org/entities/my",
                                    "my-notation")
    entity.version = "1.0"
    entity.encoding = "utf-8"
    entity.actualEncoding = "us-ascii"
    doctype.entities._seq.append(entity)
    return doctype 
Example #24
Source File: test_minidom.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink() 
Example #25
Source File: test_minidom.py    From BinderFilter with MIT License 5 votes vote down vote up
def create_doc_without_doctype(doctype=None):
    return getDOMImplementation().createDocument(None, "doc", doctype) 
Example #26
Source File: test_minidom.py    From BinderFilter with MIT License 5 votes vote down vote up
def create_nonempty_doctype():
    doctype = getDOMImplementation().createDocumentType("doc", None, None)
    doctype.entities._seq = []
    doctype.notations._seq = []
    notation = xml.dom.minidom.Notation("my-notation", None,
                                        "http://xml.python.org/notations/my")
    doctype.notations._seq.append(notation)
    entity = xml.dom.minidom.Entity("my-entity", None,
                                    "http://xml.python.org/entities/my",
                                    "my-notation")
    entity.version = "1.0"
    entity.encoding = "utf-8"
    entity.actualEncoding = "us-ascii"
    doctype.entities._seq.append(entity)
    return doctype 
Example #27
Source File: test_minidom.py    From BinderFilter with MIT License 5 votes vote down vote up
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink() 
Example #28
Source File: test_minidom.py    From oss-ftp with MIT License 5 votes vote down vote up
def create_doc_without_doctype(doctype=None):
    return getDOMImplementation().createDocument(None, "doc", doctype) 
Example #29
Source File: test_minidom.py    From oss-ftp with MIT License 5 votes vote down vote up
def create_nonempty_doctype():
    doctype = getDOMImplementation().createDocumentType("doc", None, None)
    doctype.entities._seq = []
    doctype.notations._seq = []
    notation = xml.dom.minidom.Notation("my-notation", None,
                                        "http://xml.python.org/notations/my")
    doctype.notations._seq.append(notation)
    entity = xml.dom.minidom.Entity("my-entity", None,
                                    "http://xml.python.org/entities/my",
                                    "my-notation")
    entity.version = "1.0"
    entity.encoding = "utf-8"
    entity.actualEncoding = "us-ascii"
    doctype.entities._seq.append(entity)
    return doctype 
Example #30
Source File: test_minidom.py    From oss-ftp with MIT License 5 votes vote down vote up
def testRenameOther(self):
        # We have to create a comment node explicitly since not all DOM
        # builders used with minidom add comments to the DOM.
        doc = xml.dom.minidom.getDOMImplementation().createDocument(
            xml.dom.EMPTY_NAMESPACE, "e", None)
        node = doc.createComment("comment")
        self.assertRaises(xml.dom.NotSupportedErr, doc.renameNode, node,
                          xml.dom.EMPTY_NAMESPACE, "foo")
        doc.unlink()