1.1 --- a/XSLForms/Fields.py Sun May 08 23:13:39 2005 +0000
1.2 +++ b/XSLForms/Fields.py Sun May 15 19:54:13 2005 +0000
1.3 @@ -369,7 +369,7 @@
1.4 print "Building time", time.time() - t
1.5
1.6 t = time.time()
1.7 - libxml2dom.toStream(documents[args["instance-name"]], stream=open(args["plain-output"], "wb"), encoding="utf-8")
1.8 + documents[args["instance-name"]].toStream(stream=open(args["plain-output"], "wb"), encoding="utf-8")
1.9 print "Prettyprinting time", time.time() - t
1.10
1.11 print "Selectors", repr(fields.get_selectors(items, documents))
2.1 --- a/XSLForms/Output.py Sun May 08 23:13:39 2005 +0000
2.2 +++ b/XSLForms/Output.py Sun May 15 19:54:13 2005 +0000
2.3 @@ -5,8 +5,8 @@
2.4 """
2.5
2.6 import Constants
2.7 -import libxslt
2.8 -import libxml2
2.9 +import libxsltmod, libxml2mod
2.10 +import libxml2dom
2.11
2.12 """
2.13 import libxml2
2.14 @@ -42,8 +42,8 @@
2.15
2.16 l = []
2.17 # Skip attribute reference.
2.18 - if node.type == "attribute":
2.19 - node = node.parent
2.20 + if node.nodeType == node.ATTRIBUTE_NODE:
2.21 + node = node.parentNode
2.22 # Manually insert the attribute name if defined.
2.23 if attribute_ref:
2.24 # A real attribute is referenced.
2.25 @@ -51,21 +51,21 @@
2.26 l.insert(0, name)
2.27 if multivalue:
2.28 l.insert(0, Constants.multi_separator)
2.29 - l.insert(0, node.name)
2.30 - node = node.parent
2.31 + l.insert(0, node.nodeName)
2.32 + node = node.parentNode
2.33 l.insert(0, Constants.path_separator)
2.34 # Otherwise, treat the element name as an attribute name.
2.35 else:
2.36 - l.insert(0, node.name)
2.37 + l.insert(0, node.nodeName)
2.38 l.insert(0, Constants.path_separator)
2.39 - node = node.parent
2.40 + node = node.parentNode
2.41 # Element references.
2.42 - while node is not None and node.type != "document_xml":
2.43 - l.insert(0, str(int(node.xpathEval("count(preceding-sibling::*) + 1"))))
2.44 + while node is not None and node.nodeType != node.DOCUMENT_NODE:
2.45 + l.insert(0, str(int(node.xpath("count(preceding-sibling::*) + 1"))))
2.46 l.insert(0, Constants.pair_separator)
2.47 - l.insert(0, node.name)
2.48 + l.insert(0, node.nodeName)
2.49 l.insert(0, Constants.path_separator)
2.50 - node = node.parent
2.51 + node = node.parentNode
2.52 return "".join(l)
2.53
2.54 def path_to_context(context, attribute_ref, multivalue_name=None):
2.55 @@ -79,11 +79,10 @@
2.56 name.
2.57 """
2.58
2.59 - pctxt = libxslt.xpathParserContext(_obj=context)
2.60 - context = pctxt.context()
2.61 - node = context.contextNode()
2.62 - transform_context = context.transformContext()
2.63 - name_var = transform_context.variableLookup("this-name", None)
2.64 + context = libxml2mod.xmlXPathParserGetContext(context)
2.65 + #context = libxsltmod.xsltXPathGetTransformContext(pctxt)
2.66 + transform_context = libxsltmod.xsltXPathGetTransformContext(context)
2.67 + name_var = libxsltmod.xsltVariableLookup(transform_context, "this-name", None)
2.68 if multivalue_name is not None:
2.69 name = multivalue_name
2.70 multivalue = 1
2.71 @@ -93,44 +92,49 @@
2.72 else:
2.73 name = None
2.74 multivalue = 0
2.75 + node = libxml2dom.Node(libxml2mod.xmlXPathGetContextNode(context))
2.76 return path_to_node(node, attribute_ref, name, multivalue)
2.77
2.78 def this_position(context):
2.79 - return path_to_context(context, 0)
2.80 + r = path_to_context(context, 0)
2.81 + return r.encode("utf-8")
2.82
2.83 def field_name(context):
2.84 - return path_to_context(context, 1)
2.85 + r = path_to_context(context, 1)
2.86 + return r.encode("utf-8")
2.87
2.88 def multi_field_name(context, multivalue_name):
2.89 - return path_to_context(context, 1, multivalue_name)
2.90 + r = path_to_context(context, 1, multivalue_name)
2.91 + return r.encode("utf-8")
2.92
2.93 def new_field(context, name):
2.94 - return path_to_context(context, 0) + "/" + name
2.95 + r = path_to_context(context, 0) + "/" + name
2.96 + return r.encode("utf-8")
2.97
2.98 def other_field_names(context, nodes):
2.99 names = []
2.100 for node in nodes:
2.101 - n = libxml2.xmlNode(node)
2.102 - name = path_to_node(n, 0, None, 0)
2.103 + name = path_to_node(libxml2dom.Node(node), 0, None, 0)
2.104 if name not in names:
2.105 names.append(name)
2.106 - return ",".join(names)
2.107 + r = ",".join(names)
2.108 + return r.encode("utf-8")
2.109
2.110 def other_multi_field_names(context, multivalue_name, nodes):
2.111 names = []
2.112 for node in nodes:
2.113 - n = libxml2.xmlNode(node)
2.114 - name = path_to_node(n, 1, multivalue_name, 1)
2.115 + name = path_to_node(libxml2dom.Node(node), 1, multivalue_name, 1)
2.116 if name not in names:
2.117 names.append(name)
2.118 - return ",".join(names)
2.119 + r = ",".join(names)
2.120 + return r.encode("utf-8")
2.121
2.122 -libxslt.registerExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position)
2.123 -libxslt.registerExtModuleFunction("field-name", "http://www.boddie.org.uk/ns/xmltools/template", field_name)
2.124 -libxslt.registerExtModuleFunction("multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", multi_field_name)
2.125 -libxslt.registerExtModuleFunction("new-field", "http://www.boddie.org.uk/ns/xmltools/template", new_field)
2.126 -libxslt.registerExtModuleFunction("other-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_field_names)
2.127 -libxslt.registerExtModuleFunction("other-multi-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_names)
2.128 +libxsltmod.xsltRegisterExtModuleFunction("this-position", "http://www.boddie.org.uk/ns/xmltools/template", this_position)
2.129 +libxsltmod.xsltRegisterExtModuleFunction("field-name", "http://www.boddie.org.uk/ns/xmltools/template", field_name)
2.130 +libxsltmod.xsltRegisterExtModuleFunction("multi-field-name", "http://www.boddie.org.uk/ns/xmltools/template", multi_field_name)
2.131 +libxsltmod.xsltRegisterExtModuleFunction("new-field", "http://www.boddie.org.uk/ns/xmltools/template", new_field)
2.132 +libxsltmod.xsltRegisterExtModuleFunction("other-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_field_names)
2.133 +libxsltmod.xsltRegisterExtModuleFunction("other-multi-field-names", "http://www.boddie.org.uk/ns/xmltools/template", other_multi_field_names)
2.134
2.135 def get_field_name(field_or_multi_name):
2.136 return field_or_multi_name.split(Constants.multi_separator)[0]
3.1 --- a/XSLOutput.py Sun May 08 23:13:39 2005 +0000
3.2 +++ b/XSLOutput.py Sun May 15 19:54:13 2005 +0000
3.3 @@ -6,7 +6,7 @@
3.4
3.5 # NOTE: Make this use other implementations, too.
3.6
3.7 -import libxslt
3.8 +import libxsltmod
3.9 import libxml2dom
3.10
3.11 class OutputError(Exception):
3.12 @@ -33,7 +33,7 @@
3.13
3.14 self.stylesheets = []
3.15 for filename in filenames:
3.16 - self.stylesheets.append(libxslt.parseStylesheetFile(filename))
3.17 + self.stylesheets.append(libxsltmod.xsltParseStylesheetFile(filename))
3.18
3.19 def __del__(self):
3.20
3.21 @@ -42,7 +42,7 @@
3.22 """
3.23
3.24 for stylesheet in self.stylesheets:
3.25 - stylesheet.freeStylesheet()
3.26 + libxsltmod.xsltFreeStylesheet(stylesheet)
3.27
3.28 def send_output(self, stream, encoding, document):
3.29
3.30 @@ -51,12 +51,10 @@
3.31 the given 'document'.
3.32 """
3.33
3.34 - result = self._get_result(document)
3.35 + result = self.get_result(document)
3.36
3.37 if result is not None:
3.38 - # Since result is a native node, use the serialize method.
3.39 - stream.write(result.serialize(encoding))
3.40 - result.freeDoc()
3.41 + stream.write(result.toString(encoding))
3.42 else:
3.43 raise OutputError, "Transformation failed."
3.44
3.45 @@ -70,7 +68,7 @@
3.46 result = self._get_result(document)
3.47
3.48 if result is not None:
3.49 - return libxml2dom.Node(result)
3.50 + return libxml2dom.adoptNodes([result])[0]
3.51 else:
3.52 raise OutputError, "Transformation failed."
3.53
3.54 @@ -93,10 +91,8 @@
3.55
3.56 last_result = document
3.57 for stylesheet in self.stylesheets:
3.58 - result = stylesheet.applyStylesheet(last_result, parameters)
3.59 + result = libxsltmod.xsltApplyStylesheet(stylesheet, last_result, parameters)
3.60 if last_result is not None:
3.61 - if last_result is not document:
3.62 - last_result.freeDoc()
3.63 last_result = result
3.64 else:
3.65 raise OutputError, "Transformation failed."
4.1 --- a/examples/Common/Configurator/__init__.py Sun May 08 23:13:39 2005 +0000
4.2 +++ b/examples/Common/Configurator/__init__.py Sun May 15 19:54:13 2005 +0000
4.3 @@ -73,7 +73,6 @@
4.4 # Get the XML representation of the request.
4.5
4.6 documents = fields.make_documents(parameters.items())
4.7 - print "*", libxml2dom.toString(documents["configuration"])
4.8 else:
4.9 trans.set_response_code(405)
4.10 raise WebStack.Generic.EndOfResponse
4.11 @@ -84,6 +83,7 @@
4.12 configuration = documents["configuration"]
4.13 else:
4.14 configuration = fields.new_instance("configuration")
4.15 + print "*", configuration.toString()
4.16
4.17 # Add and remove elements according to the selectors found.
4.18
4.19 @@ -100,7 +100,7 @@
4.20
4.21 if parameters.has_key("export"):
4.22 trans.set_content_type(WebStack.Generic.ContentType("text/xml", self.encoding))
4.23 - libxml2dom.toStream(configuration, trans.get_response_stream(), trans.get_response_stream_encoding())
4.24 + configuration.toStream(trans.get_response_stream(), trans.get_response_stream_encoding())
4.25
4.26 # When not exported, the data is transformed to produce a normal Web
4.27 # page.