Skip to content

Commit

Permalink
add missing genxmlif lib
Browse files Browse the repository at this point in the history
  • Loading branch information
flixr committed Jan 15, 2016
1 parent 3b0da8a commit 8e29d7c
Show file tree
Hide file tree
Showing 11 changed files with 3,136 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tools/generator/lib/genxmlif/README.txt
@@ -0,0 +1,82 @@
Release Notes for genxmlif, Release 0.9.0

genxmlif is a generic XML interface package
which currently uses minidom, elementtree or 4DOM as XML parser
Other parsers can be adapted by implementing an appropriate interface class

--------------------------------------------------------------------
The genxmlif generic XML interface package is

Copyright (c) 2005-2008 by Roland Leuthe

By obtaining, using, and/or copying this software and/or its
associated documentation, you agree that you have read, understood,
and will comply with the following terms and conditions:

Permission to use, copy, modify, and distribute this software and
its associated documentation for any purpose and without fee is
hereby granted, provided that the above copyright notice appears in
all copies, and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of
the author not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.

THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
ABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.
---------------------------------------------------------------------

Contents
========

README.txt
__init__.py
xmlif4Dom.py
xmlifApi.py
xmlifBase.py
xmlifDom.py
xmlifElementTree.py
xmlifMinidom.py
xmlifODict.py
xmlifUtils.py
xmliftest.py


---------------------------------------------------------------------

HISTORY:
=======

Changes for Release 0.9.0
=========================

- Caution, interface changed!
API changes:
* TreeWrapper and ElementWrapper classes re-designed and renamed
(Now derivation from these classes is possible)
* insertSubtree method moved from TreeWrapper class to ElementWrapper class
* some new public methods added (e.g. removeAttribute)
* print functionality improved
* GenXmlIfError exception introduced (parser and XInclude errors are mapped to this exception class)
* pydoc comments for all API methods added
* caching introduced (for performance optimization)


Changes for Release 0.8
=======================

- Caution, interface changed! Method getXPathList returns now 3 parameters instead of 1 in release 0.7!
- performance optimization (caching, mainly for elementtree interface)
- some bugs fixed


Changes for Release 0.7
=======================

- some special methods for XML schema validation support added
92 changes: 92 additions & 0 deletions tools/generator/lib/genxmlif/__init__.py
@@ -0,0 +1,92 @@
#
# genxmlif, Release 0.9.0
# file: __init__.py
#
# genxmlif package file
#
# history:
# 2005-04-25 rl created
#
# Copyright (c) 2005-2008 by Roland Leuthe. All rights reserved.
#
# --------------------------------------------------------------------
# The generic XML interface is
#
# Copyright (c) 2005-2008 by Roland Leuthe
#
# By obtaining, using, and/or copying this software and/or its
# associated documentation, you agree that you have read, understood,
# and will comply with the following terms and conditions:
#
# Permission to use, copy, modify, and distribute this software and
# its associated documentation for any purpose and without fee is
# hereby granted, provided that the above copyright notice appears in
# all copies, and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of
# the author not be used in advertising or publicity
# pertaining to distribution of the software without specific, written
# prior permission.
#
# THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
# TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
# ABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
# --------------------------------------------------------------------


######################################################################
# PUBLIC DEFINITIONS
######################################################################


# supported XML interfaces

XMLIF_MINIDOM = "XMLIF_MINIDOM"
XMLIF_4DOM = "XMLIF_4DOM"
XMLIF_ELEMENTTREE = "XMLIF_ELEMENTTREE"

# namespace definitions

XINC_NAMESPACE = "http://www.w3.org/2001/XInclude"


# definition of genxmlif path

import os
GENXMLIF_DIR = os.path.dirname(__file__)


########################################
# central function to choose the XML interface to be used
#

def chooseXmlIf (xmlIf, verbose=0, useCaching=1, processXInclude=1):
if xmlIf == XMLIF_MINIDOM:
import xmlifMinidom
return xmlifMinidom.XmlInterfaceMinidom(verbose, useCaching, processXInclude)

elif xmlIf == XMLIF_4DOM:
import xmlif4Dom
return xmlif4Dom.XmlInterface4Dom(verbose, useCaching, processXInclude)

elif xmlIf == XMLIF_ELEMENTTREE:
import xmlifElementTree
return xmlifElementTree.XmlInterfaceElementTree(verbose, useCaching, processXInclude)

else:
raise AttributeError, "Unknown XML interface: %s" %(xmlIf)


########################################
# define own exception for GenXmlIf errors
# The following errors/exceptions are mapped to a GenxmlIf exception:
# - Expat errors
# - XInclude errors
#
class GenXmlIfError (StandardError):
pass

