[Python-checkins] CVS: python/dist/src/Lib xmllib.py,1.23,1.24
Sjoerd Mullender
python-dev@python.org
Wed, 6 Dec 2000 02:38:00 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv19399
Modified Files:
xmllib.py
Log Message:
Two changes:
- Use new Error class (subclass of RuntimeError so is backward
compatible) which is raised when RuntimeError used to be raised.
- Report original attribute name in error messages instead of name
mangled with namespace URL.
Index: xmllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xmllib.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** xmllib.py 2000/08/31 10:26:52 1.23
--- xmllib.py 2000/12/06 10:37:57 1.24
***************
*** 9,12 ****
--- 9,15 ----
version = '0.3'
+ class Error(RuntimeError):
+ pass
+
# Regular expressions used for parsing
***************
*** 310,314 ****
'standalone')
if version[1:-1] != '1.0':
! raise RuntimeError, 'only XML version 1.0 supported'
if encoding: encoding = encoding[1:-1]
if standalone: standalone = standalone[1:-1]
--- 313,317 ----
'standalone')
if version[1:-1] != '1.0':
! raise Error('only XML version 1.0 supported')
if encoding: encoding = encoding[1:-1]
if standalone: standalone = standalone[1:-1]
***************
*** 391,395 ****
continue
else:
! raise RuntimeError, 'neither < nor & ??'
# We get here only if incomplete matches but
# nothing else
--- 394,398 ----
continue
else:
! raise Error('neither < nor & ??')
# We get here only if incomplete matches but
# nothing else
***************
*** 420,424 ****
rawdata = self.rawdata
if rawdata[i:i+4] <> '<!--':
! raise RuntimeError, 'unexpected call to handle_comment'
res = commentclose.search(rawdata, i+4)
if res is None:
--- 423,427 ----
rawdata = self.rawdata
if rawdata[i:i+4] <> '<!--':
! raise Error('unexpected call to handle_comment')
res = commentclose.search(rawdata, i+4)
if res is None:
***************
*** 486,490 ****
rawdata = self.rawdata
if rawdata[i:i+9] <> '<![CDATA[':
! raise RuntimeError, 'unexpected call to parse_cdata'
res = cdataclose.search(rawdata, i+9)
if res is None:
--- 489,493 ----
rawdata = self.rawdata
if rawdata[i:i+9] <> '<![CDATA[':
! raise Error('unexpected call to parse_cdata')
res = cdataclose.search(rawdata, i+9)
if res is None:
***************
*** 510,514 ****
res = tagfind.match(rawdata, i+2)
if res is None:
! raise RuntimeError, 'unexpected call to parse_proc'
k = res.end(0)
name = res.group(0)
--- 513,517 ----
res = tagfind.match(rawdata, i+2)
if res is None:
! raise Error('unexpected call to parse_proc')
k = res.end(0)
name = res.group(0)
***************
*** 623,629 ****
--- 626,636 ----
self.stack[-1] = tagname, nsdict, nstag
# translate namespace of attributes
+ attrnamemap = {} # map from new name to old name (used for error reporting)
+ for key in attrdict.keys():
+ attrnamemap[key] = key
if self.__use_namespaces:
nattrdict = {}
for key, val in attrdict.items():
+ okey = key
res = qname.match(key)
if res is not None:
***************
*** 646,649 ****
--- 653,657 ----
key = ns + ' ' + key
nattrdict[key] = val
+ attrnamemap[key] = okey
attrdict = nattrdict
attributes = self.attributes.get(nstag)
***************
*** 651,655 ****
for key in attrdict.keys():
if not attributes.has_key(key):
! self.syntax_error("unknown attribute `%s' in tag `%s'" % (key, tagname))
for key, val in attributes.items():
if val is not None and not attrdict.has_key(key):
--- 659,663 ----
for key in attrdict.keys():
if not attributes.has_key(key):
! self.syntax_error("unknown attribute `%s' in tag `%s'" % (attrnamemap[key], tagname))
for key, val in attributes.items():
if val is not None and not attrdict.has_key(key):
***************
*** 784,788 ****
# Example -- handle relatively harmless syntax errors, could be overridden
def syntax_error(self, message):
! raise RuntimeError, 'Syntax error at line %d: %s' % (self.lineno, message)
# To be overridden -- handlers for unknown objects
--- 792,796 ----
# Example -- handle relatively harmless syntax errors, could be overridden
def syntax_error(self, message):
! raise Error('Syntax error at line %d: %s' % (self.lineno, message))
# To be overridden -- handlers for unknown objects
***************
*** 907,911 ****
x.feed(c)
x.close()
! except RuntimeError, msg:
t1 = time()
print msg
--- 915,919 ----
x.feed(c)
x.close()
! except Error, msg:
t1 = time()
print msg