]> granicus.if.org Git - python/commitdiff
The "context" parameter to the ExternalEntityRefParameter exposes internal
authorFred Drake <fdrake@acm.org>
Sat, 23 Dec 2000 22:12:07 +0000 (22:12 +0000)
committerFred Drake <fdrake@acm.org>
Sat, 23 Dec 2000 22:12:07 +0000 (22:12 +0000)
information from the Expat library that is not part of its public API.
Do not print this information as the format of the string may (and will)
change as Expat evolves.

Add additional tests to make sure the ParserCreate() function raises the
right exceptions on illegal parameters.

Lib/test/output/test_pyexpat
Lib/test/test_pyexpat.py

index 6aed69d41e32cdcbfb2b9e828400692d20d6f631..4d9981cbbeb00ac8132c31b43dee238e0d18b13e 100644 (file)
@@ -30,7 +30,7 @@ Character data:
 End of CDATA section
 End element:
        'sub2'
-External entity ref: ('http://www.python.org/namespace=http://www.w3.org/XML/1998/namespace\014external_entity', None, 'entity.file', None)
+External entity ref: (None, 'entity.file', None)
 End element:
        'root'
 PI:
@@ -60,7 +60,7 @@ Character data:
 End of CDATA section
 End element:
        u'sub2'
-External entity ref: (u'http://www.python.org/namespace=http://www.w3.org/XML/1998/namespace\014external_entity', None, u'entity.file', None)
+External entity ref: (None, u'entity.file', None)
 End element:
        u'root'
 PI:
@@ -90,6 +90,15 @@ Character data:
 End of CDATA section
 End element:
        u'sub2'
-External entity ref: (u'http://www.python.org/namespace=http://www.w3.org/XML/1998/namespace\014external_entity', None, u'entity.file', None)
+External entity ref: (None, u'entity.file', None)
 End element:
        u'root'
+
+Testing constructor for proper handling of namespace_separator values:
+Legal values tested o.k.
+Caught expected TypeError:
+ParserCreate, argument 2: expected string or None, int found
+Caught expected ValueError:
+namespace_separator must be one character, omitted, or None
+Caught expected ValueError:
+namespace_separator must be one character, omitted, or None
index fae1849f9233da68f254c00b08db8ccfd3576593..0c400b4d6d1a1bb892d0e1c8837b19bbab787d8c 100644 (file)
@@ -50,7 +50,7 @@ class Outputter:
 
     def ExternalEntityRefHandler(self, *args):
         context, base, sysId, pubId = args
-        print 'External entity ref:', args
+        print 'External entity ref:', args[1:]
         return 1
 
     def DefaultHandler(self, userData):
@@ -150,3 +150,34 @@ except expat.error:
     print '** Line', parser.ErrorLineNumber
     print '** Column', parser.ErrorColumnNumber
     print '** Byte', parser.ErrorByteIndex
+
+
+# Tests that make sure we get errors when the namespace_separator value
+# is illegal, and that we don't for good values:
+print
+print "Testing constructor for proper handling of namespace_separator values:"
+expat.ParserCreate()
+expat.ParserCreate(namespace_separator=None)
+expat.ParserCreate(namespace_separator=' ')
+print "Legal values tested o.k."
+try:
+    expat.ParserCreate(namespace_separator=42)
+except TypeError, e:
+    print "Caught expected TypeError:"
+    print e
+else:
+    print "Failed to catch expected TypeError."
+try:
+    expat.ParserCreate(namespace_separator='too long')
+except ValueError, e:
+    print "Caught expected ValueError:"
+    print e
+else:
+    print "Failed to catch expected ValueError."
+try:
+    expat.ParserCreate(namespace_separator='') # too short
+except ValueError, e:
+    print "Caught expected ValueError:"
+    print e
+else:
+    print "Failed to catch expected ValueError."