1 #!/usr/bin/env python 2 3 """ 4 Errors for DOM Level 3. 5 6 Copyright (C) 2008 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU Lesser General Public License as published by the Free 10 Software Foundation; either version 3 of the License, or (at your option) any 11 later version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 details. 17 18 You should have received a copy of the GNU Lesser General Public License along 19 with this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 class DOMError: 23 24 """ 25 DOM Level 3 Core exception. 26 See: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ERROR-Interfaces-DOMError 27 """ 28 29 SEVERITY_WARNING = 1 30 SEVERITY_ERROR = 2 31 SEVERITY_FATAL_ERROR = 3 32 33 def __init__(self, severity=None, message=None, type=None, relatedException=None, relatedData=None, location=None): 34 self.severity = severity 35 self.message = message 36 self.type = type 37 self.relatedException = relatedException 38 self.relatedData = relatedData 39 self.location = location 40 41 def __repr__(self): 42 return "DOMError(%d, %r, %r)" % (self.severity, self.message, self.type) 43 44 def __str__(self): 45 return "DOMError: %s" % self.message 46 47 # NOTE: Find a reasonable way of exposing error details. 48 49 class DOMErrorHandler: 50 51 """ 52 DOM Level 3 Core error handler. 53 See: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ERROR-Interfaces-DOMErrorHandler 54 """ 55 56 def __init__(self): 57 self.errors = [] 58 59 def handleError(self, error): 60 self.errors.append(error) 61 62 # Special extension methods. 63 64 def reset(self): 65 self.errors = [] 66 67 def __repr__(self): 68 return "DOMErrorHandler()" 69 70 def __str__(self): 71 return "DOMErrorHandler: %r" % self.errors 72 73 # vim: tabstop=4 expandtab shiftwidth=4