martin f. krafft | 3434b6b | 2013-06-14 20:40:52 +0200 | [diff] [blame] | 1 | # |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # |
| 4 | # This file is part of reclass (http://github.com/madduck/reclass) |
| 5 | # |
| 6 | # Copyright © 2007–13 martin f. krafft <madduck@madduck.net> |
| 7 | # Released under the terms of the Artistic Licence 2.0 |
| 8 | # |
| 9 | |
| 10 | import posix |
| 11 | |
| 12 | class ReclassException(Exception): |
| 13 | |
| 14 | def __init__(self, rc=posix.EX_SOFTWARE, *args): |
| 15 | super(ReclassException, self).__init__(*args) |
| 16 | self._rc = rc |
| 17 | |
| 18 | def __str__(self): |
| 19 | return "reclass encountered an exception, sorry!" |
| 20 | |
| 21 | message = property(lambda self: self.__str__()) |
| 22 | rc = property(lambda self: self._rc) |
| 23 | |
| 24 | |
| 25 | class NotFoundError(ReclassException): |
| 26 | |
| 27 | def __init__(self, rc=posix.EX_IOERR): |
| 28 | super(NotFoundError, self).__init__(rc) |
| 29 | |
| 30 | |
| 31 | class NodeNotFound(NotFoundError): |
| 32 | |
| 33 | def __init__(self, storage, classname, uri): |
| 34 | super(NodeNotFound, self).__init__() |
| 35 | self._storage = storage |
| 36 | self._name = classname |
| 37 | self._uri = uri |
| 38 | |
| 39 | def __str__(self): |
| 40 | return "Node '{0}' not found under {1}://{2}".format(self._name, |
| 41 | self._storage, |
| 42 | self._uri) |
| 43 | |
| 44 | |
| 45 | class ClassNotFound(NodeNotFound): |
| 46 | |
| 47 | def __init__(self, storage, classname, uri, nodename): |
| 48 | super(ClassNotFound, self).__init__(storage, classname, uri) |
| 49 | self._nodename = nodename |
| 50 | |
| 51 | def __str__(self): |
| 52 | return "Class '{0}' (in ancestry of node {1}) not found under {2}://{3}" \ |
| 53 | .format(self._name, self._nodename, self._storage, self._uri) |