1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

changed the generator to provide casing for the XmlTextReader similar to

* python/generator.py python/libxml2class.txt
  python/tests/reader.py python/tests/reader2.py: changed the
  generator to provide casing for the XmlTextReader similar to
  C# so that examples and documentation are more directly transposable.
  Fixed the couple of tests in the suite.
Daniel
This commit is contained in:
Daniel Veillard
2002-12-28 21:14:18 +00:00
parent 6943a4db3e
commit aba976d825
5 changed files with 113 additions and 106 deletions

View File

@ -1,3 +1,11 @@
Sat Dec 28 22:11:57 CET 2002 Daniel Veillard <daniel@veillard.com>
* python/generator.py python/libxml2class.txt
python/tests/reader.py python/tests/reader2.py: changed the
generator to provide casing for the XmlTextReader similar to
C# so that examples and documentation are more directly transposable.
Fixed the couple of tests in the suite.
Sat Dec 28 15:55:32 CET 2002 Daniel Veillard <daniel@veillard.com> Sat Dec 28 15:55:32 CET 2002 Daniel Veillard <daniel@veillard.com>
* doc/guidelines.html: added a document on guildeline for * doc/guidelines.html: added a document on guildeline for

View File

@ -681,7 +681,6 @@ def nameFixup(name, classe, type, file):
func = "regexp" + name[6:] func = "regexp" + name[6:]
elif name[0:13] == "xmlTextReader" and file == "xmlreader": elif name[0:13] == "xmlTextReader" and file == "xmlreader":
func = name[13:] func = name[13:]
func = string.lower(func[0:1]) + func[1:]
elif name[0:11] == "xmlACatalog": elif name[0:11] == "xmlACatalog":
func = name[11:] func = name[11:]
func = string.lower(func[0:1]) + func[1:] func = string.lower(func[0:1]) + func[1:]

View File

@ -562,43 +562,43 @@ Class xmlAttr(xmlNode)
Class xmlTextReader() Class xmlTextReader()
# functions from module xmlreader # functions from module xmlreader
attributeCount() AttributeCount()
baseUri() BaseUri()
close() Close()
depth() Depth()
GetAttribute()
GetAttributeNo()
GetAttributeNs()
GetParserProp()
GetRemainder()
HasAttributes()
HasValue()
IsDefault()
IsEmptyElement()
LocalName()
LookupNamespace()
MoveToAttribute()
MoveToAttributeNo()
MoveToAttributeNs()
MoveToElement()
MoveToFirstAttribute()
MoveToNextAttribute()
Name()
NamespaceUri()
NodeType()
Normalization()
Prefix()
QuoteChar()
Read()
ReadAttributeValue()
ReadInnerXml()
ReadOuterXml()
ReadState()
ReadString()
SetParserProp()
Value()
XmlLang()
freeTextReader() freeTextReader()
getAttribute()
getAttributeNo()
getAttributeNs()
getParserProp()
getRemainder()
hasAttributes()
hasValue()
isDefault()
isEmptyElement()
localName()
lookupNamespace()
moveToAttribute()
moveToAttributeNo()
moveToAttributeNs()
moveToElement()
moveToFirstAttribute()
moveToNextAttribute()
name()
namespaceUri()
nodeType()
normalization()
prefix()
quoteChar()
read()
readAttributeValue()
readInnerXml()
readOuterXml()
readState()
readString()
setParserProp()
value()
xmlLang()
Class xmlReg() Class xmlReg()
# functions from module xmlregexp # functions from module xmlregexp

View File

