当前位置: 首页>>代码示例>>Python>>正文


Python wsgi.STATUS_CODE_TEXT类代码示例

本文整理汇总了Python中django.core.handlers.wsgi.STATUS_CODE_TEXT的典型用法代码示例。如果您正苦于以下问题:Python STATUS_CODE_TEXT类的具体用法?Python STATUS_CODE_TEXT怎么用?Python STATUS_CODE_TEXT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了STATUS_CODE_TEXT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, node=None, status=503, description=''):
     HttpResponse.__init__(self, status=status)
     Exception.__init__(self)
     self.message = (STATUS_CODE_TEXT.get(status, 'Error %s' % status) +
                     '\n' + (description or ''))
     self.__node = node
     self.payload = {'error': STATUS_CODE_TEXT.get(status),
                     'description': description}
开发者ID:mohamedattahri,项目名称:Nuages,代码行数:8,代码来源:__init__.py

示例2: generate_docs_from_configuration

    def generate_docs_from_configuration(self, configuration):
        docs = []
        for c in configuration:
            if c[-1]:
                conf_value = c[-1].get('request_data', {})
                if callable(conf_value):
                    request_data = conf_value.__name__
                else:
                    request_data = conf_value
                comment = c[-1].get('comment', None)
            else:
                comment = None
                request_data = {}
            doc = '%(method)s %(url)s %(status_code)s "%(status)s" ' \
                  '%(request_data)r' % {
                            'method': c[2],
                            'url': c[0],
                            'status_code': c[1],
                            'status': STATUS_CODE_TEXT.get(c[1], 'UNKNOWN'),
                            'request_data': request_data
                        }
            if comment:
                doc = '%s %s' % (doc, comment)
            docs.append(doc)

        return docs
开发者ID:yunmanger1,项目名称:django-skd-smoke,代码行数:26,代码来源:tests.py

示例3: get_context

 def get_context(self):
     return {
         'message': self.message,
         'http_status_code': self.status_code,
         'http_status_text': STATUS_CODE_TEXT.get(self.status_code, 'UNKNOWN'),
         'http_exception': self,
     }
开发者ID:luzfcb,项目名称:django-perm,代码行数:7,代码来源:http.py

示例4: __new__

    def __new__(mcs, name, bases, attrs):
        cls = super(GenerateTestMethodsMeta, mcs).__new__(
            mcs, name, bases, attrs)

        # If this metaclass is instantiating something found in one of these modules
        # then we skip generation of test cases, etc.  Without this, we will erroneously
        # detect error case of TESTS_CONFIGURATION being None
        # Also, skip certain classes based on class name
        skip_modules = ['skd_smoke', ]
        skip_names = ['NewBase', 'SmokeTestCase', ]
        if attrs.get('__module__') in skip_modules or name in skip_names:
            return cls

        # Build a dict of all the 'defaults' they defined to go with their test class
        defined_defaults = {}
        for defaultable in DEFAULTABLE_PARAMS:
            attr_name = "default_" + defaultable
            if hasattr(cls, attr_name):
                defined_defaults[attr_name] = getattr(cls, attr_name)

        # noinspection PyBroadException
        try:
            config = prepare_configuration(cls.TESTS_CONFIGURATION, defined_defaults)
        except Exception:
            fail_method = generate_fail_test_method(traceback.format_exc())
            fail_method_name = cls.FAIL_METHOD_NAME
            fail_method.__name__ = str(fail_method_name)

            setattr(cls, fail_method_name, fail_method)
        else:
            for urlname, status, method, data in config:
                # For each config item, if it doesnt exist in config tuple's "data" then
                # see if user has defined a default on the test class
                find_conf = lambda name: data.get(name, getattr(cls, "default_" + name, None))

                comment = find_conf('comment')
                initialize = find_conf('initialize')
                url_args = find_conf('url_args')
                url_kwargs = find_conf('url_kwargs')
                request_data = find_conf('request_data')
                get_user_credentials = find_conf('user_credentials')
                redirect_to = find_conf('redirect_to')
                status_text = STATUS_CODE_TEXT.get(status, 'UNKNOWN')

                test_method_name = prepare_test_name(urlname, method, status)

                test_method = generate_test_method(
                    urlname, status, method, initialize, url_args, url_kwargs,
                    request_data, get_user_credentials, redirect_to
                )
                test_method.__name__ = str(test_method_name)
                test_method.__doc__ = prepare_test_method_doc(
                    method, urlname, status, status_text, request_data,
                    comment
                )

                setattr(cls, test_method_name, test_method)

        return cls
