| 1 |
|
| 2 |
""" |
| 3 |
pyxs.exceptions |
| 4 |
~~~~~~~~~~~~~~~ |
| 5 |
|
| 6 |
This module implements a number of Python exceptions used by |
| 7 |
:mod:`pyxs` classes. |
| 8 |
|
| 9 |
:copyright: (c) 2011 by Selectel, see AUTHORS for more details. |
| 10 |
:license: LGPL, see LICENSE for more details. |
| 11 |
""" |
| 12 |
|
| 13 |
__all__ = [ |
| 14 |
"InvalidOperation", "InvalidPayload", "InvalidPath", "InvalidPermission", |
| 15 |
"ConnectionError", "UnexpectedPacket" |
| 16 |
] |
| 17 |
|
| 18 |
|
| 19 |
class PyXSError(Exception): |
| 20 |
"""Base class for all :mod:`pyxs` exceptions.""" |
| 21 |
|
| 22 |
|
| 23 |
class InvalidOperation(ValueError, PyXSError): |
| 24 |
"""Exception raised when :class:`~pyxs._internal.Packet` is passed |
| 25 |
an operation, which isn't listed in :data:`~pyxs._internal.Op`. |
| 26 |
|
| 27 |
:param int operation: invalid operation value. |
| 28 |
""" |
| 29 |
|
| 30 |
|
| 31 |
class InvalidPayload(ValueError, PyXSError): |
| 32 |
"""Exception raised when :class:`~pyxs.Packet` is initialized with |
| 33 |
payload, which exceeds 4096 bytes restriction or contains a |
| 34 |
trailing ``NULL``. |
| 35 |
|
| 36 |
:param bytes operation: invalid payload value. |
| 37 |
""" |
| 38 |
|
| 39 |
|
| 40 |
class InvalidPath(ValueError, PyXSError): |
| 41 |
"""Exception raised when a path proccessed by a command doesn't |
| 42 |
match the following constraints: |
| 43 |
|
| 44 |
* its length should not exceed 3072 or 2048 for absolute and |
| 45 |
relative path respectively. |
| 46 |
* it should only consist of ASCII alphanumerics and the four |
| 47 |
punctuation characters ``-/_@`` -- `hyphen`, `slash`, `underscore` |
| 48 |
and `atsign`. |
| 49 |
* it shouldn't have a trailing ``/``, except for the root path. |
| 50 |
|
| 51 |
:param bytes path: invalid path value. |
| 52 |
""" |
| 53 |
|
| 54 |
|
| 55 |
class InvalidPermission(ValueError, PyXSError): |
| 56 |
"""Exception raised for permission which don't match the following |
| 57 |
format:: |
| 58 |
|
| 59 |
w<domid> write only |
| 60 |
r<domid> read only |
| 61 |
b<domid> both read and write |
| 62 |
n<domid> no access |
| 63 |
|
| 64 |
:param bytes perm: invalid permission value. |
| 65 |
""" |
| 66 |
|
| 67 |
|
| 68 |
class ConnectionError(PyXSError): |
| 69 |
"""Exception raised for failures during socket operations.""" |
| 70 |
|
| 71 |
|
| 72 |
class UnexpectedPacket(ConnectionError): |
| 73 |
"""Exception raised when received packet header doesn't match the |
| 74 |
header of the packet sent, for example if outgoing packet has |
| 75 |
``op = Op.READ`` the incoming packet is expected to have |
| 76 |
``op = Op.READ`` as well. |
| 77 |
""" |