commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/common/src GParser.py


From: Jason Cater
Subject: gnue/common/src GParser.py
Date: Wed, 20 Mar 2002 15:02:13 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/03/20 15:02:13

Modified files:
        common/src     : GParser.py 

Log message:
        instead of printing an error and exiting on markup errors, the parser 
will now raise an exception so that the underlying tools can catch this 
exception and die gracefully.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GParser.py.diff?tr1=1.26&tr2=1.27&r1=text&r2=text

Patches:
Index: gnue/common/src/GParser.py
diff -c gnue/common/src/GParser.py:1.26 gnue/common/src/GParser.py:1.27
*** gnue/common/src/GParser.py:1.26     Fri Feb 15 22:58:59 2002
--- gnue/common/src/GParser.py  Wed Mar 20 15:02:13 2002
***************
*** 1,33 ****
  #
  # This file is part of GNU Enterprise.
  #
! # GNU Enterprise is free software; you can redistribute it 
! # and/or modify it under the terms of the GNU General Public 
! # License as published by the Free Software Foundation; either 
  # version 2, or (at your option) any later version.
  #
! # GNU Enterprise is distributed in the hope that it will be 
! # useful, but WITHOUT ANY WARRANTY; without even the implied 
! # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  # PURPOSE. See the GNU General Public License for more details.
  #
! # You should have received a copy of the GNU General Public 
! # License along with program; see the file COPYING. If not, 
  # write to the Free Software Foundation, Inc., 59 Temple Place
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # Copyright 2000 Free Software Foundation
  #
  # FILE:
  # GParser.py
  #
  # DESCRIPTION:
! # Class that contains a sax based xml processor for GNUE
  #
  # NOTES:
  #
- # HISTORY:
- #
  
  import sys
  
--- 1,31 ----
  #
  # This file is part of GNU Enterprise.
  #
! # GNU Enterprise is free software; you can redistribute it
! # and/or modify it under the terms of the GNU General Public
! # License as published by the Free Software Foundation; either
  # version 2, or (at your option) any later version.
  #
! # GNU Enterprise is distributed in the hope that it will be
! # useful, but WITHOUT ANY WARRANTY; without even the implied
! # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  # PURPOSE. See the GNU General Public License for more details.
  #
! # You should have received a copy of the GNU General Public
! # License along with program; see the file COPYING. If not,
  # write to the Free Software Foundation, Inc., 59 Temple Place
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # Copyright 2000-2002 Free Software Foundation
  #
  # FILE:
  # GParser.py
  #
  # DESCRIPTION:
! # Class that contains a SAX2-based XML processor for GNUe
  #
  # NOTES:
  #
  
  import sys
  
***************
*** 43,49 ****
        http://pyxml.sourceforge.net/
  
  """
!   sys.exit()
  
  import string
  import GDebug
--- 41,47 ----
        http://pyxml.sourceforge.net/
  
  """
!   
  
  import string
  import GDebug
***************
*** 53,58 ****
--- 51,64 ----
  
  #######################################################
  #
+ # Error classed raised for markup errors
+ #
+ class MarkupError(StandardError):
+   pass
+ 
+ 
+ #######################################################
+ #
  # loadXMLObject
  #
  # This method loads an object from an XML file and
***************
*** 90,101 ****
    object = dh.getRoot()
  
    if not object:
!     print "Error loading %s: empty definition file" % (xmlFileType)
!     sys.exit()
    elif object._type != rootType:
!     print "Error loading %s: not a valid %s definition (expected: %s, got: 
%s)" % (xmlFileType,
           xmlFileType, rootType, object._type)
-     sys.exit()
  
    #object.showTree()
  
--- 96,105 ----
    object = dh.getRoot()
  
    if not object:
!     raise MarkupError, "Error loading %s: empty definition file" % 
(xmlFileType)
    elif object._type != rootType:
!     raise MarkupError, "Error loading %s: not a valid %s definition 
(expected: %s, got: %s)" % (xmlFileType,
           xmlFileType, rootType, object._type)
  
    #object.showTree()
  
***************
*** 134,140 ****
  # NOTE: This is a redefinition of GTypecast.boolean.
  #   This redefinition will be removed as soon as all
  #   references to it are changes.  You should be using
