If DEBUG: raise NotImplemented Exception.
        If not, raise 404.
        :raises:`django.http.Http404` if production environment.
        :raises:`NotImplementedError` if ``settings.DEBUG`` is True
961983
def not_implemented(self, context, **response_kwargs):
        '''
        
        '''
        if settings.DEBUG:
            raise NotImplementedError(_('This export type ({})is not yet supported.'.format(self.format)))
        raise Http404
946590
def _raise_error(self, status_code, raw_data):
        
        error_message = raw_data
        additional_info = None
        try:
            additional_info = json.loads(raw_data)
            error_message = additional_info.get('error', error_message)
            if isinstance(error_message, dict) and 'type' in error_message:
                error_message = error_message['type']
        except:
            pass

        raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
868375
def _resp_exception(self, resp):
        

        message = [
            'Url: [ %s ] Reason: [ %s ] Request: [ %s ] Status Code: [ %s ]. ',
            resp.url,
            resp.reason,
            resp.request,
            resp.status_code
        ]

        # Check to make sure we have all the bits needed
        if not hasattr(resp, 'status_code'):
            message[0] += 'No Status to check. Turbolift will retry...'
            raise exceptions.SystemProblem(message)
        elif resp is None:
            message[0] += 'No response information. Turbolift will retry...'
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 401:
            message[0] += (
                'Turbolift experienced an Authentication issue. Turbolift'
                ' will retry...'
            )
            self.job_args.update(auth.authenticate(self.job_args))
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 404:
            message[0] += 'Item not found.'
            LOG.debug(*message)
        elif resp.status_code == 409:
            message[0] += (
                'Request Conflict. Turbolift is abandoning this...'
            )
        elif resp.status_code == 413:
            return_headers = resp.headers
            retry_after = return_headers.get('retry_after', 10)
            cloud_utils.stupid_hack(wait=retry_after)
            message[0] += (
                'The System encountered an API limitation and will'
                ' continue in [ %s ] Seconds' % retry_after
            )
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 502:
            message[0] += (
                'Failure making Connection. Turbolift will retry...'
            )
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 503:
            cloud_utils.stupid_hack(wait=10)
            message[0] += 'SWIFT-API FAILURE'
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 504:
            cloud_utils.stupid_hack(wait=10)
            message[0] += 'Gateway Failure.'
            raise exceptions.SystemProblem(message)
        elif resp.status_code >= 300:
            message[0] += 'General exception.'
            raise exceptions.SystemProblem(message)
        else:
            LOG.debug(*message)
80106
def check_server(self):
        
        msg = 'API server not found. Please check your API url configuration.'

        try:
            response = self.session.head(self.domain)
        except Exception as e:
            raise_from(errors.ServerError(msg), e)

        try:
            self._check_response(response)
        except errors.NotFound as e:
            raise raise_from(errors.ServerError(msg), e)
850875
def throw_if_parsable(resp):
    
    e = None
    try:
        e = parse_response(resp)
    except:
        # Error occurred during parsing the response. We ignore it and delegate
        # the situation to caller to handle.
        LOG.debug(utils.stringify_expt())

    if e is not None:
        raise e

    if resp.status_code == 404:
        raise NoSuchObject('No such object.')
    else:
        text = resp.text if six.PY3 else resp.content
        if text:
            raise ODPSError(text, code=str(resp.status_code))
        else:
            raise ODPSError(str(resp.status_code))
1358120
def debug_application(self, environ, start_response):
        """"""
        app_iter = None
        try:
            app_iter = self.app(environ, start_response)
            for item in app_iter:
                yield item
            if hasattr(app_iter, 'close'):
                app_iter.close()
        except Exception:
            if hasattr(app_iter, 'close'):
                app_iter.close()

            context = RequestContext({'environ':dict(environ)})
            for injector in self.context_injectors:
                context.update(injector(environ))

            traceback = get_current_traceback(skip=1, show_hidden_frames=self.show_hidden_frames,
                                              context=context)
            for frame in traceback.frames:
                self.frames[frame.id] = frame
            self.tracebacks[traceback.id] = traceback

            try:
                start_response('500 INTERNAL SERVER ERROR', [
                    ('Content-Type', 'text/html; charset=utf-8'),
                    # Disable Chrome's XSS protection, the debug
                    # output can cause false-positives.
                    ('X-XSS-Protection', '0'),
                    ])
            except Exception:
                # if we end up here there has been output but an error
                # occurred.  in that situation we can do nothing fancy any
                # more, better log something into the error log and fall
                # back gracefully.
                environ['wsgi.errors'].write(
                    'Debugging middleware caught exception in streamed '
                    'response at a point where response headers were already '
                    'sent.\n')
            else:
                yield traceback.render_full(
                    evalex=self.evalex,
                    secret=self.secret
                ).encode('utf-8', 'replace')

            # This will lead to double logging in case backlash logger is set to DEBUG
            # but this is actually wanted as some environments, like WebTest, swallow
            # wsgi.environ making the traceback totally disappear.
            log.debug(traceback.plaintext)
            traceback.log(environ['wsgi.errors'])