开发者ID:wahuneke,项目名称:django-skd-smoke,代码行数:59,代码来源:__init__.py

示例5: status_text

 def status_text(self):
     """
     Returns reason text corresponding to our HTTP response status code.
     Provided for convenience.
     """
     # TODO: Deprecate and use a template tag instead
     # TODO: Status code text for RFC 6585 status codes
     return STATUS_CODE_TEXT.get(self.status_code, '')
开发者ID:cubettech,项目名称:taiga-back,代码行数:8,代码来源:response.py

示例6: request

    def request(self, host, handler, request_body, verbose=0):
        self.verbose = verbose
        response = self.client.post(handler, request_body, content_type="text/xml")
        
        status_code, msg, headers = response.status_code, STATUS_CODE_TEXT.get(response.status_code, str(response.status_code)), response.items()

        if response.status_code != 200:
            raise ProtocolError(host + handler, status_code, msg, headers)
        
        return self._parse_response(response.content, None)
开发者ID:hasadna,项目名称:django-backlinks,代码行数:10,代码来源:xmlrpc.py

示例7: do_render

 def do_render(template=None):
     if template:
         template = 'http_responses/%s.html' % (template,)
     else:
         template = 'http_responses/%i.html' % (exception.http_code, ),
     return self.render(
         request,
         template,
         {
             'http_code': exception.http_code,
             'http_message': STATUS_CODE_TEXT.get(exception.http_code, 'UNKNOWN'), # TRANSLATE IN TEMPLATE
             'http_response_exception': exception,
         }
     )
开发者ID:jaylett,项目名称:django_exceptional_middleware,代码行数:14,代码来源:middleware.py

示例8: process_response

 def process_response(self, request, response):
     if 300 <= int(response.status_code) < 400:
         redirect_to = response.get('Location', None)
         if redirect_to:
             try:        # Django >= 1.6
                 reason_phrase = response.reason_phrase
             except AttributeError:
                 reason_phrase = STATUS_CODE_TEXT.get(response.status_code,
                                                      'UNKNOWN STATUS CODE')
             status_line = '%s %s' % (response.status_code, reason_phrase)
             cookies = response.cookies
             context = {'redirect_to': redirect_to, 'status_line': status_line}
             response = render_to_response('debug_toolbar/redirect.html', context)
             response.cookies = cookies
     return response
开发者ID:AayushU,项目名称:osqa,代码行数:15,代码来源:redirects.py

示例9: __new__

    def __new__(mcs, name, bases, attrs):
        cls = super(GenerateTestMethodsMeta, mcs).__new__(
            mcs, name, bases, attrs)

        # Ensure test method generation is only performed for subclasses of
        # GenerateTestMethodsMeta (excluding GenerateTestMethodsMeta class
        # itself).
        parents = [b for b in bases if isinstance(b, GenerateTestMethodsMeta)]
        if not parents:
            return cls

        # noinspection PyBroadException
        try:
            config = prepare_configuration(cls.TESTS_CONFIGURATION)
        except Exception:
            fail_method = generate_fail_test_method(traceback.format_exc())
            fail_method_name = cls.FAIL_METHOD_NAME
            fail_method.__name__ = str(fail_method_name)

            setattr(cls, fail_method_name, fail_method)
        else:
            for urlname, status, method, data in config:
                comment = data.get('comment', None)
                initialize = data.get('initialize', None)
                url_args = data.get('url_args', None)
                url_kwargs = data.get('url_kwargs', None)
                request_data = data.get('request_data', None)
                get_user_credentials = data.get('user_credentials', None)
                redirect_to = data.get('redirect_to', None)
                status_text = STATUS_CODE_TEXT.get(status, 'UNKNOWN')

                test_method_name = prepare_test_name(urlname, method, status)

                test_method = generate_test_method(
                    urlname, status, method, initialize, url_args, url_kwargs,
                    request_data, get_user_credentials, redirect_to
                )
                test_method.__name__ = str(test_method_name)
                test_method.__doc__ = prepare_test_method_doc(
                    method, urlname, status, status_text, request_data,
                    comment
                )

                setattr(cls, test_method_name, test_method)

        return cls
