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


Python cherrypy.response方法代码示例

本文整理汇总了Python中cherrypy.response方法的典型用法代码示例。如果您正苦于以下问题:Python cherrypy.response方法的具体用法?Python cherrypy.response怎么用?Python cherrypy.response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cherrypy的用法示例。


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

示例1: clean_headers

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def clean_headers(status):
    """Remove any headers which should not apply to an error response."""
    response = cherrypy.serving.response

    # Remove headers which applied to the original content,
    # but do not apply to the error page.
    respheaders = response.headers
    for key in ['Accept-Ranges', 'Age', 'ETag', 'Location', 'Retry-After',
                'Vary', 'Content-Encoding', 'Content-Length', 'Expires',
                'Content-Location', 'Content-MD5', 'Last-Modified']:
        if key in respheaders:
            del respheaders[key]

    if status != 416:
        # A server sending a response with status code 416 (Requested
        # range not satisfiable) SHOULD include a Content-Range field
        # with a byte-range-resp-spec of "*". The instance-length
        # specifies the current length of the selected resource.
        # A response with status code 206 (Partial Content) MUST NOT
        # include a Content-Range field with a byte-range- resp-spec of "*".
        if 'Content-Range' in respheaders:
            del respheaders['Content-Range'] 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:24,代码来源:_cperror.py

示例2: set_response

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def set_response(self):
        """Modify cherrypy.response status, headers, and body to represent
        self.

        CherryPy uses this internally, but you can also use it to create an
        HTTPError object and set its output without *raising* the exception.
        """
        response = cherrypy.serving.response

        clean_headers(self.code)

        # In all cases, finalize will be called after this method,
        # so don't bother cleaning up response values here.
        response.status = self.status
        tb = None
        if cherrypy.serving.request.show_tracebacks:
            tb = format_exc()

        response.headers.pop('Content-Length', None)

        content = self.get_error_page(self.status, traceback=tb,
                                      message=self._message)
        response.body = content

        _be_ie_unfriendly(self.code) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:27,代码来源:_cperror.py

示例3: _be_ie_unfriendly

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def _be_ie_unfriendly(status):
    response = cherrypy.serving.response

    # For some statuses, Internet Explorer 5+ shows "friendly error
    # messages" instead of our response.body if the body is smaller
    # than a given size. Fix this by returning a body over that size
    # (by adding whitespace).
    # See http://support.microsoft.com/kb/q218155/
    s = _ie_friendly_error_sizes.get(status, 0)
    if s:
        s += 1
        # Since we are issuing an HTTP error status, we assume that
        # the entity is short, and we should just collapse it.
        content = response.collapse_body()
        content_length = len(content)
        if content_length and content_length < s:
            # IN ADDITION: the response must be written to IE
            # in one chunk or it will still get replaced! Bah.
            content = content + (b' ' * (s - content_length))
        response.body = content
        response.headers['Content-Length'] = str(len(content)) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:23,代码来源:_cperror.py

示例4: _populate_known_types

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def _populate_known_types(self):
        b = [x for x in vars(builtins).values()
             if type(x) is type(str)]

        def traverse(obj, namespace):
            for name in dir(obj):
                # Hack for 3.2's warning about body_params
                if name == 'body_params':
                    continue
                vtype = type(getattr(obj, name, None))
                if vtype in b:
                    self.known_config_types[namespace + '.' + name] = vtype

        traverse(cherrypy.request, 'request')
        traverse(cherrypy.response, 'response')
        traverse(cherrypy.server, 'server')
        traverse(cherrypy.engine, 'engine')
        traverse(cherrypy.log, 'log') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:20,代码来源:_cpchecker.py

示例5: run_standard_benchmarks

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def run_standard_benchmarks():
    print('')
    print('Client Thread Report (1000 requests, 14 byte response body, '
          '%s server threads):' % cherrypy.server.thread_pool)
    print_report(thread_report())

    print('')
    print('Client Thread Report (1000 requests, 14 bytes via staticdir, '
          '%s server threads):' % cherrypy.server.thread_pool)
    print_report(thread_report('%s/static/index.html' % SCRIPT_NAME))

    print('')
    print('Size Report (1000 requests, 50 client threads, '
          '%s server threads):' % cherrypy.server.thread_pool)
    print_report(size_report())


