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:
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:
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
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):
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."