开发者ID:NatashaMik,项目名称:django-skd-smoke,代码行数:46,代码来源:__init__.py

示例10: AttrDict

from django.core.handlers.wsgi import STATUS_CODE_TEXT
from restlib2.structures import AttrDict

# New codes - http://tools.ietf.org/html/draft-nottingham-http-new-status-04
STATUS_CODE_TEXT.setdefault(422, 'UNPROCESSABLE ENTITY')
STATUS_CODE_TEXT.setdefault(428, 'PRECONDITION REQUIRED')
STATUS_CODE_TEXT.setdefault(429, 'TOO MANY REQUESTS')
STATUS_CODE_TEXT.setdefault(431, 'REQUEST HEADER FIELDS TOO LARGE')
STATUS_CODE_TEXT.setdefault(511, 'NETWORK AUTHENTICATION REQUIRED')

# Invert dict for reference by name
codes = AttrDict('HTTP Status Codes', [
    (y.lower().replace(' ', '_'), x) for x, y in STATUS_CODE_TEXT.items()
])


# PATCH Method introduced - http://tools.ietf.org/html/rfc5789
methods = AttrDict('HTTP Methods',
    GET = 'GET',
    HEAD = 'HEAD',
    OPTIONS = 'OPTIONS',
    POST = 'POST',
    PUT = 'PUT',
    DELETE = 'DELETE',
    PATCH = 'PATCH',
)
开发者ID:jessethegame,项目名称:restlib2,代码行数:26,代码来源:__init__.py

示例11: status_text

 def status_text(self):
     """
     Return reason text corresponding to our HTTP response status code.
     Provided for convenience.
     """
     return STATUS_CODE_TEXT.get(self.status, '')
开发者ID:Audish,项目名称:django-rest-framework,代码行数:6,代码来源:response.py

示例12: HttpResponse

                        redis_store.publish_message(message)
                    elif fd == redis_fd:
                        response = redis_store.parse_response()
                        if response[0] == 'message':
                            message = response[2]
                            websocket.send(message)
                    else:
                        logger.error('Invalid file descriptor: {0}'.format(fd))
        except WebSocketError, excpt:
            logger.warning('WebSocketError: ', exc_info=sys.exc_info())
            response = HttpResponse(status=1001, content='Websocket Closed')
        except UpgradeRequiredError:
            logger.info('Websocket upgrade required')
            response = HttpResponseBadRequest(status=426, content=excpt)
        except HandshakeError, excpt:
            logger.warning('HandshakeError: ', exc_info=sys.exc_info())
            response = HttpResponseBadRequest(content=excpt)
        except Exception, excpt:
            logger.error('Other Exception: ', exc_info=sys.exc_info())
            response = HttpResponseServerError(content=excpt)
        else:
            response = HttpResponse()
        if websocket:
            redis_store.unsubscribe(request, access_key)
            websocket.close(code=1001, message='Websocket Closed')
        if hasattr(start_response, 'im_self') and not start_response.im_self.headers_sent:
            status_text = STATUS_CODE_TEXT.get(response.status_code, 'UNKNOWN STATUS CODE')
            status = '{0} {1}'.format(response.status_code, status_text)
            start_response(force_str(status), response._headers.values())
        return response
开发者ID:Jacob45,项目名称:liveeverfit,代码行数:30,代码来源:wsgi_server.py

