source: server/lib/gutenbach/ipp/core/errors.py @ b01b6d1

no-cups
Last change on this file since b01b6d1 was b01b6d1, checked in by Jessica B. Hamrick <jhamrick@…>, 12 years ago

Clean up printer, job, and requests code

  • Property mode set to 100644
File size: 6.1 KB
Line 
1__all__ = [
2    'IPPException',
3    'IPPClientException',
4    'IPPServerException',
5
6    'ClientErrorBadRequest',
7    'ClientErrorForbidden',
8    'ClientErrorNotAuthenticated',
9    'ClientErrorNotAuthorized',
10    'ClientErrorNotPossible',
11    'ClientErrorTimeout',
12    'ClientErrorNotFound',
13    'ClientErrorGone',
14    'ClientErrorRequestEntity',
15    'ClientErrorRequestValue',
16    'ClientErrorDocumentFormatNotSupported',
17    'ClientErrorAttributes',
18    'ClientErrorUriSchemeNotSupported',
19    'ClientErrorCharsetNotSupported',
20    'ClientErrorConflict',
21    'ClientErrorCompressionNotSupported',
22    'ClientErrorCompressionError',
23    'ClientErrorDocumentFormatError',
24    'ClientErrorDocumentAccessError',
25    'ClientErrorAttributesNotSettable',
26    'ClientErrorIgnoredAllSubscriptions',
27    'ClientErrorTooManySubscriptions',
28    'ClientErrorIgnoredAllNotifications',
29    'ClientErrorPrintSupportFileNotFound',
30
31    'ServerErrorInternalError',
32    'ServerErrorOperationNotSupported',
33    'ServerErrorServiceUnavailable',
34    'ServerErrorVersionNotSupported',
35    'ServerErrorDeviceError',
36    'ServerErrorTemporaryError',
37    'ServerErrorNotAccepting',
38    'ServerErrorPrinterBusy',
39    'ServerErrorJobCancelled',
40    'ServerErrorMultipleJobsNotSupported',
41    'ServerErrorPrinterIsDeactivated',
42]
43   
44
45from .constants import ErrorCodes, AttributeTags
46from .attributegroup import AttributeGroup
47
48class IPPException(Exception):
49    def __init__(self, message=""):
50        self.message = message
51
52    def __str__(self):
53        return self.message
54
55class IPPClientException(IPPException):
56    def update_response(self, response):
57        if hasattr(self, "ipp_error_code"):
58            response.operation_id = self.ipp_error_code
59        else:
60            response.operation_id = ErrorCodes.BAD_REQUEST
61
62class IPPServerException(IPPException):
63    def update_response(self, response):
64        if hasattr(self, "ipp_error_code"):
65            response.operation_id = self.ipp_error_code
66        else:
67            response.operation_id = ErrorCodes.INTERNAL_ERROR
68   
69### Client error codes
70
71class ClientErrorBadRequest(IPPClientException):
72    ipp_error_code = ErrorCodes.BAD_REQUEST
73
74class ClientErrorForbidden(IPPClientException):
75    ipp_error_code = ErrorCodes.FORBIDDEN
76
77class ClientErrorNotAuthenticated(IPPClientException):
78    ipp_error_code = ErrorCodes.NOT_AUTHENTICATED
79
80class ClientErrorNotAuthorized(IPPClientException):
81    ipp_error_code = ErrorCodes.NOT_AUTHORIZED
82
83class ClientErrorNotPossible(IPPClientException):
84    ipp_error_code = ErrorCodes.NOT_POSSIBLE
85
86class ClientErrorTimeout(IPPClientException):
87    ipp_error_code = ErrorCodes.TIMEOUT
88
89class ClientErrorNotFound(IPPClientException):
90    ipp_error_code = ErrorCodes.NOT_FOUND
91
92class ClientErrorGone(IPPClientException):
93    ipp_error_code = ErrorCodes.GONE
94
95class ClientErrorRequestEntity(IPPClientException):
96    ipp_error_code = ErrorCodes.REQUEST_ENTITY
97
98class ClientErrorRequestValue(IPPClientException):
99    ipp_error_code = ErrorCodes.REQUEST_VALUE
100
101class ClientErrorDocumentFormatNotSupported(IPPClientException):
102    ipp_error_code = ErrorCodes.DOCUMENT_FORMAT
103
104class ClientErrorAttributes(IPPClientException):
105    ipp_error_code = ErrorCodes.ATTRIBUTES
106
107    def __init__(self, message, attrs):
108        self.message = message
109        if hasattr(attrs, '__iter__'):
110            self.bad_attrs = attrs
111        else:
112            self.bad_attrs = [attrs]
113
114    def update_response(self, response):
115        super(ClientErrorAttributes, self).update_response(response)
116        response.attribute_groups.append(
117            AttributeGroup(
118                AttributeTags.UNSUPPORTED,
119                self.bad_attrs))
120
121class ClientErrorUriSchemeNotSupported(IPPClientException):
122    ipp_error_code = ErrorCodes.URI_SCHEME
123
124class ClientErrorCharsetNotSupported(IPPClientException):
125    ipp_error_code = ErrorCodes.CHARSET
126
127class ClientErrorConflict(IPPClientException):
128    ipp_error_code = ErrorCodes.CONFLICT
129
130class ClientErrorCompressionNotSupported(IPPClientException):
131    ipp_error_code = ErrorCodes.COMPRESSION_NOT_SUPPORTED
132
133class ClientErrorCompressionError(IPPClientException):
134    ipp_error_code = ErrorCodes.COMPRESSION_ERROR
135
136class ClientErrorDocumentFormatError(IPPClientException):
137    ipp_error_code = ErrorCodes.DOCUMENT_FORMAT_ERROR
138
139class ClientErrorDocumentAccessError(IPPClientException):
140    ipp_error_code = ErrorCodes.DOCUMENT_ACCESS_ERROR
141
142class ClientErrorAttributesNotSettable(IPPClientException):
143    ipp_error_code = ErrorCodes.ATTRIBUTES_NOT_SETTABLE
144
145class ClientErrorIgnoredAllSubscriptions(IPPClientException):
146    ipp_error_code = ErrorCodes.IGNORED_ALL_SUBSCRIPTIONS
147
148class ClientErrorTooManySubscriptions(IPPClientException):
149    ipp_error_code = ErrorCodes.TOO_MANY_SUBSCRIPTIONS
150
151class ClientErrorIgnoredAllNotifications(IPPClientException):
152    ipp_error_code = ErrorCodes.IGNORED_ALL_NOTIFICATIONS
153
154class ClientErrorPrintSupportFileNotFound(IPPClientException):
155    ipp_error_code = ErrorCodes.PRINT_SUPPORT_FILE_NOT_FOUND
156
157### Server error codes
158
159class ServerErrorInternalError(IPPServerException):
160    ipp_error_code = ErrorCodes.INTERNAL_ERROR
161
162class ServerErrorOperationNotSupported(IPPServerException):
163    ipp_error_code = ErrorCodes.OPERATION_NOT_SUPPORTED
164
165class ServerErrorServiceUnavailable(IPPServerException):
166    ipp_error_code = ErrorCodes.SERVICE_UNAVAILABLE
167
168class ServerErrorVersionNotSupported(IPPServerException):
169    ipp_error_code = ErrorCodes.VERSION_NOT_SUPPORTED
170
171class ServerErrorDeviceError(IPPServerException):
172    ipp_error_code = ErrorCodes.DEVICE_ERROR
173
174class ServerErrorTemporaryError(IPPServerException):
175    ipp_error_code = ErrorCodes.TEMPORARY_ERROR
176
177class ServerErrorNotAccepting(IPPServerException):
178    ipp_error_code = ErrorCodes.NOT_ACCEPTING
179
180class ServerErrorPrinterBusy(IPPServerException):
181    ipp_error_code = ErrorCodes.PRINTER_BUSY
182
183class ServerErrorJobCancelled(IPPServerException):
184    ipp_error_code = ErrorCodes.ERROR_JOB_CANCELLED
185
186class ServerErrorMultipleJobsNotSupported(IPPServerException):
187    ipp_error_code = ErrorCodes.MULTIPLE_JOBS_NOT_SUPPORTED
188
189class ServerErrorPrinterIsDeactivated(IPPServerException):
190    ipp_error_code = ErrorCodes.PRINTER_IS_DEACTIVATED
Note: See TracBrowser for help on using the repository browser.