#                         modpython and other WSGI                         # 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:20,代码来源:benchmark.py

示例6: clean_headers

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def clean_headers(status):
    """Remove any headers which should not apply to an error response."""
    import cherrypy

    response = cherrypy.serving.response

    # Remove headers which applied to the original content,
    # but do not apply to the error page.
    respheaders = response.headers
    for key in ["Accept-Ranges", "Age", "ETag", "Location", "Retry-After",
                "Vary", "Content-Encoding", "Content-Length", "Expires",
                "Content-Location", "Content-MD5", "Last-Modified"]:
        if key in respheaders:
            del respheaders[key]

    if status != 416:
        # A server sending a response with status code 416 (Requested
        # range not satisfiable) SHOULD include a Content-Range field
        # with a byte-range-resp-spec of "*". The instance-length
        # specifies the current length of the selected resource.
        # A response with status code 206 (Partial Content) MUST NOT
        # include a Content-Range field with a byte-range- resp-spec of "*".
        if "Content-Range" in respheaders:
            del respheaders["Content-Range"] 
开发者ID:naparuba,项目名称:opsbro,代码行数:26,代码来源:_cperror.py

示例7: _be_ie_unfriendly

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def _be_ie_unfriendly(status):
    import cherrypy
    response = cherrypy.serving.response

    # For some statuses, Internet Explorer 5+ shows "friendly error
    # messages" instead of our response.body if the body is smaller
    # than a given size. Fix this by returning a body over that size
    # (by adding whitespace).
    # See http://support.microsoft.com/kb/q218155/
    s = _ie_friendly_error_sizes.get(status, 0)
    if s:
        s += 1
        # Since we are issuing an HTTP error status, we assume that
        # the entity is short, and we should just collapse it.
        content = response.collapse_body()
        l = len(content)
        if l and l < s:
            # IN ADDITION: the response must be written to IE
            # in one chunk or it will still get replaced! Bah.
            content = content + (ntob(" ") * (s - l))
        response.body = content
        response.headers['Content-Length'] = str(len(content)) 
开发者ID:naparuba,项目名称:opsbro,代码行数:24,代码来源:_cperror.py

示例8: clean_headers

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def clean_headers(status):
    """Remove any headers which should not apply to an error response."""
    import cherrypy

    response = cherrypy.serving.response

    # Remove headers which applied to the original content,
    # but do not apply to the error page.
    respheaders = response.headers
    for key in ['Accept-Ranges', 'Age', 'ETag', 'Location', 'Retry-After',
                'Vary', 'Content-Encoding', 'Content-Length', 'Expires',
                'Content-Location', 'Content-MD5', 'Last-Modified']:
        if key in respheaders:
            del respheaders[key]

    if status != 416:
        # A server sending a response with status code 416 (Requested
        # range not satisfiable) SHOULD include a Content-Range field
        # with a byte-range-resp-spec of "*". The instance-length
        # specifies the current length of the selected resource.
        # A response with status code 206 (Partial Content) MUST NOT
        # include a Content-Range field with a byte-range- resp-spec of "*".
        if 'Content-Range' in respheaders:
            del respheaders['Content-Range'] 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:26,代码来源:_cperror.py

示例9: _be_ie_unfriendly

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def _be_ie_unfriendly(status):
    import cherrypy
    response = cherrypy.serving.response

    # For some statuses, Internet Explorer 5+ shows "friendly error
    # messages" instead of our response.body if the body is smaller
    # than a given size. Fix this by returning a body over that size
    # (by adding whitespace).
    # See http://support.microsoft.com/kb/q218155/
    s = _ie_friendly_error_sizes.get(status, 0)
    if s:
        s += 1
        # Since we are issuing an HTTP error status, we assume that
        # the entity is short, and we should just collapse it.
        content = response.collapse_body()
        l = len(content)
        if l and l < s:
            # IN ADDITION: the response must be written to IE
            # in one chunk or it will still get replaced! Bah.
            content = content + (ntob(' ') * (s - l))
        response.body = content
        response.headers['Content-Length'] = str(len(content)) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:24,代码来源:_cperror.py

