Convenience decorator to associate HTTP status codes with :class:`.ApiError` subclasses.

    :param http_code: (int) HTTP status code.
    :return: wrapper function.
186207
def api_exception(http_code):
    
    def wrapper(*args):
        code = args[0]
        ErrorMapping.mapping[http_code] = code
        return code
    return wrapper
617292
def check_status_code(response, verbose):
    
    if (response.status_code == 410 and
            response.url.startswith(("https://pypi.python.org",
                                     "https://testpypi.python.org"))):
        print("It appears you're uploading to pypi.python.org (or "
              "testpypi.python.org). You've received a 410 error response. "
              "Uploading to those sites is deprecated. The new sites are "
              "pypi.org and test.pypi.org. Try using "
              "https://upload.pypi.org/legacy/ "
              "(or https://test.pypi.org/legacy/) to upload your packages "
              "instead. These are the default URLs for Twine now. More at "
              "https://packaging.python.org/guides/migrating-to-pypi-org/ ")
    try:
        response.raise_for_status()
    except HTTPError as err:
        if response.text:
            if verbose:
                print('Content received from server:\n{}'.format(
                    response.text))
            else:
                print('NOTE: Try --verbose to see response content.')
        raise err
662835
def http_error(self, url, fp, errcode, errmsg, headers, data=None):
        """"""
        # First check if there's a specific handler for this error
        name = 'http_error_%d' % errcode
        if hasattr(self, name):
            method = getattr(self, name)
            if data is None:
                result = method(url, fp, errcode, errmsg, headers)
            else:
                result = method(url, fp, errcode, errmsg, headers, data)
            if result: return result
        return self.http_error_default(url, fp, errcode, errmsg, headers)
1076710
def write_error(self, status_code, **kwargs):
        
        http_error = _get_http_error(kwargs)
        if http_error:
            self.finish(self._error_template(status_code,
                                             http_error.errors,
                                             http_error.source))
        else:
            source = kwargs.get('source', getattr(options, 'name', None))
            # Slightly annoyed that have to rely on the internal self._reason
            # to deal with unhandled exceptions. On the dev version of
            # tornado self._reason is always set, while in the current version
            # a reason kwarg is passed down from `send_error` but not set
            # on the instance.
            reason = kwargs.get('reason', self._reason)
            self.finish(self._error_template(status_code, reason, source))
1203134
def _create_error(self, status_code):
        

        return jsend.error(message=ComodoCA.status_code[status_code], code=status_code)
1197588
def http_error_307(self, url, fp, errcode, errmsg, headers, data=None):
        """"""
        if data is None:
            return self.http_error_302(url, fp, errcode, errmsg, headers, data)
        else:
            return self.http_error_default(url, fp, errcode, errmsg, headers)
862926
def error_class_for_http_status(status):
    """"""
    try:
        return error_classes[status]
    except KeyError:
        def new_status_error(xml_response):
            if (status > 400 and status < 500):
                return UnexpectedClientError(status, xml_response)
            if (status > 500 and status < 600):
                return UnexpectedServerError(status, xml_response)
            return UnexpectedStatusError(status, xml_response)
        return new_status_error
539061
def apply_status_code(self, status_code):
        
        self._check_ended()
        if not status_code:
            return

        if status_code >= 500:
            self.add_fault_flag()
        elif status_code == 429:
            self.add_throttle_flag()
            self.add_error_flag()
        elif status_code >= 400:
            self.add_error_flag()
893229
def get_reason_for_status(status_code):
        

        if status_code in requests.status_codes.codes:
            return requests.status_codes._codes[status_code][0].replace('_',
                                                                        ' ')
        else:
            return 'Unknown status code - {0}'.format(status_code)
557813
def error_code(self, code):
		
		return WWebResponse(
			status=code,
			headers=WHTTPHeaders(**{'Content-Type': 'text/plain; charset=utf-8'}),
			response_data=self.__message__(code).encode()
		)
691742
def errors(self,
               errors: List[str],
               code: Union[int, Tuple[int, str, str]] = HTTPStatus.BAD_REQUEST,
               key: str = 'errors',
               headers: Optional[Dict[str, str]] = None,
               ):
        
        return jsonify({key: errors}), code, headers or {}
505544
def error_wrapper(fn, error_class):  # type: (Callable or None, Exception) -> ...
    
    def wrapper(*args, **kwargs):
        try:
            return fn(*args, **kwargs)
        except Exception as e:
            six.reraise(error_class, error_class(e), sys.exc_info()[2])

    return wrapper
966340
def _return_response_and_status_code(response):
    
    if response.status_code == requests.codes.ok:
        return dict(results=response.json(), response_code=response.status_code)
    elif response.status_code == 204:
        return dict(error='You exceeded the public API request rate limit (4 requests of any nature per minute)',
                    response_code=response.status_code)
    elif response.status_code == 403:
        return dict(error='You tried to perform calls to functions for which you require a Private API key.',
                    response_code=response.status_code)
    else:
        return dict(response_code=response.status_code)
268212
def _check_for_errors(response, json_response):
        
        status_code = response.status_code
        try:
            response.raise_for_status()
        except requests.HTTPError as why:
            raise ApiError(str(why), reply_code=status_code)
        if isinstance(json_response, dict) and 'error' in json_response:
            raise ApiError(json_response['error'], reply_code=status_code)
1337128
def __check_http_err(self, status_code):
        """"""
        if status_code == 403:
            raise exceptions.APIAuthenticationError(self.api_key)
        elif status_code == 503:
            raise exceptions.APITimeoutError()
        else:
            return False
57147
def _check_response_status(self, response):
        
        if response.status_code != requests.codes.ok:
            self._logger.error("%s %s", response.status_code, response.text)
            raise exceptions.RequestNonSuccessException(
                "Url {0} had status_code {1}".format(
                    response.url, response.status_code))
171428
def status_code(self):
        
        try:
            return self._status_code
        except AttributeError:
            self._status_code = self._response.getcode()
        return self._status_code