! #   GTypecast from now on. 
  #
  #######################################################
  bool = GTypecast.boolean
--- 138,144 ----
  # NOTE: This is a redefinition of GTypecast.boolean.
  #   This redefinition will be removed as soon as all
  #   references to it are changes.  You should be using
! #   GTypecast from now on.
  #
  #######################################################
  bool = GTypecast.boolean
***************
*** 152,160 ****
  
  
  def default(attrs, key, default):
!   if attrs.has_key(key):
      return attrs[key]
!   else:
      return default
  
  
--- 156,164 ----
  
  
  def default(attrs, key, default):
!   try:
      return attrs[key]
!   except KeyError:
      return default
  
  
***************
*** 187,194 ****
  
      # Make sure the tag we are looking at is a valid tag
      if not self.xmlElements.has_key (name):
!       print 'Error processing <%s> tag [I do not know what a <%s> tag does]' 
% (name, name)
!       sys.exit()
  
      baseAttrs = default(self.xmlElements[name],'Attributes',{})
      attrs = {}
--- 191,197 ----
  
      # Make sure the tag we are looking at is a valid tag
      if not self.xmlElements.has_key (name):
!       raise MarkupError, 'Error processing <%s> tag [I do not know what a 
<%s> tag does]' % (name, name)
  
      baseAttrs = default(self.xmlElements[name],'Attributes',{})
      attrs = {}
***************
*** 198,219 ****
  
        # Make sure the attribute we are looking at is a valid attribute
        if not baseAttrs.has_key(attr):
!         print 'Error processing <%s> tag [I do not recognize the "%s" 
attribute' % (name, attr)
!         sys.exit()
  
        # Typecasting, anyone?  If attribute should be int, make it an int
        try:
          attrs[attr] = default(baseAttrs[attr],'Typecast',char)(saxattrs[attr])
          loadedxmlattrs[attr] = attrs[attr]
        except:
!         print 'Error processing <%s> tag [invalid type for "%s" attribute; 
value is "%s"]' % (name, attr, saxattrs[attr])
!         sys.exit()
  
        # If this attribute must be unique, check for duplicates
        if default (baseAttrs[attr],'Unique',0):
          if self.uniqueIDs.has_key('%s' % (saxattrs[attr])):
!           print 'Error processing <%s> tag ["%s" attribute should be unique; 
duplicate value is "%s"]' % (name, attr, saxattrs[attr])
!           sys.exit()
  
      for attr in baseAttrs.keys():
        if not attrs.has_key(attr):
--- 201,219 ----
  
        # Make sure the attribute we are looking at is a valid attribute
        if not baseAttrs.has_key(attr):
!         raise MarkupError, 'Error processing <%s> tag [I do not recognize the 
"%s" attribute' % (name, attr)
  
        # Typecasting, anyone?  If attribute should be int, make it an int
        try:
          attrs[attr] = default(baseAttrs[attr],'Typecast',char)(saxattrs[attr])
          loadedxmlattrs[attr] = attrs[attr]
        except:
!         raise MarkupError, 'Error processing <%s> tag [invalid type for "%s" 
attribute; value is "%s"]' % (name, attr, saxattrs[attr])
  
        # If this attribute must be unique, check for duplicates
        if default (baseAttrs[attr],'Unique',0):
          if self.uniqueIDs.has_key('%s' % (saxattrs[attr])):
!           raise MarkupError, 'Error processing <%s> tag ["%s" attribute 
should be unique; duplicate value is "%s"]' % (name, attr, saxattrs[attr])
  
      for attr in baseAttrs.keys():
        if not attrs.has_key(attr):
***************
*** 224,231 ****
  
          # Check for missing required attributes
          elif default(baseAttrs[attr], 'Required', 0):
!           print 'Error processing <%s> tag [required attribute "%s" not 
present]' % (name, attr)
!           sys.exit()
  
  
      if self.bootstrapflag:
--- 224,230 ----
  
          # Check for missing required attributes
          elif default(baseAttrs[attr], 'Required', 0):
!           raise MarkupError, 'Error processing <%s> tag [required attribute 
"%s" not present]' % (name, attr)
  
  
      if self.bootstrapflag:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]