| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 | #    Copyright 2014 dotCloud inc.#    Licensed under the Apache License, Version 2.0 (the "License");#    you may not use this file except in compliance with the License.#    You may obtain a copy of the License at##        http://www.apache.org/licenses/LICENSE-2.0##    Unless required by applicable law or agreed to in writing, software#    distributed under the License is distributed on an "AS IS" BASIS,#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.#    See the License for the specific language governing permissions and#    limitations under the License.import requestsclass APIError(requests.exceptions.HTTPError):    def __init__(self, message, response, explanation=None):        # requests 1.2 supports response as a keyword argument, but        # requests 1.1 doesn't        super(APIError, self).__init__(message)        self.response = response        self.explanation = explanation        if self.explanation is None and response.content:            self.explanation = response.content.strip()    def __str__(self):        message = super(APIError, self).__str__()        if self.is_client_error():            message = '%s Client Error: %s' % (                self.response.status_code, self.response.reason)        elif self.is_server_error():            message = '%s Server Error: %s' % (                self.response.status_code, self.response.reason)        if self.explanation:            message = '%s ("%s")' % (message, self.explanation)        return message    def is_client_error(self):        return 400 <= self.response.status_code < 500    def is_server_error(self):        return 500 <= self.response.status_code < 600class DockerException(Exception):    passclass InvalidRepository(DockerException):    passclass InvalidConfigFile(DockerException):    passclass DeprecatedMethod(DockerException):    pass
 |