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 | |
---|
45 | from .constants import ErrorCodes, AttributeTags |
---|
46 | from .attributegroup import AttributeGroup |
---|
47 | |
---|
48 | class IPPException(Exception): |
---|
49 | def __init__(self, message=""): |
---|
50 | self.message = message |
---|
51 | |
---|
52 | def __str__(self): |
---|
53 | return self.message |
---|
54 | |
---|
55 | class 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 | |
---|
62 | class 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 | |
---|
71 | class ClientErrorBadRequest(IPPClientException): |
---|
72 | ipp_error_code = ErrorCodes.BAD_REQUEST |
---|
73 | |
---|
74 | class ClientErrorForbidden(IPPClientException): |
---|
75 | ipp_error_code = ErrorCodes.FORBIDDEN |
---|
76 | |
---|
77 | class ClientErrorNotAuthenticated(IPPClientException): |
---|
78 | ipp_error_code = ErrorCodes.NOT_AUTHENTICATED |
---|
79 | |
---|
80 | class ClientErrorNotAuthorized(IPPClientException): |
---|
81 | ipp_error_code = ErrorCodes.NOT_AUTHORIZED |
---|
82 | |
---|
83 | class ClientErrorNotPossible(IPPClientException): |
---|
84 | ipp_error_code = ErrorCodes.NOT_POSSIBLE |
---|
85 | |
---|
86 | class ClientErrorTimeout(IPPClientException): |
---|
87 | ipp_error_code = ErrorCodes.TIMEOUT |
---|
88 | |
---|
89 | class ClientErrorNotFound(IPPClientException): |
---|
90 | ipp_error_code = ErrorCodes.NOT_FOUND |
---|
91 | |
---|
92 | class ClientErrorGone(IPPClientException): |
---|
93 | ipp_error_code = ErrorCodes.GONE |
---|
94 | |
---|
95 | class ClientErrorRequestEntity(IPPClientException): |
---|
96 | ipp_error_code = ErrorCodes.REQUEST_ENTITY |
---|
97 | |
---|
98 | class ClientErrorRequestValue(IPPClientException): |
---|
99 | ipp_error_code = ErrorCodes.REQUEST_VALUE |
---|
100 | |
---|
101 | class ClientErrorDocumentFormatNotSupported(IPPClientException): |
---|
102 | ipp_error_code = ErrorCodes.DOCUMENT_FORMAT |
---|
103 | |
---|
104 | class 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 | |
---|
121 | class ClientErrorUriSchemeNotSupported(IPPClientException): |
---|
122 | ipp_error_code = ErrorCodes.URI_SCHEME |
---|
123 | |
---|
124 | class ClientErrorCharsetNotSupported(IPPClientException): |
---|
125 | ipp_error_code = ErrorCodes.CHARSET |
---|
126 | |
---|
127 | class ClientErrorConflict(IPPClientException): |
---|
128 | ipp_error_code = ErrorCodes.CONFLICT |
---|
129 | |
---|
130 | class ClientErrorCompressionNotSupported(IPPClientException): |
---|
131 | ipp_error_code = ErrorCodes.COMPRESSION_NOT_SUPPORTED |
---|
132 | |
---|
133 | class ClientErrorCompressionError(IPPClientException): |
---|
134 | ipp_error_code = ErrorCodes.COMPRESSION_ERROR |
---|
135 | |
---|
136 | class ClientErrorDocumentFormatError(IPPClientException): |
---|
137 | ipp_error_code = ErrorCodes.DOCUMENT_FORMAT_ERROR |
---|
138 | |
---|
139 | class ClientErrorDocumentAccessError(IPPClientException): |
---|
140 | ipp_error_code = ErrorCodes.DOCUMENT_ACCESS_ERROR |
---|
141 | |
---|
142 | class ClientErrorAttributesNotSettable(IPPClientException): |
---|
143 | ipp_error_code = ErrorCodes.ATTRIBUTES_NOT_SETTABLE |
---|
144 | |
---|
145 | class ClientErrorIgnoredAllSubscriptions(IPPClientException): |
---|
146 | ipp_error_code = ErrorCodes.IGNORED_ALL_SUBSCRIPTIONS |
---|
147 | |
---|
148 | class ClientErrorTooManySubscriptions(IPPClientException): |
---|
149 | ipp_error_code = ErrorCodes.TOO_MANY_SUBSCRIPTIONS |
---|
150 | |
---|
151 | class ClientErrorIgnoredAllNotifications(IPPClientException): |
---|
152 | ipp_error_code = ErrorCodes.IGNORED_ALL_NOTIFICATIONS |
---|
153 | |
---|
154 | class ClientErrorPrintSupportFileNotFound(IPPClientException): |
---|
155 | ipp_error_code = ErrorCodes.PRINT_SUPPORT_FILE_NOT_FOUND |
---|
156 | |
---|
157 | ### Server error codes |
---|
158 | |
---|
159 | class ServerErrorInternalError(IPPServerException): |
---|
160 | ipp_error_code = ErrorCodes.INTERNAL_ERROR |
---|
161 | |
---|
162 | class ServerErrorOperationNotSupported(IPPServerException): |
---|
163 | ipp_error_code = ErrorCodes.OPERATION_NOT_SUPPORTED |
---|
164 | |
---|
165 | class ServerErrorServiceUnavailable(IPPServerException): |
---|
166 | ipp_error_code = ErrorCodes.SERVICE_UNAVAILABLE |
---|
167 | |
---|
168 | class ServerErrorVersionNotSupported(IPPServerException): |
---|
169 | ipp_error_code = ErrorCodes.VERSION_NOT_SUPPORTED |
---|
170 | |
---|
171 | class ServerErrorDeviceError(IPPServerException): |
---|
172 | ipp_error_code = ErrorCodes.DEVICE_ERROR |
---|
173 | |
---|
174 | class ServerErrorTemporaryError(IPPServerException): |
---|
175 | ipp_error_code = ErrorCodes.TEMPORARY_ERROR |
---|
176 | |
---|
177 | class ServerErrorNotAccepting(IPPServerException): |
---|
178 | ipp_error_code = ErrorCodes.NOT_ACCEPTING |
---|
179 | |
---|
180 | class ServerErrorPrinterBusy(IPPServerException): |
---|
181 | ipp_error_code = ErrorCodes.PRINTER_BUSY |
---|
182 | |
---|
183 | class ServerErrorJobCancelled(IPPServerException): |
---|
184 | ipp_error_code = ErrorCodes.ERROR_JOB_CANCELLED |
---|
185 | |
---|
186 | class ServerErrorMultipleJobsNotSupported(IPPServerException): |
---|
187 | ipp_error_code = ErrorCodes.MULTIPLE_JOBS_NOT_SUPPORTED |
---|
188 | |
---|
189 | class ServerErrorPrinterIsDeactivated(IPPServerException): |
---|
190 | ipp_error_code = ErrorCodes.PRINTER_IS_DEACTIVATED |
---|