A string-like object that can additionally have a code.
| 61 | |
| 62 | |
| 63 | class ErrorDetail(str): |
| 64 | """ |
| 65 | A string-like object that can additionally have a code. |
| 66 | """ |
| 67 | code = None |
| 68 | |
| 69 | def __new__(cls, string, code=None): |
| 70 | self = super().__new__(cls, string) |
| 71 | self.code = code |
| 72 | return self |
| 73 | |
| 74 | def __eq__(self, other): |
| 75 | result = super().__eq__(other) |
| 76 | if result is NotImplemented: |
| 77 | return NotImplemented |
| 78 | try: |
| 79 | return result and self.code == other.code |
| 80 | except AttributeError: |
| 81 | return result |
| 82 | |
| 83 | def __ne__(self, other): |
| 84 | result = self.__eq__(other) |
| 85 | if result is NotImplemented: |
| 86 | return NotImplemented |
| 87 | return not result |
| 88 | |
| 89 | def __repr__(self): |
| 90 | return 'ErrorDetail(string=%r, code=%r)' % ( |
| 91 | str(self), |
| 92 | self.code, |
| 93 | ) |
| 94 | |
| 95 | def __hash__(self): |
| 96 | return hash(str(self)) |
| 97 | |
| 98 | |
| 99 | class APIException(Exception): |
no outgoing calls