# HG changeset patch # User paulb # Date 1124380633 0 # Node ID 7011c24f4bb7c5142eda9262846e8df3e2ef383a # Parent 610e3d7331edaa194198d22f004b55a9253e3f25 [project @ 2005-08-18 15:57:13 by paulb] Moved XSLOutput and XMLTable into a new XSLTools package. Renamed the scripts. diff -r 610e3d7331ed -r 7011c24f4bb7 README.txt --- a/README.txt Thu Aug 18 15:56:06 2005 +0000 +++ b/README.txt Thu Aug 18 15:57:13 2005 +0000 @@ -45,10 +45,12 @@ New in XSLTools 0.2 (Changes since XSLTools 0.1) ------------------------------------------------ -Added XMLTable. +Made a new XSLTools package and moved XSLOutput into it. +Added XMLTable (to the XSLTools package). Changed in-page requests to contain proper POST data. Added Debian package support. Added missing COPYING.txt file. +Renamed the scripts to avoid naming issues in system-wide installations. Notes on In-Page Update Functionality ------------------------------------- @@ -132,7 +134,8 @@ Release Procedures ------------------ -Update the XSLOutput.py and XSLForms/__init__.py __version__ attributes. +Update the XSLTools/__init__.py and XSLForms/__init__.py __version__ +attributes. Change the version number and package filename/directory in the documentation. Change code examples in the documentation if appropriate. Update the release notes (see above). diff -r 610e3d7331ed -r 7011c24f4bb7 XMLTable.py --- a/XMLTable.py Thu Aug 18 15:56:06 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -#!/usr/bin/env python - -"A list of tuples to XML document converter." - -import libxml2dom -from UserDict import UserDict - -class OrderedDict(UserDict): - - "A dictionary with keys in the order in which they were given." - - def __init__(self, *args): - UserDict.__init__(self, *args) - self._keys = self.data.keys() - - def __setitem__(self, key, value): - UserDict.__setitem__(self, key, value) - if key not in self._keys: - self._keys.append(key) - - def __delitem__(self, key): - UserDict.__delitem__(self, key) - del self._keys[key] - - def keys(self): - return self._keys - - def items(self): - l = [] - for key in self._keys: - l.append((key, self.data[key])) - return l - - def values(self): - return [value for key, value in self.items()] - -class Converter: - def __init__(self, ns=None, prefix="", doc=None, root=None): - self.ns = ns - self.prefix = prefix - if doc is not None: - self.doc = doc - else: - self.doc = libxml2dom.createDocument(ns, prefix+"table", None) - if root is not None: - self.root = root - else: - self.root = self.doc.xpath("*")[0] - - def add_rows(self, rows): - for row in rows: - self.add_row(row) - - def add_row(self, row, index=-1, row_element_name="row", use_key_as_element_name=0): - row_element = self.doc.createElementNS(self.ns, self.prefix+row_element_name) - if index == -1: - self.root.appendChild(row_element) - else: - self.root.insertBefore(row_element, self.root.xpath("*[%s]" % (index + 1))[0]) - - # Permit dictionaries. - - if hasattr(row, "items"): - for name, value in row.items(): - if use_key_as_element_name: - column_element = self.doc.createElementNS(self.ns, self.prefix+unicode(name)) - else: - column_element = self.doc.createElementNS(self.ns, self.prefix+"column") - column_element.setAttributeNS(self.ns, self.prefix+"name", unicode(name)) - row_element.appendChild(column_element) - text = self.doc.createTextNode(unicode(value)) - column_element.appendChild(text) - - # As well as sequences. - - else: - for column in row: - column_element = self.doc.createElementNS(self.ns, self.prefix+"column") - row_element.appendChild(column_element) - text = self.doc.createTextNode(unicode(column)) - column_element.appendChild(text) - -if __name__ == "__main__": - from rdflib.TripleStore import TripleStore - import sys - s = TripleStore() - s.load(sys.argv[1]) - converter = Converter() - converter.add_rows(s.triples((None, None, None))) - libxml2dom.toStream(converter.doc, sys.stdout) - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 610e3d7331ed -r 7011c24f4bb7 XSLOutput.py --- a/XSLOutput.py Thu Aug 18 15:56:06 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -#!/usr/bin/env python - -""" -XSL output classes and functions. - -Copyright (C) 2005 Paul Boddie - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library 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 -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -""" - -__version__ = "0.2" - -# NOTE: Make this use other implementations, too. - -import libxsltmod -import libxml2dom - -class OutputError(Exception): - pass - -class Processor: - - """ - A handler which can prepare output for an XMLTools2 template. - """ - - def __init__(self, filenames, references=None, parameters=None): - - """ - Initialise the handler with the 'filenames' of stylesheets producing the - final output, a 'references' dictionary indicating related stylesheets. - Additional 'parameters' may also be specified as a dictionary. - """ - - self.references = references or {} - self.parameters = parameters or {} - - # Remember the stylesheet documents. - - self.stylesheets = [] - for filename in filenames: - doc = libxml2dom.macrolib.parseFile(filename) - self.stylesheets.append(libxsltmod.xsltParseStylesheetDoc(doc)) - - def __del__(self): - - """ - Tidy up the stylesheet documents. - """ - - for stylesheet in self.stylesheets: - libxsltmod.xsltFreeStylesheet(stylesheet) - - def send_output(self, stream, encoding, document): - - """ - Send output to the given 'stream' using the given output encoding for - the given 'document'. - """ - - result = self.get_result(document) - - if result is not None: - stream.write(result.toString(encoding)) - else: - raise OutputError, "Transformation failed." - - def get_result(self, document): - - """ - Return a transformed document produced from the object's stylesheets and - the given 'document'. - """ - - result = self._get_result(document) - - if result is not None: - return libxml2dom.adoptNodes([result])[0] - else: - raise OutputError, "Transformation failed." - - def _get_result(self, document): - - """ - Return a transformation of the given 'document'. - """ - - if hasattr(document, "as_native_node"): - document = document.as_native_node() - - # Transform the localised instance into the final output. - - parameters = {} - for name, reference in self.references.items(): - parameters[name.encode("utf-8")] = ("document('%s')" % self._quote(reference)).encode("utf-8") - for name, parameter in self.parameters.items(): - parameters[name.encode("utf-8")] = ("'%s'" % self._quote(parameter)).encode("utf-8") - #print "**", repr(parameters) - - last_result = document - for stylesheet in self.stylesheets: - result = libxsltmod.xsltApplyStylesheet(stylesheet, last_result, parameters) - if last_result is not None: - last_result = result - else: - raise OutputError, "Transformation failed." - - return result - - def _quote(self, s): - - "Make the given parameter string 's' palatable for libxslt." - - return s.replace("'", "%27") - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 610e3d7331ed -r 7011c24f4bb7 setup.py --- a/setup.py Thu Aug 18 15:56:06 2005 +0000 +++ b/setup.py Thu Aug 18 15:57:13 2005 +0000 @@ -11,8 +11,7 @@ author_email = "paul@boddie.org.uk", url = "http://www.boddie.org.uk/python/XSLTools.html", version = XSLForms.__version__, - packages = ["XSLForms"], - py_modules = ["XMLTable", "XSLOutput"], + packages = ["XSLForms", "XSLTools"], package_data = {"XSLForms" : ["XSL/*.xsl"]}, - scripts = ["scripts/extract.py", "scripts/output.py", "scripts/prepare.py"] + scripts = ["scripts/xslform_extract.py", "scripts/xslform_output.py", "scripts/xslform_prepare.py"] )