示例10: clean_headers

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def clean_headers(status):
    """Remove any headers which should not apply to an error response."""
    import cherrypy
    
    response = cherrypy.serving.response
    
    # Remove headers which applied to the original content,
    # but do not apply to the error page.
    respheaders = response.headers
    for key in ["Accept-Ranges", "Age", "ETag", "Location", "Retry-After",
                "Vary", "Content-Encoding", "Content-Length", "Expires",
                "Content-Location", "Content-MD5", "Last-Modified"]:
        if key in respheaders:
            del respheaders[key]
    
    if status != 416:
        # A server sending a response with status code 416 (Requested
        # range not satisfiable) SHOULD include a Content-Range field
        # with a byte-range-resp-spec of "*". The instance-length
        # specifies the current length of the selected resource.
        # A response with status code 206 (Partial Content) MUST NOT
        # include a Content-Range field with a byte-range- resp-spec of "*".
        if "Content-Range" in respheaders:
            del respheaders["Content-Range"] 
开发者ID:binhex,项目名称:moviegrabber,代码行数:26,代码来源:_cperror.py

示例11: _populate_known_types

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def _populate_known_types(self):
        b = [x for x in vars(builtins).values()
             if type(x) is type(str)]
        
        def traverse(obj, namespace):
            for name in dir(obj):
                # Hack for 3.2's warning about body_params
                if name == 'body_params':
                    continue
                vtype = type(getattr(obj, name, None))
                if vtype in b:
                    self.known_config_types[namespace + "." + name] = vtype
        
        traverse(cherrypy.request, "request")
        traverse(cherrypy.response, "response")
        traverse(cherrypy.server, "server")
        traverse(cherrypy.engine, "engine")
        traverse(cherrypy.log, "log") 
开发者ID:binhex,项目名称:moviegrabber,代码行数:20,代码来源:_cpchecker.py

示例12: run_standard_benchmarks

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def run_standard_benchmarks():
    print("")
    print("Client Thread Report (1000 requests, 14 byte response body, "
           "%s server threads):" % cherrypy.server.thread_pool)
    print_report(thread_report())
    
    print("")
    print("Client Thread Report (1000 requests, 14 bytes via staticdir, "
           "%s server threads):" % cherrypy.server.thread_pool)
    print_report(thread_report("%s/static/index.html" % SCRIPT_NAME))
    
    print("")
    print("Size Report (1000 requests, 50 client threads, "
           "%s server threads):" % cherrypy.server.thread_pool)
    print_report(size_report())


#                         modpython and other WSGI                         # 
开发者ID:binhex,项目名称:moviegrabber,代码行数:20,代码来源:benchmark.py

示例13: default_status

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def default_status(cls):
        """
        The default redirect status for the request.

        RFC 2616 indicates a 301 response code fits our goal; however,
        browser support for 301 is quite messy. Use 302/303 instead. See
        http://www.alanflavell.org.uk/www/post-redirect.html
        """
        return 303 if cherrypy.serving.request.protocol >= (1, 1) else 302 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:11,代码来源:_cperror.py

示例14: respond

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def respond(body, encoding='utf-8', allow_none=0):
    """Construct HTTP response body."""
    if not isinstance(body, XMLRPCFault):
        body = (body,)

    _set_response(
        xmlrpc_dumps(
            body, methodresponse=1,
            encoding=encoding,
            allow_none=allow_none
        )
    ) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:14,代码来源:xmlrpcutil.py

示例15: on_error

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import response [as 别名]
def on_error(*args, **kwargs):
    """Construct HTTP response body for an error response."""
    body = str(sys.exc_info()[1])
    _set_response(xmlrpc_dumps(XMLRPCFault(1, body))) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:6,代码来源:xmlrpcutil.py


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