Statistics
| Branch: | Tag: | Revision:

root / snf-django-lib / snf_django / lib / api / faults.py @ 6c1c0738

History | View | Annotate | Download (2.8 kB)

1 bd40abfa Christos Stavrakakis
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
2 2715ade4 Sofia Papagiannaki
#
3 5635f9ef Antony Chazapis
# Redistribution and use in source and binary forms, with or
4 5635f9ef Antony Chazapis
# without modification, are permitted provided that the following
5 5635f9ef Antony Chazapis
# conditions are met:
6 2715ade4 Sofia Papagiannaki
#
7 5635f9ef Antony Chazapis
#   1. Redistributions of source code must retain the above
8 5635f9ef Antony Chazapis
#      copyright notice, this list of conditions and the following
9 5635f9ef Antony Chazapis
#      disclaimer.
10 2715ade4 Sofia Papagiannaki
#
11 5635f9ef Antony Chazapis
#   2. Redistributions in binary form must reproduce the above
12 5635f9ef Antony Chazapis
#      copyright notice, this list of conditions and the following
13 5635f9ef Antony Chazapis
#      disclaimer in the documentation and/or other materials
14 5635f9ef Antony Chazapis
#      provided with the distribution.
15 2715ade4 Sofia Papagiannaki
#
16 5635f9ef Antony Chazapis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 5635f9ef Antony Chazapis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 5635f9ef Antony Chazapis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 5635f9ef Antony Chazapis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 5635f9ef Antony Chazapis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 5635f9ef Antony Chazapis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 5635f9ef Antony Chazapis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 5635f9ef Antony Chazapis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 5635f9ef Antony Chazapis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 5635f9ef Antony Chazapis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 5635f9ef Antony Chazapis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 5635f9ef Antony Chazapis
# POSSIBILITY OF SUCH DAMAGE.
28 2715ade4 Sofia Papagiannaki
#
29 5635f9ef Antony Chazapis
# The views and conclusions contained in the software and
30 5635f9ef Antony Chazapis
# documentation are those of the authors and should not be
31 5635f9ef Antony Chazapis
# interpreted as representing official policies, either expressed
32 5635f9ef Antony Chazapis
# or implied, of GRNET S.A.
33 5635f9ef Antony Chazapis
34 2715ade4 Sofia Papagiannaki
35 bd40abfa Christos Stavrakakis
"""Common API faults."""
36 bd40abfa Christos Stavrakakis
37 bd40abfa Christos Stavrakakis
38 420c24ee Ilias Tsitsimpis
def camel_case(s):
39 b956618e Antony Chazapis
    return s[0].lower() + s[1:]
40 b956618e Antony Chazapis
41 b956618e Antony Chazapis
42 b956618e Antony Chazapis
class Fault(Exception):
43 fde7b7cb Ilias Tsitsimpis
    def __init__(self, message='', details='', name='', code=None):
44 b956618e Antony Chazapis
        self.message = message
45 b956618e Antony Chazapis
        self.details = details
46 fde7b7cb Ilias Tsitsimpis
        if not hasattr(self, 'code'):
47 fde7b7cb Ilias Tsitsimpis
            self.code = code
48 420c24ee Ilias Tsitsimpis
        self.name = name or camel_case(self.__class__.__name__)
49 fde7b7cb Ilias Tsitsimpis
        Exception.__init__(self, message, details, self.name, self.code)
50 b956618e Antony Chazapis
51 2715ade4 Sofia Papagiannaki
52 bd40abfa Christos Stavrakakis
# 2xx
53 b956618e Antony Chazapis
class NotModified(Fault):
54 b956618e Antony Chazapis
    code = 304
55 b956618e Antony Chazapis
56 2715ade4 Sofia Papagiannaki
57 bd40abfa Christos Stavrakakis
# 4xx
58 b956618e Antony Chazapis
class BadRequest(Fault):
59 b956618e Antony Chazapis
    code = 400