491435
def _raise_exception(cls, reason, data=None):
    
    text_dict = {
        "error": reason
    }

    if data is not None:
        text_dict["errors"] = data

    raise cls(
        text=json.dumps(text_dict),
        content_type="application/json"
    )
742412
def on_view_not_found(
            self,
            environ: Dict[str, Any],
            start_response: Callable[[str, List[Tuple[str, str]]], None],
    ) -> Iterable[bytes]:
        
        start_response('404 Not Found', [('Content-type', 'text/plain')])
        return [b'Not found']
1317394
def _raise_for_status(response):
    '''
    
    '''
    http_error_msg = ""

    if 400 <= response.status_code < 500:
        http_error_msg = "{0} Client Error: {1}".format(response.status_code,
                                                        response.reason)

    elif 500 <= response.status_code < 600:
        http_error_msg = "{0} Server Error: {1}".format(response.status_code,
                                                        response.reason)

    if http_error_msg:
        try:
            more_info = response.json().get("message")
        except ValueError:
            more_info = None
        if more_info and more_info.lower() != response.reason.lower():
            http_error_msg += ".\n\t{0}".format(more_info)
        raise requests.exceptions.HTTPError(http_error_msg, response=response)
1216964
def not_found(cls, errors=None):
        
        if cls.expose_status:  # pragma: no cover
            cls.response.content_type = 'application/json'
            cls.response._status_line = '404 Not Found'

        return cls(404, None, errors).to_json
271477
def _raise_for_status(response):
    
    message = ''
    if 400 <= response.status < 500:
        message = '%s Client Error: %s' % (response.status, response.reason)
    elif 500 <= response.status < 600:
        message = '%s Server Error: %s' % (response.status, response.reason)
    else:
        return
    if response.status == 503:
        raise ConnectionError(message)
    if response.headers.get("content-type", "").startswith("application/json"):
        data = json.loads(response.data.decode('utf-8'))
        error = data.get('error', {})
        error_trace = data.get('error_trace', None)
        if "results" in data:
            errors = [res["error_message"] for res in data["results"]
                      if res.get("error_message")]
            if errors:
                raise ProgrammingError("\n".join(errors))
        if isinstance(error, dict):
            raise ProgrammingError(error.get('message', ''),
                                   error_trace=error_trace)
        raise ProgrammingError(error, error_trace=error_trace)
    raise ProgrammingError(message)
204209
def debug(self, value):
        
        self.__debug = value
        if self.__debug:
            # if debug status is True, turn on debug logging
            for _, logger in iteritems(self.logger):
                logger.setLevel(logging.DEBUG)
            # turn on httplib debug
            httplib.HTTPConnection.debuglevel = 1
        else:
            # if debug status is False, turn off debug logging,
            # setting log level to default `logging.WARNING`
            for _, logger in iteritems(self.logger):
                logger.setLevel(logging.WARNING)
            # turn off httplib debug
            httplib.HTTPConnection.debuglevel = 0
992282
def _handle_client_exception():
    
    try:
        yield

    except _ClientException as exception:
        if exception.http_status in _ERROR_CODES:
            raise _ERROR_CODES[exception.http_status](
                exception.http_reason)
        raise
604
def raise_not_found(self, environ, msg):
        
        raise NotFound(response=self.rewriterapp._error_response(environ, msg))
385667
def raise_exception(self, exception, tup=None):
        
        if tup:
            message = (
                "Python {exception_name} raised while processing Tuple "
                "{tup!r}\n{traceback}"
            )
        else:
            message = "Python {exception_name} raised\n{traceback}"
        message = message.format(
            exception_name=exception.__class__.__name__, tup=tup, traceback=format_exc()
        )
        self.send_message({"command": "error", "msg": str(message)})
        self.send_message({"command": "sync"})
92914
def enable_debug(self):
        """"""

        if not self.connected:
            raise HardwareError("Cannot enable debug if we are not in a connected state")

        self._loop.run_coroutine(self.adapter.open_interface(0, 'debug'))
720929
def api_exception(e):
    
    _, _, exc_traceback = sys.exc_info()
    tb = '\n'.join(traceback.format_tb(exc_traceback))
    return {
        400: BadRequestError,
        401: UnauthorizedError,
        403: ForbiddenError,
        404: NotFoundError,
        405: MethodNotAllowedError,
        409: ConflictError,
        410: GoneError,
        422: UnprocessibleEntityError,
        429: TooManyRequestsError,
        500: InternalServerError,
        503: ServiceUnavailableError,
        504: ServerTimeoutError,
    }.get(e.status, DynamicApiError)(e, tb)