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