60 b956618e Antony Chazapis
61 2715ade4 Sofia Papagiannaki
62 b956618e Antony Chazapis
class Unauthorized(Fault):
63 b956618e Antony Chazapis
    code = 401
64 b956618e Antony Chazapis
65 2715ade4 Sofia Papagiannaki
66 14983b5d Antony Chazapis
class Forbidden(Fault):
67 b956618e Antony Chazapis
    code = 403
68 b956618e Antony Chazapis
69 2715ade4 Sofia Papagiannaki
70 bd40abfa Christos Stavrakakis
class ResizeNotAllowed(Forbidden):
71 bd40abfa Christos Stavrakakis
    pass
72 bd40abfa Christos Stavrakakis
73 bd40abfa Christos Stavrakakis
74 b956618e Antony Chazapis
class ItemNotFound(Fault):
75 b956618e Antony Chazapis
    code = 404
76 b956618e Antony Chazapis
77 2715ade4 Sofia Papagiannaki
78 b956618e Antony Chazapis
class Conflict(Fault):
79 b956618e Antony Chazapis
    code = 409
80 b956618e Antony Chazapis
81 2715ade4 Sofia Papagiannaki
82 bd40abfa Christos Stavrakakis
class BuildInProgress(Conflict):
83 bd40abfa Christos Stavrakakis
    pass
84 bd40abfa Christos Stavrakakis
85 bd40abfa Christos Stavrakakis
86 b956618e Antony Chazapis
class LengthRequired(Fault):
87 b956618e Antony Chazapis
    code = 411
88 b956618e Antony Chazapis
89 2715ade4 Sofia Papagiannaki
90 b956618e Antony Chazapis
class PreconditionFailed(Fault):
91 b956618e Antony Chazapis
    code = 412
92 b956618e Antony Chazapis
93 2715ade4 Sofia Papagiannaki
94 6d0f82fe Antony Chazapis
class RequestEntityTooLarge(Fault):
95 6d0f82fe Antony Chazapis
    code = 413
96 6d0f82fe Antony Chazapis
97 2715ade4 Sofia Papagiannaki
98 bd40abfa Christos Stavrakakis
class OverLimit(RequestEntityTooLarge):
99 bd40abfa Christos Stavrakakis
    pass
100 bd40abfa Christos Stavrakakis
101 bd40abfa Christos Stavrakakis
102 bd40abfa Christos Stavrakakis
class BadMediaType(Fault):
103 bd40abfa Christos Stavrakakis
    code = 415
104 bd40abfa Christos Stavrakakis
105 bd40abfa Christos Stavrakakis
106 b956618e Antony Chazapis
class RangeNotSatisfiable(Fault):
107 b956618e Antony Chazapis
    code = 416
108 b956618e Antony Chazapis
109 2715ade4 Sofia Papagiannaki
110 bd40abfa Christos Stavrakakis
class NetworkInUse(Fault):
111 bd40abfa Christos Stavrakakis
    code = 421
112 bd40abfa Christos Stavrakakis
113 bd40abfa Christos Stavrakakis
114 b956618e Antony Chazapis
class UnprocessableEntity(Fault):
115 b956618e Antony Chazapis
    code = 422
116 b956618e Antony Chazapis
117 2715ade4 Sofia Papagiannaki
118 bd40abfa Christos Stavrakakis
# 5xx
119 08de868d Antony Chazapis
class InternalServerError(Fault):
120 08de868d Antony Chazapis
    code = 500
121 08de868d Antony Chazapis
122 2715ade4 Sofia Papagiannaki
123 08de868d Antony Chazapis
class NotImplemented(Fault):
124 08de868d Antony Chazapis
    code = 501
125 bd40abfa Christos Stavrakakis
126 bd40abfa Christos Stavrakakis
127 bd40abfa Christos Stavrakakis
class ServiceUnavailable(Fault):
128 bd40abfa Christos Stavrakakis
    code = 503