PATCH: Correct system ID for generated XML
Mark Mitchell
mark at codesourcery.com
Mon Sep 15 20:35:22 UTC 2003
The system ids in the generated XML documents for QMTest were
incorrect. This patch redirects them to a stable URL.
--
Mark Mitchell
CodeSourcery, LLC
mark at codesourcery.com
2003-09-15 Mark Mitchell <mark at codesourcery.com>
* qm/extension.py (make_dom_document): Simplify.
* qm/user.py (XmlDatabase.Write): Likewise.
* qm/xmlutil.py (make_system_id): Use CodeSourcery URLs.
(make_public_id): New function.
(create_dom_document): Compute full system and public identifiers
here.
* qm/test/base.py (dtds): Remove.
* qm/test/cmdline.py (QMTest.__ExecuteCreateTarget): Adjust call
to create_dom_document.
(QMTest.__ExecuteRegister): Likewise.
* qm/test/classes/xml_database.py: Likewise.
* qm/test/classes/xml_result_stream.py: Likewise.
* qm/test/share/dtds/class-directory.dtd: Tidy.
* qm/test/share/dtds/result.dtd: Likewise.
Index: qm/extension.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/extension.py,v
retrieving revision 1.12
diff -c -5 -p -r1.12 extension.py
*** qm/extension.py 3 Jul 2003 19:32:04 -0000 1.12
--- qm/extension.py 15 Sep 2003 20:05:02 -0000
*************** def make_dom_document(extension_class, a
*** 312,324 ****
returns -- A new DOM document corresponding to an instance of the
extension class."""
document = qm.xmlutil.create_dom_document(
! public_id=qm.test.base.dtds["extension"],
! dtd_file_name="extension",
! document_element_tag="extension"
)
make_dom_element(extension_class, arguments, document,
document.documentElement)
return document
--- 312,323 ----
returns -- A new DOM document corresponding to an instance of the
extension class."""
document = qm.xmlutil.create_dom_document(
! public_id = "Extension",
! document_element_tag = "extension"
)
make_dom_element(extension_class, arguments, document,
document.documentElement)
return document
Index: qm/user.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/user.py,v
retrieving revision 1.10
diff -c -5 -p -r1.10 user.py
*** qm/user.py 11 Oct 2002 20:23:24 -0000 1.10
--- qm/user.py 15 Sep 2003 20:05:02 -0000
*************** class XmlDatabase:
*** 387,398 ****
def Write(self):
"""Write out the user database."""
# Create a DOM document for the database.
document = xmlutil.create_dom_document(
! public_id=xml_user_database_dtd,
! dtd_file_name="user.dtd",
document_element_tag="users"
)
document_element = document.documentElement
# Create elements for users in the database.
for user in self.__users.values():
--- 387,397 ----
def Write(self):
"""Write out the user database."""
# Create a DOM document for the database.
document = xmlutil.create_dom_document(
! public_id = "User",
document_element_tag="users"
)
document_element = document.documentElement
# Create elements for users in the database.
for user in self.__users.values():
Index: qm/xmlutil.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/xmlutil.py,v
retrieving revision 1.21
diff -c -5 -p -r1.21 xmlutil.py
*** qm/xmlutil.py 18 Jun 2003 17:14:01 -0000 1.21
--- qm/xmlutil.py 15 Sep 2003 20:05:02 -0000
*************** import xml.dom.minidom
*** 25,38 ****
########################################################################
# functions
########################################################################
def make_system_id(name):
! """Construct a system ID for the file 'name'."""
! return "http://www.software-carpentry.com/qm/xml/%s" % name
def load_xml_file(path):
"""Return a DOM document loaded from the XML file 'path'."""
--- 25,52 ----
########################################################################
# functions
########################################################################
+ def make_public_id(name):
+ """Return a public ID for the DTD with the given 'name'.
+
+ 'name' -- The name of the DTD.
+
+ returns -- A public ID for the DTD."""
+
+ return "-//QM/%s/%s//EN" % (qm.version, name)
+
+
def make_system_id(name):
! """Return a system ID for the DTD with the given 'name'.
!
! 'name' -- The name of the DTD, as a relative UNIX path.
!
! returns -- A URL for the DTD."""
! return "http://www.codesourcery.com/qm/dtds/%s/%s" % (qm.version, name)
def load_xml_file(path):
"""Return a DOM document loaded from the XML file 'path'."""
*************** def create_dom_text_element(document, ta
*** 174,208 ****
return element
__dom_implementation = xml.dom.minidom.getDOMImplementation()
! def create_dom_document(public_id, dtd_file_name, document_element_tag):
"""Create a DOM document.
! 'public_id' -- The public ID of the DTD to use for this document.
!
! 'dtd_file_name' -- The name of the DTD file for this document.
'document_element_tag' -- The tag of the main document element.
returns -- A DOM document node."""
! system_id = make_system_id(dtd_file_name)
# Create the document type for the XML document.
document_type = __dom_implementation.createDocumentType(
qualifiedName=document_element_tag,
publicId=public_id,
systemId=system_id
)
# Create a new DOM document.
! return __dom_implementation.createDocument(
! namespaceURI=None,
! qualifiedName=document_element_tag,
! doctype=document_type
! )
!
__hyphen_regex = re.compile("(--+)")
def __hyphen_replacement(match):
return "-" + " -" * (len(match.group(0)) - 1)
--- 188,221 ----
return element
__dom_implementation = xml.dom.minidom.getDOMImplementation()
! def create_dom_document(public_id, document_element_tag):
"""Create a DOM document.
! 'public_id' -- The (partial) public ID for the DTD.
'document_element_tag' -- The tag of the main document element.
returns -- A DOM document node."""
! public_id = make_public_id(public_id)
! system_id = make_system_id(public_id.lower() + ".dtd")
# Create the document type for the XML document.
document_type = __dom_implementation.createDocumentType(
qualifiedName=document_element_tag,
publicId=public_id,
systemId=system_id
)
# Create a new DOM document.
! document = __dom_implementation.\
! createDocument(namespaceURI=None,
! qualifiedName=document_element_tag,
! doctype=document_type)
! return document
!
__hyphen_regex = re.compile("(--+)")
def __hyphen_replacement(match):
return "-" + " -" * (len(match.group(0)) - 1)
Index: qm/test/base.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/base.py,v
retrieving revision 1.90
diff -c -5 -p -r1.90 base.py
*** qm/test/base.py 27 Aug 2003 16:17:57 -0000 1.90
--- qm/test/base.py 15 Sep 2003 20:05:03 -0000
*************** import string
*** 32,62 ****
import sys
import tempfile
import types
########################################################################
- # constants
- ########################################################################
-
- dtds = {
- "class-directory":
- "-//Software Carpentry//QMTest Class Directory V0.1//EN",
- "extension": "-//Software Carpentry//QMTest Extension V0.1//EN",
- "tdb-configuration":
- "-//Software Carpentry//QMTest TDB Configuration V0.1//EN",
- "resource": "-//Software Carpentry//QMTest Resource V0.1//EN",
- "result": "-//Software Carpentry//QMTest Result V0.3//EN",
- "suite": "-//Software Carpentry//QMTest Suite V0.1//EN",
- "target": "-//Software Carpentry//QMTest Target V0.1//EN",
- "test": "-//Software Carpentry//QMTest Test V0.1//EN",
- }
- """A mapping for DTDs used by QMTest.
-
- Keys are DTD types ("resource", "result", etc). Values are the
- corresponding DTD public identifiers."""
-
- ########################################################################
# Exceptions
########################################################################
class CouldNotLoadExtensionError(QMException):
"""An exception indicating that an extension class could not be loaded."""
--- 32,41 ----
Index: qm/test/cmdline.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/cmdline.py,v
retrieving revision 1.97
diff -c -5 -p -r1.97 cmdline.py
*** qm/test/cmdline.py 15 Sep 2003 05:13:17 -0000 1.97
--- qm/test/cmdline.py 15 Sep 2003 20:05:03 -0000
*************** Valid formats are "full", "brief" (the d
*** 976,987 ****
for duplicate in duplicates:
targets_element.removeChild(duplicate)
duplicate.unlink()
else:
document = (qm.xmlutil.create_dom_document
! (public_id = dtds["target"],
! dtd_file_name = "target.dtd",
document_element_tag = "targets"))
targets_element = document.documentElement
# Get the attributes.
attributes = self.__GetAttributeOptions()
--- 976,986 ----
for duplicate in duplicates:
targets_element.removeChild(duplicate)
duplicate.unlink()
else:
document = (qm.xmlutil.create_dom_document
! (public_id = "QMTest/Target",
document_element_tag = "targets"))
targets_element = document.documentElement
# Get the attributes.
attributes = self.__GetAttributeOptions()
*************** Valid formats are "full", "brief" (the d
*** 1120,1131 ****
classes_file_name = os.path.join(directory, "classes.qmc")
try:
document = qm.xmlutil.load_xml_file(classes_file_name)
except:
document = (qm.xmlutil.create_dom_document
! (public_id=qm.test.base.dtds["class-directory"],
! dtd_file_name="class-directory.dtd",
document_element_tag="class-directory"))
# Remove any previous entries for this class.
duplicates = []
for element in qm.xmlutil.get_children(document.documentElement,
--- 1119,1129 ----
classes_file_name = os.path.join(directory, "classes.qmc")
try:
document = qm.xmlutil.load_xml_file(classes_file_name)
except:
document = (qm.xmlutil.create_dom_document
! (public_id = "Class-Directory",
document_element_tag="class-directory"))
# Remove any previous entries for this class.
duplicates = []
for element in qm.xmlutil.get_children(document.documentElement,
Index: qm/test/classes/xml_database.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/classes/xml_database.py,v
retrieving revision 1.15
diff -c -5 -p -r1.15 xml_database.py
*** qm/test/classes/xml_database.py 7 Aug 2003 17:05:20 -0000 1.15
--- qm/test/classes/xml_database.py 15 Sep 2003 20:05:03 -0000
*************** class XMLDatabase(ExtensionDatabase):
*** 117,128 ****
# Don't write directory suites to suite file.
assert not suite.IsImplicit()
# Generate the document and document type for XML suite files.
document = qm.xmlutil.create_dom_document(
! public_id=qm.test.base.dtds["suite"],
! dtd_file_name="suite.dtd",
document_element_tag="suite"
)
# Construct the suite element node by adding children for test
# IDs and suite IDs. Use the raw test and suite IDs, i.e. don't
# expand suites to their contained tests.
--- 117,127 ----
# Don't write directory suites to suite file.
assert not suite.IsImplicit()
# Generate the document and document type for XML suite files.
document = qm.xmlutil.create_dom_document(
! public_id="QMTest/Suite",
document_element_tag="suite"
)
# Construct the suite element node by adding children for test
# IDs and suite IDs. Use the raw test and suite IDs, i.e. don't
# expand suites to their contained tests.
Index: qm/test/classes/xml_result_stream.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/classes/xml_result_stream.py,v
retrieving revision 1.3
diff -c -5 -p -r1.3 xml_result_stream.py
*** qm/test/classes/xml_result_stream.py 3 Jul 2003 19:32:04 -0000 1.3
--- qm/test/classes/xml_result_stream.py 15 Sep 2003 20:05:03 -0000
*************** class XMLResultStream(FileResultStream):
*** 41,58 ****
super(XMLResultStream, self).__init__(arguments)
# Create an XML document, since the DOM API requires you
# to have a document when you create a node.
self.__document = qm.xmlutil.create_dom_document(
! public_id=qm.test.base.dtds["result"],
! dtd_file_name="result.dtd",
document_element_tag="results")
# Write out the prologue.
self.file.write("<?xml version='1.0' encoding='ISO-8859-1'?>\n")
self.file.write('<!DOCTYPE results PUBLIC "%s" "%s">\n'
! % (qm.test.base.dtds["result"],
! qm.xmlutil.make_system_id("result.dtd")))
# Begin the list of results.
self.file.write("<results>\n")
def WriteAnnotation(self, key, value):
--- 41,57 ----
super(XMLResultStream, self).__init__(arguments)
# Create an XML document, since the DOM API requires you
# to have a document when you create a node.
self.__document = qm.xmlutil.create_dom_document(
! public_id="QMTest/Result",
document_element_tag="results")
# Write out the prologue.
self.file.write("<?xml version='1.0' encoding='ISO-8859-1'?>\n")
self.file.write('<!DOCTYPE results PUBLIC "%s" "%s">\n'
! % (qm.xmlutil.make_public_id("QMTest/Result"),
! qm.xmlutil.make_system_id("qmtest/result.dtd")))
# Begin the list of results.
self.file.write("<results>\n")
def WriteAnnotation(self, key, value):
Index: qm/test/share/dtds/class-directory.dtd
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/share/dtds/class-directory.dtd,v
retrieving revision 1.3
diff -c -5 -p -r1.3 class-directory.dtd
*** qm/test/share/dtds/class-directory.dtd 13 Jun 2002 17:30:31 -0000 1.3
--- qm/test/share/dtds/class-directory.dtd 15 Sep 2003 20:05:03 -0000
***************
*** 5,28 ****
Date: 2001-10-09
Contents:
DTD for class directory files.
! Copyright (C) 2001, 2002 CodeSourcery LLC. All rights reserved.
For license terms see the file COPYING.
-->
! <!-- NAME: QMTest Class Directory V0.1 -->
<!-- A class directory. -->
<!ELEMENT class-directory (class*)>
<!-- A class. -->
<!ELEMENT class (#PCDATA)>
! <!ATTLIST class kind (database | file | resource | target | test) #REQUIRED>
<!--
Local Variables:
mode: xml
indent-tabs-mode: nil
--- 5,28 ----
Date: 2001-10-09
Contents:
DTD for class directory files.
! Copyright (C) 2001, 2002, 2003 CodeSourcery LLC. All rights reserved.
For license terms see the file COPYING.
-->
! <!-- NAME: QMTest Class Directory -->
<!-- A class directory. -->
<!ELEMENT class-directory (class*)>
<!-- A class. -->
<!ELEMENT class (#PCDATA)>
! <!ATTLIST class kind CDATA #REQUIRED>
<!--
Local Variables:
mode: xml
indent-tabs-mode: nil
Index: qm/test/share/dtds/result.dtd
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/share/dtds/result.dtd,v
retrieving revision 1.3
diff -c -5 -p -r1.3 result.dtd
*** qm/test/share/dtds/result.dtd 28 May 2002 01:37:55 -0000 1.3
--- qm/test/share/dtds/result.dtd 15 Sep 2003 20:05:03 -0000
***************
*** 3,31 ****
File: results.dtd
Author: Alex Samuel
Date: 2001-03-14
Contents:
! DTD for test result sets.
! Copyright (C) 2001, 2002 CodeSourcery LLC. All rights reserved.
For license terms see the file COPYING.
-->
! <!-- NAME: QMTest Result V0.3 -->
<!-- The results of a test run. -->
! <!ELEMENT results (result*)>
! <!-- The result of executing a single test or resource function. -->
<!ELEMENT result (outcome, property*)>
<!ATTLIST result id CDATA #REQUIRED
kind (test | resource) #REQUIRED>
! <!-- The outcome of a test or resource function. -->
<!ELEMENT outcome (#PCDATA)>
<!-- An additional annotation to the result. -->
<!ELEMENT property (#PCDATA)>
<!ATTLIST property name CDATA #REQUIRED>
--- 3,35 ----
File: results.dtd
Author: Alex Samuel
Date: 2001-03-14
Contents:
! DTD for result files.
! Copyright (C) 2001, 2002, 2003 CodeSourcery LLC. All rights reserved.
For license terms see the file COPYING.
-->
! <!-- NAME: QMTest Result -->
<!-- The results of a test run. -->
! <!ELEMENT results (result | annotation)*>
! <!-- Meta-data about the test run. -->
! <!ELEMENT annotation (#PCDATA)>
! <!ATTLIST annotation key CDATA #REQUIRED>
!
! <!-- The result of executing a test or resource. -->
<!ELEMENT result (outcome, property*)>
<!ATTLIST result id CDATA #REQUIRED
kind (test | resource) #REQUIRED>
! <!-- The outcome of a test or resource. -->
<!ELEMENT outcome (#PCDATA)>
<!-- An additional annotation to the result. -->
<!ELEMENT property (#PCDATA)>
<!ATTLIST property name CDATA #REQUIRED>
More information about the qmtest
mailing list