示例13: __init__

 def __init__(self, node=None, status=503, description=''):
     HttpResponse.__init__(self, status=status)
     Exception.__init__(self)
     self.message = description or STATUS_CODE_TEXT.get(status)
     self.__node = node
     self.content = str(self)
开发者ID:dotpot,项目名称:Nuages,代码行数:6,代码来源:__init__.py

示例14: __call__

 def __call__(self, environ, start_response):
     """ Hijack the main loop from the original thread and listen on events on Redis and Websockets"""
     websocket = None
     request = None
     subscriber = self.Subscriber(self._redis_connection)
     try:
         self.assure_protocol_requirements(environ)
         request = WSGIRequest(environ)
         self.process_request(request)
         channels, echo_message = self.process_subscriptions(request)
         if callable(private_settings.WS4REDIS_ALLOWED_CHANNELS):
             channels = list(private_settings.WS4REDIS_ALLOWED_CHANNELS(request, channels))
         websocket = self.upgrade_websocket(environ, start_response)
         logger.debug('Subscribed to channels: {0}'.format(', '.join(channels)))
         subscriber.set_pubsub_channels(request, channels)
         subscriber.user_connect(request)
         websocket_fd = websocket.get_file_descriptor()
         listening_fds = [websocket_fd]
         redis_fd = subscriber.get_file_descriptor()
         if redis_fd:
             listening_fds.append(redis_fd)
         subscriber.send_persited_messages(websocket)
         recvmsg = None
         while websocket and not websocket.closed:
             ready = self.select(listening_fds, [], [], 4.0)[0]
             if not ready:
                 # flush empty socket
                 websocket.flush()
             for fd in ready:
                 if fd == websocket_fd:
                     recvmsg = RedisMessage(websocket.receive())
                     if recvmsg:
                         subscriber.publish_message(recvmsg)
                 elif fd == redis_fd:
                     sendmsg = RedisMessage(subscriber.parse_response())
                     if sendmsg and (echo_message or sendmsg != recvmsg):
                         websocket.send(sendmsg)
                 else:
                     logger.error('Invalid file descriptor: {0}'.format(fd))
             if private_settings.WS4REDIS_HEARTBEAT:
                 websocket.send(private_settings.WS4REDIS_HEARTBEAT)
     except WebSocketError as excpt:
         logger.warning('WebSocketError: ', exc_info=sys.exc_info())
         response = http.HttpResponse(status=1001, content='Websocket Closed')
     except UpgradeRequiredError as excpt:
         logger.info('Websocket upgrade required')
         response = http.HttpResponseBadRequest(status=426, content=excpt)
     except HandshakeError as excpt:
         logger.warning('HandshakeError: ', exc_info=sys.exc_info())
         response = http.HttpResponseBadRequest(content=excpt)
     except PermissionDenied as excpt:
         logger.warning('PermissionDenied: ', exc_info=sys.exc_info())
         response = http.HttpResponseForbidden(content=excpt)
     except Exception as excpt:
         logger.error('Other Exception: ', exc_info=sys.exc_info())
         response = http.HttpResponseServerError(content=excpt)
     else:
         response = http.HttpResponse()
     if websocket:
         subscriber.user_disconnect(request)
         websocket.close(code=1001, message='Websocket Closed')
     if hasattr(start_response, 'im_self') and not start_response.im_self.headers_sent:
         logger.warning('Staring late response on websocket')
         status_text = STATUS_CODE_TEXT.get(response.status_code, 'UNKNOWN STATUS CODE')
         status = '{0} {1}'.format(response.status_code, status_text)
         start_response(force_str(status), response._headers.values())
     logger.info('Finish long living response with status code: '.format(response.status_code))
     return response
开发者ID:hoanghua,项目名称:django-websocket-redis,代码行数:68,代码来源:wsgi_server.py

示例15: raise_http_error

def raise_http_error(url, code):
    raise HTTPError(url, code, STATUS_CODE_TEXT.get(code, ''), None, None)
开发者ID:hasadna,项目名称:django-backlinks,代码行数:2,代码来源:mock.py


注:本文中的django.core.handlers.wsgi.STATUS_CODE_TEXT类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。