Statistics
| Branch: | Tag: | Revision:

root / pithos / api / faults.py @ 038f1ae9

History | View | Annotate | Download (2.3 kB)

1 5635f9ef Antony Chazapis
# Copyright 2011 GRNET S.A. All rights reserved.
2 5635f9ef Antony Chazapis
# 
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 5635f9ef Antony Chazapis
# 
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 5635f9ef Antony Chazapis
# 
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 5635f9ef Antony Chazapis
# 
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 5635f9ef Antony Chazapis
# 
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 b956618e Antony Chazapis
def camelCase(s):
35 b956618e Antony Chazapis
    return s[0].lower() + s[1:]
36 b956618e Antony Chazapis
37 b956618e Antony Chazapis
38 b956618e Antony Chazapis
class Fault(Exception):
39 b956618e Antony Chazapis
    def __init__(self, message='', details='', name=''):
40 b956618e Antony Chazapis
        Exception.__init__(self, message, details, name)
41 b956618e Antony Chazapis
        self.message = message
42 b956618e Antony Chazapis
        self.details = details
43 b956618e Antony Chazapis
        self.name = name or camelCase(self.__class__.__name__)
44 b956618e Antony Chazapis
45 b956618e Antony Chazapis
class NotModified(Fault):
46 b956618e Antony Chazapis
    code = 304
47 b956618e Antony Chazapis
48 b956618e Antony Chazapis
class BadRequest(Fault):
49 b956618e Antony Chazapis
    code = 400
50 b956618e Antony Chazapis
51 b956618e Antony Chazapis
class Unauthorized(Fault):
52 b956618e Antony Chazapis
    code = 401
53 b956618e Antony Chazapis
54 b956618e Antony Chazapis
class ResizeNotAllowed(Fault):
55 b956618e Antony Chazapis
    code = 403
56 b956618e Antony Chazapis
57 b956618e Antony Chazapis
class ItemNotFound(Fault):
58 b956618e Antony Chazapis
    code = 404
59 b956618e Antony Chazapis
60 b956618e Antony Chazapis
class Conflict(Fault):
61 b956618e Antony Chazapis
    code = 409
62 b956618e Antony Chazapis
63 b956618e Antony Chazapis
class LengthRequired(Fault):
64 b956618e Antony Chazapis
    code = 411
65 b956618e Antony Chazapis
66 b956618e Antony Chazapis
class PreconditionFailed(Fault):
67 b956618e Antony Chazapis
    code = 412
68 b956618e Antony Chazapis
69 b956618e Antony Chazapis
class RangeNotSatisfiable(Fault):
70 b956618e Antony Chazapis
    code = 416
71 b956618e Antony Chazapis
72 b956618e Antony Chazapis
class UnprocessableEntity(Fault):
73 b956618e Antony Chazapis
    code = 422
74 b956618e Antony Chazapis
75 b956618e Antony Chazapis
class ServiceUnavailable(Fault):
76 b956618e Antony Chazapis
    code = 503