139 changes: 139 additions & 0 deletions tools/generator/lib/genxmlif/xmlif4Dom.py
@@ -0,0 +1,139 @@
#
# genxmlif, Release 0.9.0
# file: xmlif4Dom.py
#
# XML interface class to the 4DOM library
#
# history:
# 2005-04-25 rl created
# 2008-07-01 rl Limited support of XInclude added
#
# Copyright (c) 2005-2008 by Roland Leuthe. All rights reserved.
#
# --------------------------------------------------------------------
# The generix XML interface is
#
# Copyright (c) 2005-2008 by Roland Leuthe
#
# By obtaining, using, and/or copying this software and/or its
# associated documentation, you agree that you have read, understood,
# and will comply with the following terms and conditions:
#
# Permission to use, copy, modify, and distribute this software and
# its associated documentation for any purpose and without fee is
# hereby granted, provided that the above copyright notice appears in
# all copies, and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of
# the author not be used in advertising or publicity
# pertaining to distribution of the software without specific, written
# prior permission.
#
# THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
# TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
# ABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
# --------------------------------------------------------------------

import urllib
from xml.dom.ext.reader.Sax2 import Reader, XmlDomGenerator
from xml.sax._exceptions import SAXParseException
from ..genxmlif import XMLIF_4DOM, GenXmlIfError
from xmlifUtils import convertToAbsUrl
from xmlifDom import XmlInterfaceDom, XmlIfBuilderExtensionDom, InternalDomTreeWrapper, InternalDomElementWrapper


class XmlInterface4Dom (XmlInterfaceDom):
#####################################################
# for description of the interface methods see xmlifbase.py
#####################################################

def __init__ (self, verbose, useCaching, processXInclude):
XmlInterfaceDom.__init__ (self, verbose, useCaching, processXInclude)
self.xmlIfType = XMLIF_4DOM
if self.verbose:
print "Using 4Dom interface module..."


def parse (self, file, baseUrl="", internalOwnerDoc=None):
absUrl = convertToAbsUrl (file, baseUrl)
fp = urllib.urlopen (absUrl)
return self._parseStream (fp, file, absUrl, internalOwnerDoc)


def parseString (self, text, baseUrl="", internalOwnerDoc=None):
import cStringIO
fp = cStringIO.StringIO(text)
absUrl = convertToAbsUrl ("", baseUrl)
return self._parseStream (fp, "", absUrl, internalOwnerDoc)


def _parseStream (self, fp, file, absUrl, internalOwnerDoc):
reader = Reader(validate=0, keepAllWs=0, catName=None,
saxHandlerClass=ExtXmlDomGenerator, parser=None)
reader.handler.extinit(file, absUrl, reader.parser, self)
if internalOwnerDoc != None:
ownerDoc = internalOwnerDoc.document
else:
ownerDoc = None
try:
tree = reader.fromStream(fp, ownerDoc)
fp.close()
except SAXParseException, errInst:
fp.close()
raise GenXmlIfError, "%s: SAXParseException: %s" %(file, str(errInst))

treeWrapper = reader.handler.treeWrapper

# XInclude support
if self.processXInclude:
if internalOwnerDoc == None:
internalOwnerDoc = treeWrapper.getTree()
self.xInclude (treeWrapper.getRootNode(), absUrl, internalOwnerDoc)

return treeWrapper


###################################################
# Extended DOM generator class derived from XmlDomGenerator
# extended to store related line numbers, file/URL names and
# defined namespaces in the node object

class ExtXmlDomGenerator(XmlDomGenerator, XmlIfBuilderExtensionDom):
def __init__(self, keepAllWs=0):
XmlDomGenerator.__init__(self, keepAllWs)
self.treeWrapper = None


def extinit (self, filePath, absUrl, parser, xmlIf):
self.filePath = filePath
self.absUrl = absUrl
self.parser = parser
self.xmlIf = xmlIf


def startElement(self, name, attribs):
XmlDomGenerator.startElement(self, name, attribs)

if not self.treeWrapper:
self.treeWrapper = self.xmlIf.treeWrapperClass(self, InternalDomTreeWrapper(self._rootNode), self.xmlIf.useCaching)
XmlIfBuilderExtensionDom.__init__(self, self.filePath, self.absUrl, self.treeWrapper, self.xmlIf.elementWrapperClass)

curNode = self._nodeStack[-1]
internal4DomElementWrapper = InternalDomElementWrapper(curNode, self.treeWrapper.getTree())
curNs = self._namespaces.items()
try:
curNs.remove( (None,None) )
except:
pass

XmlIfBuilderExtensionDom.startElementHandler (self, internal4DomElementWrapper, self.parser.getLineNumber(), curNs)


def endElement(self, name):
curNode = self._nodeStack[-1]
XmlIfBuilderExtensionDom.endElementHandler (self, curNode.xmlIfExtInternalWrapper, self.parser.getLineNumber())
XmlDomGenerator.endElement(self, name)

0 comments on commit 8e29d7c

Please sign in to comment.