1# Copyright (c) 2012-2014 Andy Davidoff http://www.disruptek.com/ 2# 3# Permission is hereby granted, free of charge, to any person obtaining a 4# copy of this software and associated documentation files (the 5# "Software"), to deal in the Software without restriction, including 6# without limitation the rights to use, copy, modify, merge, publish, dis- 7# tribute, sublicense, and/or sell copies of the Software, and to permit 8# persons to whom the Software is furnished to do so, subject to the fol- 9# lowing conditions: 10# 11# The above copyright notice and this permission notice shall be included 12# in all copies or substantial portions of the Software. 13# 14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 16# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 17# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20# IN THE SOFTWARE. 21from boto.exception import BotoServerError 22from boto.mws.response import ResponseFactory 23 24 25class ResponseErrorFactory(ResponseFactory): 26 27 def __call__(self, status, reason, body=None): 28 server = BotoServerError(status, reason, body=body) 29 supplied = self.find_element(server.error_code, '', ResponseError) 30 print(supplied.__name__) 31 return supplied(status, reason, body=body) 32 33 34class ResponseError(BotoServerError): 35 """ 36 Undefined response error. 37 """ 38 retry = False 39 40 def __repr__(self): 41 return '{0.__name__}({1.reason}: "{1.message}")' \ 42 .format(self.__class__, self) 43 44 def __str__(self): 45 doc = self.__doc__ and self.__doc__.strip() + "\n" or '' 46 return '{1.__name__}: {0.reason} {2}\n{3}' \ 47 '{0.message}'.format(self, self.__class__, 48 self.retry and '(Retriable)' or '', doc) 49 50 51class RetriableResponseError(ResponseError): 52 retry = True 53 54 55class InvalidParameterValue(ResponseError): 56 """ 57 One or more parameter values in the request is invalid. 58 """ 59 60 61class InvalidParameter(ResponseError): 62 """ 63 One or more parameters in the request is invalid. 64 """ 65 66 67class InvalidAddress(ResponseError): 68 """ 69 Invalid address. 70 """ 71