summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmerten <smerten@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-11-16 13:28:27 +0000
committersmerten <smerten@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-11-16 13:28:27 +0000
commitc30948c3cf01caa70300099c39a2a40aaa2ea74a (patch)
tree5d3c89d5a5c6ba8cc9a3778b69256b249723c164
parentb4f817c8fb346e8689f29307cf0c032706d5fe7a (diff)
downloaddocutils-c30948c3cf01caa70300099c39a2a40aaa2ea74a.tar.gz
Code uses docutils_xml.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@7728 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--sandbox/odf2docutils/global.log76
-rw-r--r--sandbox/odf2docutils/odf2docutils.rst65
-rw-r--r--sandbox/odf2docutils/odf2docutilslib/parsers/__init__.py0
-rw-r--r--sandbox/odf2docutils/odf2docutilslib/parsers/xml.py318
-rw-r--r--sandbox/odf2docutils/odf2docutilslib/parsers/xslt.py92
-rw-r--r--sandbox/odf2docutils/odf2docutilslib/python.py2
-rw-r--r--sandbox/odf2docutils/odf2docutilslib/writers/__init__.py0
-rw-r--r--sandbox/odf2docutils/odf2docutilslib/writers/xslt.py58
-rw-r--r--sandbox/odf2docutils/odf2docutilslib/xslt.py4
-rwxr-xr-xsandbox/odf2docutils/setup.py2
-rw-r--r--sandbox/odf2docutils/tag.log2
-rw-r--r--sandbox/odf2docutils/version.py2
12 files changed, 147 insertions, 474 deletions
diff --git a/sandbox/odf2docutils/global.log b/sandbox/odf2docutils/global.log
index 8174ba159..98ff6bcf6 100644
--- a/sandbox/odf2docutils/global.log
+++ b/sandbox/odf2docutils/global.log
@@ -1,4 +1,80 @@
**************************************
+Date: Sat Nov 16 14:21:30 CET 2013
+Author: stefan
+Tag: odf2docutils_1_107
+
+--------------------------------------
+Update of /home/stefan/vault/sm/odf2docutils
+In directory eskebo:/home/stefan/free/odf2docutils
+
+Modified Files:
+ setup.py
+
+--------------------------------------
+Log Message:
+Debgging.
+**************************************
+Date: Sat Nov 16 14:01:06 CET 2013
+Author: stefan
+Tag: odf2docutils_1_106
+
+--------------------------------------
+Update of /home/stefan/vault/sm/odf2docutils/odf2docutilslib
+In directory eskebo:/home/stefan/free/odf2docutils/odf2docutilslib
+
+Modified Files:
+ python.py xslt.py
+
+--------------------------------------
+Update of /home/stefan/vault/sm/odf2docutils/odf2docutilslib/parsers
+In directory eskebo:/home/stefan/free/odf2docutils/odf2docutilslib/parsers
+
+Removed Files:
+ __init__.py xml.py xslt.py
+
+--------------------------------------
+Update of /home/stefan/vault/sm/odf2docutils/odf2docutilslib/writers
+In directory eskebo:/home/stefan/free/odf2docutils/odf2docutilslib/writers
+
+Removed Files:
+ __init__.py xslt.py
+
+--------------------------------------
+Log Message:
+Removed sources now obtained from package `docutils_xml`.
+**************************************
+Date: Sat Nov 16 13:32:56 CET 2013
+Author: stefan
+Tag: odf2docutils_1_105
+
+--------------------------------------
+Update of /home/stefan/vault/sm/odf2docutils
+In directory eskebo:/home/stefan/free/odf2docutils
+
+Modified Files:
+ Makefile
+
+--------------------------------------
+Log Message:
+Debugging.
+**************************************
+Date: Sat Nov 16 13:29:47 CET 2013
+Author: stefan
+Tag: odf2docutils_1_104
+
+--------------------------------------
+Update of /home/stefan/vault/sm/odf2docutils
+In directory eskebo:/home/stefan/free/odf2docutils
+
+Modified Files:
+ .cvsignore Makefile
+Added Files:
+ odf2docutils.rst
+
+--------------------------------------
+Log Message:
+Added documentation the reStructuredText way.
+**************************************
Date: Mon Nov 11 13:32:40 CET 2013
Author: stefan
Tag: odf2docutils_1_103
diff --git a/sandbox/odf2docutils/odf2docutils.rst b/sandbox/odf2docutils/odf2docutils.rst
new file mode 100644
index 000000000..bda44d4ae
--- /dev/null
+++ b/sandbox/odf2docutils/odf2docutils.rst
@@ -0,0 +1,65 @@
+============
+odf2docutils
+============
+
+------------------------------------
+convert an ODF input to Docutils XML
+------------------------------------
+
+:Author: smerten@oekonux.de
+:Copyright: GPL v2
+:Manual section: 1
+:Manual group: text processing
+
+SYNOPSIS
+========
+
+**odf2docutils.py** [*options*\]... [*odf* [*docutils*\]]
+
+DESCRIPTION
+===========
+
+Converts an `Open Document Format`_ (ODF) file to Docutils XML.
+Docutils XML can then be converted to reStructuredText by using
+xml2rst_.
+
+OPTIONS
+=======
+
+.. include:: docutilsOptions.rst
+
+SEE ALSO
+========
+
+.. _Docutils:
+
+* Docutils
+
+ http://docutils.sourceforge.net/
+
+.. _reStructuredText:
+
+* reStructuredText
+
+ http://docutils.sourceforge.net/rst.html
+
+.. _ODF:
+
+* _`Open Document Format`
+
+ https://www.oasis-open.org/standards#opendocumentv1.2
+
+* _`xml2rst`
+
+ http://svn.code.sf.net/p/docutils/code/trunk/sandbox/xml2rst/
+
+AVAILABILITY
+============
+
+**odf2docutils** is available from
+
+http://www.merten-home.de/FreeSoftware/odf2docutils/
+
+and the Docutils sandbox
+
+http://svn.code.sf.net/p/docutils/code/trunk/sandbox/odf2docutils
diff --git a/sandbox/odf2docutils/odf2docutilslib/parsers/__init__.py b/sandbox/odf2docutils/odf2docutilslib/parsers/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/sandbox/odf2docutils/odf2docutilslib/parsers/__init__.py
+++ /dev/null
diff --git a/sandbox/odf2docutils/odf2docutilslib/parsers/xml.py b/sandbox/odf2docutils/odf2docutilslib/parsers/xml.py
deleted file mode 100644
index 1de562a40..000000000
--- a/sandbox/odf2docutils/odf2docutilslib/parsers/xml.py
+++ /dev/null
@@ -1,318 +0,0 @@
-# Copyright (C) 2013 Stefan Merten
-
-# This file is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published
-# by the Free Software Foundation; either version 2 of the License,
-# or (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
-
-"""
-Base classes for parsing XML and transform it to a Docutils document.
-"""
-
-__docformat__ = 'reStructuredText' # Formatted to be rendered by epydoc
-
-###############################################################################
-###############################################################################
-# Import
-
-import docutils.parsers, docutils.nodes
-
-from lxml import etree
-
-###############################################################################
-###############################################################################
-# Constants
-
-###############################################################################
-###############################################################################
-# Variables
-
-###############################################################################
-###############################################################################
-# Functions
-
-###############################################################################
-###############################################################################
-# Classes
-
-class SomeChildren(docutils.nodes.TreePruningException):
- """
- Thrown to process only some children of the given node.
-
- Resembles ::
-
- <xsl:apply-templates
- select="..."/>
- """
-
- def __init__(self, tags):
- """
- :Parameters:
-
- tags : ( ( str | unicode, str | unicode ), ... )
- See `tags`.
-
- """
- self.tags = [ ( unicode(prefix), unicode(tag) )
- for ( prefix, tag ) in tags ]
- """
- :type: ( ( unicode, unicode ), ... )
-
- List of children tags to process. A tag is given as a pair of namespace
- prefix and local name.
- """
-
-###############################################################################
-
-class XmlVisitor(object):
- """
- Base visitor class for visiting an XML tree.
-
- See `event_prefix_tag` for a description of the methods in this visitor.
- """
-
- def event_prefix_tag(self, elem):
- """
- Dummy method for documentation.
-
- Vistor methods are named *event*\_\ *prefix*\_\ *tag* where *event* is
- either ``visit`` or ``depart``, *prefix* is the namespace prefix and
- *tag* is the local name of the tag with hyphens removed.
-
- :Parameters:
-
- elem : etree._Element
- The element to process.
-
- :except docutils.nodes.TreePruningException:
- Thrown to control the behavior of the caller.
-
- Note that are more subclasses defined here.
-
- :rtype: void
-
- """
- raise NotImplementedError("'event_prefix_tag' is just for documentation")
-
- def __init__(self, parser, document):
- """
- See instance attributes for a description of the parameters.
- """
- self.parser = parser
- """
- :type: XmlParser
-
- The parser using this visitor.
- """
- self.document = document
- """
- :type: docutils.nodes.document
-
- The target document.
- """
- self.stack = [ document ]
- """
- :type: [ docutils.nodes.Node, ... ]
-
- The stack of current nodes. The last one is the most recent current
- node and the first one is the document itself.
- """
-
- def _applyMethod(self, elem, event):
- """
- Find and apply method.
-
- :Parameters:
-
- elem : lxml.etree._Element
- The element to apply the method to.
-
- event : str
- The event to apply.
- """
- ( prefix, name ) = self.parser.elem2PrefixName(elem)
- if prefix is None:
- prefix = ""
- prefix = prefix.replace("-", "")
- name = name.replace("-", "")
- methodName = "_".join(( event, prefix, name ))
- try:
- method = getattr(self, methodName)
- except AttributeError:
- method = getattr(self, "".join(( event, "Default" )))
- return method(elem)
-
- def visit(self, elem):
- """
- Visit an element.
-
- :Parameters:
-
- elem : lxml.etree._Element
- The element to visit.
- """
- self._applyMethod(elem, 'visit')
-
- def depart(self, elem):
- """
- Depart an element.
-
- :Parameters:
-
- elem : lxml.etree._Element
- The element to depart.
- """
- self._applyMethod(elem, 'depart')
-
- def visitDefault(self, elem):
- """
- Used for elements without specific visit method. Does nothing.
-
- May be overridden in subclasses.
- """
- pass
-
- def departDefault(self, elem):
- """
- Used for elements without specific depart method. Does nothing.
-
- May be overridden in subclasses.
- """
- pass
-
- def push(self, node):
- """
- Add a node to the current node and make it the current node.
-
- :Parameters:
-
- node : docutils.nodes.Node
- The new node to be made current.
-
- :return: The former current node which is now the parent.
- :rtype: docutils.nodes.Node
- """
- parent = self.stack[-1]
- assert isinstance(parent, docutils.nodes.Element), \
- "Can not push to '%s'" % ( type(parent), )
- parent.append(node)
- self.stack.append(node)
- return parent
-
- def pop(self):
- """
- Remove current node and make its parent the new current node.
-
- :return: The former current node which is now a child of the current
- node.
- :rtype: docutils.nodes.Node
- """
- return self.stack.pop()
-
-###############################################################################
-
-class XmlParser(docutils.parsers.Parser):
- """
- A generic XML parser for parsing XML input populating the Docutils doctree.
- """
-
- ns2Prefix = { }
- """
- :type: { unicode: unicode, ... }
-
- Map namespace URI to namespace tag name. Usually overridden in subclasses.
- """
-
- visitorClass = XmlVisitor
- """
- :type: class
-
- The visitor class to use. Must be a subclass of `XmlVisitor`.
-
- This is the essential thing to override in subclasses. All the logic on how
- to parse and transform an XML document is in the visitor.
- """
-
- def parse(self, inputstring, document):
- self.setup_parse(inputstring, document)
- # This is a global setting in etree which is problematic because it is
- # shared. However, this should work since it is overridden every time
- # before it is used.
- [ etree.register_namespace(prefix, uri)
- for ( uri, prefix ) in self.ns2Prefix.items() ]
- inDoc = etree.fromstring(inputstring)
- self.walk(inDoc, self.visitorClass(self, document))
- self.finish_parse()
-
- def walk(self, elem, visitor):
- """
- Traverse the element tree and create the result.
-
- :Parameters:
-
- elem : etree._Element
- The root element of the part of the input document to be traversed.
-
- visitor : XmlVisitor
- The visitor to use.
-
- :return: ``True`` if the traversal should be stopped.
- :rtype: bool
- """
- stop = False
- skipDeparture = False
- someChildren = None
- try:
- try:
- visitor.visit(elem)
- except docutils.nodes.SkipNode:
- return stop
- except docutils.nodes.SkipDeparture:
- skipDeparture = True
- except SomeChildren, e:
- someChildren = e.tags
- try:
- for child in elem:
- if (someChildren is not None
- and self.elem2PrefixName(child) not in someChildren):
- continue
- if self.walk(child, visitor):
- stop = True
- break
- except docutils.nodes.SkipSiblings:
- pass
- except docutils.nodes.SkipChildren:
- pass
- except docutils.nodes.StopTraversal:
- stop = True
- if not skipDeparture:
- visitor.depart(elem)
- return stop
-
- def elem2PrefixName(self, elem):
- """
- :Parameters:
-
- elem : etree._Element
- The element to work for.
-
- :rtype: ( unicode | None, unicode )
- :return: Namespace prefix and localname of `elem`. Namespace prefix
- may be ``None`` if no or unknown namespace.
- """
- qName = etree.QName(elem)
- prefix = None
- # elem.prefix would also work for lxml but using the namespace is saver
- if qName.namespace:
- prefix = self.ns2Prefix.get(qName.namespace, None)
- return ( prefix, qName.localname )
diff --git a/sandbox/odf2docutils/odf2docutilslib/parsers/xslt.py b/sandbox/odf2docutils/odf2docutilslib/parsers/xslt.py
deleted file mode 100644
index 4b2799fec..000000000
--- a/sandbox/odf2docutils/odf2docutilslib/parsers/xslt.py
+++ /dev/null
@@ -1,92 +0,0 @@
-# Copyright (C) 2013 Stefan Merten
-
-# This file is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published
-# by the Free Software Foundation; either version 2 of the License,
-# or (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
-
-"""
-Parse and produce result string by XSLT.
-"""
-
-__docformat__ = 'reStructuredText' # Formatted to be rendered by epydoc
-
-###############################################################################
-###############################################################################
-# Import
-
-import docutils.parsers
-
-from lxml import etree
-
-###############################################################################
-###############################################################################
-# Constants
-
-###############################################################################
-###############################################################################
-# Variables
-
-###############################################################################
-###############################################################################
-# Functions
-
-###############################################################################
-###############################################################################
-# Classes
-
-class XsltParser(docutils.parsers.Parser):
- """
- Parses XML input by XSLT and stores the result in the attribute
- `xslt_result` of the document. Works together with `XsltWriter`.
- """
-
- def __init__(self, xsltPath):
- """
- See instance variables for parameter documentation.
- """
- self.xsltPath = xsltPath
- """
- Path to the XSLT to use.
- """
- self.xslt = None
- """
- :type: Return type of `etree.XSLT`()
-
- The XSLT to use for parsing.
- """
-
- # Find XSLT
- try:
- xsltF = open(self.xsltPath)
- except IOError, e:
- raise Exception("Can't open main XSLT file %r: %s"
- % ( self.xsltPath, e, ))
-
- # Parse and prepare XSLT
- try:
- xsltDoc = etree.parse(xsltF)
- except Exception, e:
- raise Exception("Error parsing main XSLT file %r: %s"
- % ( self.xsltPath, e, ))
- xsltF.close()
- self.xslt = etree.XSLT(xsltDoc)
-
- def parse(self, inputstring, document):
- self.setup_parse(inputstring, document)
- inDoc = etree.fromstring(inputstring)
- document.xslt_result = self.xslt(inDoc, sourceName="'%s'"
- % ( document.current_source, ))
- if self.xslt.error_log:
- document.reporter.error(self.xslt.error_log)
- self.finish_parse()
diff --git a/sandbox/odf2docutils/odf2docutilslib/python.py b/sandbox/odf2docutils/odf2docutilslib/python.py
index 53ca419ff..39bd7ce7e 100644
--- a/sandbox/odf2docutils/odf2docutilslib/python.py
+++ b/sandbox/odf2docutils/odf2docutilslib/python.py
@@ -27,7 +27,7 @@ __docformat__ = 'reStructuredText' # Formatted to be rendered by epydoc
import docutils.nodes
-from parsers.xml import XmlParser, XmlVisitor
+from docutils_xml.parsers.xml import XmlParser, XmlVisitor, SomeChildren
###############################################################################
###############################################################################
diff --git a/sandbox/odf2docutils/odf2docutilslib/writers/__init__.py b/sandbox/odf2docutils/odf2docutilslib/writers/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/sandbox/odf2docutils/odf2docutilslib/writers/__init__.py
+++ /dev/null
diff --git a/sandbox/odf2docutils/odf2docutilslib/writers/xslt.py b/sandbox/odf2docutils/odf2docutilslib/writers/xslt.py
deleted file mode 100644
index 5758951b1..000000000
--- a/sandbox/odf2docutils/odf2docutilslib/writers/xslt.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# Copyright (C) 2013 Stefan Merten
-
-# This file is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published
-# by the Free Software Foundation; either version 2 of the License,
-# or (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
-
-"""
-Support writer for `XsltParser`.
-"""
-
-__docformat__ = 'reStructuredText' # Formatted to be rendered by epydoc
-
-###############################################################################
-###############################################################################
-# Import
-
-import docutils.writers
-
-###############################################################################
-###############################################################################
-# Constants
-
-###############################################################################
-###############################################################################
-# Variables
-
-###############################################################################
-###############################################################################
-# Functions
-
-###############################################################################
-###############################################################################
-# Classes
-
-###############################################################################
-
-class XsltWriter(docutils.writers.Writer):
- """
- Writer transparently writing the result from an `XsltParser`. May be used
- only together with `XsltParser`.
-
- Please note that `supported` must be set in subclass since the output
- format is determined by the XSLT.
- """
-
- def translate(self):
- self.output = str(self.document.xslt_result)
diff --git a/sandbox/odf2docutils/odf2docutilslib/xslt.py b/sandbox/odf2docutils/odf2docutilslib/xslt.py
index a70df444b..3a7ec5606 100644
--- a/sandbox/odf2docutils/odf2docutilslib/xslt.py
+++ b/sandbox/odf2docutils/odf2docutilslib/xslt.py
@@ -27,8 +27,8 @@ __docformat__ = 'reStructuredText' # Formatted to be rendered by epydoc
import os.path
-from parsers.xslt import XsltParser
-from writers.xslt import XsltWriter
+from docutils_xml.parsers.xslt import XsltParser
+from docutils_xml.writers.xslt import XsltWriter
###############################################################################
###############################################################################
diff --git a/sandbox/odf2docutils/setup.py b/sandbox/odf2docutils/setup.py
index c28a93e04..461382559 100755
--- a/sandbox/odf2docutils/setup.py
+++ b/sandbox/odf2docutils/setup.py
@@ -11,7 +11,7 @@ setup(name='odf2docutils',
author_email='smerten@oekonux.de',
url='http://docutils.sourceforge.net/sandbox/odf2docutils/',
license='GPL 2',
- requires=[ 'lxml' ],
+ requires=[ 'lxml', 'docutils_xml' ],
scripts=[ 'odf2docutils.py' ],
packages=[ 'odf2docutilslib' ],
package_data={ 'odf2docutilslib': [ 'odf2docutils.xsl' ], },
diff --git a/sandbox/odf2docutils/tag.log b/sandbox/odf2docutils/tag.log
index 493ca7393..6a9cc6c39 100644
--- a/sandbox/odf2docutils/tag.log
+++ b/sandbox/odf2docutils/tag.log
@@ -1 +1 @@
-odf2docutils_1_103
+odf2docutils_1_107
diff --git a/sandbox/odf2docutils/version.py b/sandbox/odf2docutils/version.py
index 20ab5a90c..e6956dc2b 100644
--- a/sandbox/odf2docutils/version.py
+++ b/sandbox/odf2docutils/version.py
@@ -1 +1 @@
-version = '1.0.1'
+version = '1.1'