@ -9,56 +9,56 @@ libxml2.debugMemory(1)
f = StringIO.StringIO("""<a><b b1="b1"/><c>content of c</c></a>""") f = StringIO.StringIO("""<a><b b1="b1"/><c>content of c</c></a>""")
input = libxml2.inputBuffer(f) input = libxml2.inputBuffer(f)
reader = input.newTextReader("test1") reader = input.newTextReader("test1")
ret = reader.read() ret = reader.Read()
if ret != 1: if ret != 1:
print "Error reading to first element" print "Error reading to first element"
sys.exit(1) sys.exit(1)
if reader.name() != "a" or reader.isEmptyElement() != 0 or \ if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \
reader.nodeType() != 1 or reader.hasAttributes() != 0: reader.NodeType() != 1 or reader.HasAttributes() != 0:
print "Error reading the first element" print "Error reading the first element"
sys.exit(1) sys.exit(1)
ret = reader.read() ret = reader.Read()
if ret != 1: if ret != 1:
print "Error reading to second element" print "Error reading to second element"
sys.exit(1) sys.exit(1)
if reader.name() != "b" or reader.isEmptyElement() != 1 or \ if reader.Name() != "b" or reader.IsEmptyElement() != 1 or \
reader.nodeType() != 1 or reader.hasAttributes() != 1: reader.NodeType() != 1 or reader.HasAttributes() != 1:
print "Error reading the second element" print "Error reading the second element"
sys.exit(1) sys.exit(1)
ret = reader.read() ret = reader.Read()
if ret != 1: if ret != 1:
print "Error reading to third element" print "Error reading to third element"
sys.exit(1) sys.exit(1)
if reader.name() != "c" or reader.isEmptyElement() != 0 or \ if reader.Name() != "c" or reader.IsEmptyElement() != 0 or \
reader.nodeType() != 1 or reader.hasAttributes() != 0: reader.NodeType() != 1 or reader.HasAttributes() != 0:
print "Error reading the third element" print "Error reading the third element"
sys.exit(1) sys.exit(1)
ret = reader.read() ret = reader.Read()
if ret != 1: if ret != 1:
print "Error reading to text node" print "Error reading to text node"
sys.exit(1) sys.exit(1)
if reader.name() != "#text" or reader.isEmptyElement() != 0 or \ if reader.Name() != "#text" or reader.IsEmptyElement() != 0 or \
reader.nodeType() != 3 or reader.hasAttributes() != 0 or \ reader.NodeType() != 3 or reader.HasAttributes() != 0 or \
reader.value() != "content of c": reader.Value() != "content of c":
print "Error reading the text node" print "Error reading the text node"
sys.exit(1) sys.exit(1)
ret = reader.read() ret = reader.Read()
if ret != 1: if ret != 1:
print "Error reading to end of third element" print "Error reading to end of third element"
sys.exit(1) sys.exit(1)
if reader.name() != "c" or reader.isEmptyElement() != 0 or \ if reader.Name() != "c" or reader.IsEmptyElement() != 0 or \
reader.nodeType() != 15 or reader.hasAttributes() != 0: reader.NodeType() != 15 or reader.HasAttributes() != 0:
print "Error reading the end of third element" print "Error reading the end of third element"
sys.exit(1) sys.exit(1)
ret = reader.read() ret = reader.Read()
if ret != 1: if ret != 1:
print "Error reading to end of first element" print "Error reading to end of first element"
sys.exit(1) sys.exit(1)
if reader.name() != "a" or reader.isEmptyElement() != 0 or \ if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \
reader.nodeType() != 15 or reader.hasAttributes() != 0: reader.NodeType() != 15 or reader.HasAttributes() != 0:
print "Error reading the end of first element" print "Error reading the end of first element"
sys.exit(1) sys.exit(1)
ret = reader.read() ret = reader.Read()
if ret != 0: if ret != 0:
print "Error reading to end of document" print "Error reading to end of document"
sys.exit(1) sys.exit(1)
@ -70,14 +70,14 @@ f = StringIO.StringIO("""<test xmlns:dt="urn:datatypes" dt:type="int"/>""")
input = libxml2.inputBuffer(f) input = libxml2.inputBuffer(f)
reader = input.newTextReader("test2") reader = input.newTextReader("test2")
ret = reader.read() ret = reader.Read()
if ret != 1: if ret != 1:
print "Error reading test element" print "Error reading test element"
sys.exit(1) sys.exit(1)
if reader.getAttributeNo(0) != "urn:datatypes" or \ if reader.GetAttributeNo(0) != "urn:datatypes" or \
reader.getAttributeNo(1) != "int" or \ reader.GetAttributeNo(1) != "int" or \
reader.getAttributeNs("type", "urn:datatypes") != "int" or \ reader.GetAttributeNs("type", "urn:datatypes") != "int" or \
reader.getAttribute("dt:type") != "int": reader.GetAttribute("dt:type") != "int":
print "error reading test attributes" print "error reading test attributes"
sys.exit(1) sys.exit(1)
@ -92,14 +92,14 @@ f = StringIO.StringIO("""<root xmlns:a="urn:456">
input = libxml2.inputBuffer(f) input = libxml2.inputBuffer(f)
reader = input.newTextReader("test3") reader = input.newTextReader("test3")
ret = reader.read() ret = reader.Read()
while ret == 1: while ret == 1:
if reader.name() == "ref": if reader.Name() == "ref":
if reader.lookupNamespace("a") != "urn:456": if reader.LookupNamespace("a") != "urn:456":
print "error resolving namespace prefix" print "error resolving namespace prefix"
sys.exit(1) sys.exit(1)
break break
ret = reader.read() ret = reader.Read()
if ret != 1: if ret != 1:
print "Error finding the ref element" print "Error finding the ref element"
sys.exit(1) sys.exit(1)
@ -110,125 +110,125 @@ if ret != 1:
f = StringIO.StringIO("""<testattr xmlns="urn:1" xmlns:a="urn:2" b="b" a:b="a:b"/>""") f = StringIO.StringIO("""<testattr xmlns="urn:1" xmlns:a="urn:2" b="b" a:b="a:b"/>""")
input = libxml2.inputBuffer(f) input = libxml2.inputBuffer(f)
reader = input.newTextReader("test4") reader = input.newTextReader("test4")
ret = reader.read() ret = reader.Read()
if ret != 1: if ret != 1:
print "Error reading the testattr element" print "Error reading the testattr element"
sys.exit(1) sys.exit(1)
# #
# Attribute exploration by index # Attribute exploration by index
# #
if reader.moveToAttributeNo(0) != 1: if reader.MoveToAttributeNo(0) != 1:
print "Failed moveToAttribute(0)" print "Failed moveToAttribute(0)"
sys.exit(1) sys.exit(1)
if reader.value() != "urn:1": if reader.Value() != "urn:1":
print "Failed to read attribute(0)" print "Failed to read attribute(0)"
sys.exit(1) sys.exit(1)
if reader.name() != "xmlns": if reader.Name() != "xmlns":
print "Failed to read attribute(0) name" print "Failed to read attribute(0) name"
sys.exit(1) sys.exit(1)
if reader.moveToAttributeNo(1) != 1: if reader.MoveToAttributeNo(1) != 1:
print "Failed moveToAttribute(1)" print "Failed moveToAttribute(1)"
sys.exit(1) sys.exit(1)
if reader.value() != "urn:2": if reader.Value() != "urn:2":
print "Failed to read attribute(1)" print "Failed to read attribute(1)"
sys.exit(1) sys.exit(1)
if reader.name() != "xmlns:a": if reader.Name() != "xmlns:a":
print "Failed to read attribute(1) name" print "Failed to read attribute(1) name"
sys.exit(1) sys.exit(1)
if reader.moveToAttributeNo(2) != 1: if reader.MoveToAttributeNo(2) != 1:
print "Failed moveToAttribute(2)" print "Failed moveToAttribute(2)"
sys.exit(1) sys.exit(1)
if reader.value() != "b": if reader.Value() != "b":
print "Failed to read attribute(2)" print "Failed to read attribute(2)"
sys.exit(1) sys.exit(1)
if reader.name() != "b": if reader.Name() != "b":
print "Failed to read attribute(2) name" print "Failed to read attribute(2) name"
sys.exit(1) sys.exit(1)
if reader.moveToAttributeNo(3) != 1: if reader.MoveToAttributeNo(3) != 1:
print "Failed moveToAttribute(3)" print "Failed moveToAttribute(3)"
sys.exit(1) sys.exit(1)
if reader.value() != "a:b": if reader.Value() != "a:b":
print "Failed to read attribute(3)" print "Failed to read attribute(3)"
sys.exit(1) sys.exit(1)
if reader.name() != "a:b": if reader.Name() != "a:b":
print "Failed to read attribute(3) name" print "Failed to read attribute(3) name"
sys.exit(1) sys.exit(1)
# #
# Attribute exploration by name # Attribute exploration by name
# #
if reader.moveToAttribute("xmlns") != 1: if reader.MoveToAttribute("xmlns") != 1:
print "Failed moveToAttribute('xmlns')" print "Failed moveToAttribute('xmlns')"
sys.exit(1) sys.exit(1)
if reader.value() != "urn:1": if reader.Value() != "urn:1":
print "Failed to read attribute('xmlns')" print "Failed to read attribute('xmlns')"
sys.exit(1) sys.exit(1)
if reader.moveToAttribute("xmlns:a") != 1: if reader.MoveToAttribute("xmlns:a") != 1:
print "Failed moveToAttribute('xmlns')" print "Failed moveToAttribute('xmlns')"
sys.exit(1) sys.exit(1)
if reader.value() != "urn:2": if reader.Value() != "urn:2":
print "Failed to read attribute('xmlns:a')" print "Failed to read attribute('xmlns:a')"
sys.exit(1) sys.exit(1)
if reader.moveToAttribute("b") != 1: if reader.MoveToAttribute("b") != 1:
print "Failed moveToAttribute('b')" print "Failed moveToAttribute('b')"
sys.exit(1) sys.exit(1)
if reader.value() != "b": if reader.Value() != "b":
print "Failed to read attribute('b')" print "Failed to read attribute('b')"
sys.exit(1) sys.exit(1)
if reader.moveToAttribute("a:b") != 1: if reader.MoveToAttribute("a:b") != 1:
print "Failed moveToAttribute('a:b')" print "Failed moveToAttribute('a:b')"
sys.exit(1) sys.exit(1)
if reader.value() != "a:b": if reader.Value() != "a:b":
print "Failed to read attribute('a:b')" print "Failed to read attribute('a:b')"
sys.exit(1) sys.exit(1)
if reader.moveToAttributeNs("b", "urn:2") != 1: if reader.MoveToAttributeNs("b", "urn:2") != 1:
print "Failed moveToAttribute('b', 'urn:2')" print "Failed moveToAttribute('b', 'urn:2')"
sys.exit(1) sys.exit(1)
if reader.value() != "a:b": if reader.Value() != "a:b":
print "Failed to read attribute('b', 'urn:2')" print "Failed to read attribute('b', 'urn:2')"
sys.exit(1) sys.exit(1)
# #
# Go back and read in sequence # Go back and read in sequence
# #
if reader.moveToElement() != 1: if reader.MoveToElement() != 1:
print "Failed to move back to element" print "Failed to move back to element"
sys.exit(1) sys.exit(1)
if reader.moveToFirstAttribute() != 1: if reader.MoveToFirstAttribute() != 1:
print "Failed to move to first attribute" print "Failed to move to first attribute"
sys.exit(1) sys.exit(1)
if reader.value() != "urn:1": if reader.Value() != "urn:1":
print "Failed to read attribute(0)" print "Failed to read attribute(0)"
sys.exit(1) sys.exit(1)
if reader.name() != "xmlns": if reader.Name() != "xmlns":
print "Failed to read attribute(0) name" print "Failed to read attribute(0) name"
sys.exit(1) sys.exit(1)
if reader.moveToNextAttribute() != 1: if reader.MoveToNextAttribute() != 1:
print "Failed to move to next attribute" print "Failed to move to next attribute"
sys.exit(1) sys.exit(1)
if reader.value() != "urn:2": if reader.Value() != "urn:2":
print "Failed to read attribute(1)" print "Failed to read attribute(1)"
sys.exit(1) sys.exit(1)
if reader.name() != "xmlns:a": if reader.Name() != "xmlns:a":
print "Failed to read attribute(1) name" print "Failed to read attribute(1) name"
sys.exit(1) sys.exit(1)
if reader.moveToNextAttribute() != 1: if reader.MoveToNextAttribute() != 1:
print "Failed to move to next attribute" print "Failed to move to next attribute"
sys.exit(1) sys.exit(1)
if reader.value() != "b": if reader.Value() != "b":
print "Failed to read attribute(2)" print "Failed to read attribute(2)"
sys.exit(1) sys.exit(1)
if reader.name() != "b": if reader.Name() != "b":
print "Failed to read attribute(2) name" print "Failed to read attribute(2) name"
sys.exit(1) sys.exit(1)
if reader.moveToNextAttribute() != 1: if reader.MoveToNextAttribute() != 1:
print "Failed to move to next attribute" print "Failed to move to next attribute"
sys.exit(1) sys.exit(1)
if reader.value() != "a:b": if reader.Value() != "a:b":
print "Failed to read attribute(3)" print "Failed to read attribute(3)"
sys.exit(1) sys.exit(1)
if reader.name() != "a:b": if reader.Name() != "a:b":
print "Failed to read attribute(3) name" print "Failed to read attribute(3) name"
sys.exit(1) sys.exit(1)
if reader.moveToNextAttribute() != 0: if reader.MoveToNextAttribute() != 0:
print "Failed to detect last attribute" print "Failed to detect last attribute"
sys.exit(1) sys.exit(1)

View File

@ -32,10 +32,10 @@ for file in valid_files:
continue continue
reader = libxml2.newTextReaderFilename(file) reader = libxml2.newTextReaderFilename(file)
#print "%s:" % (file) #print "%s:" % (file)
reader.setParserProp(libxml2.PARSER_VALIDATE, 1) reader.SetParserProp(libxml2.PARSER_VALIDATE, 1)
ret = reader.read() ret = reader.Read()
while ret == 1: while ret == 1:
ret = reader.read() ret = reader.Read()
if ret != 0: if ret != 0:
print "Error parsing and validating %s" % (file) print "Error parsing and validating %s" % (file)
#sys.exit(1) #sys.exit(1)