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


Python Response.headers['Server']方法代码示例

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


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

示例1: __call__

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['Server'] [as 别名]
    def __call__(self, request):
        """Processes and dispatches the request"""
        if request.method != 'POST':
            return httpexceptions.HTTPMethodNotAllowed(['POST'])
        
        body = request.body
        stream = None
        timezone_offset = self._get_timezone_offset()

        # Decode the request
        try:
            amf_request = remoting.decode(body, strict=self.strict,
                                          logger=self.logger, 
                                          timezone_offset=timezone_offset)
        except (pyamf.DecodeError, IOError):
            if self.logger:
                self.logger.exception('Error decoding AMF request')

            response = "400 Bad Request\n\nThe request body was unable to " \
                "be successfully decoded."

            if self.debug:
                response += "\n\nTraceback:\n\n%s" % gateway.format_exception()
            return httpexceptions.HTTPBadRequest(detail=response)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            if self.logger:
                self.logger.exception('Unexpected error decoding AMF request')

            response = ("500 Internal Server Error\n\nAn unexpected error "
                "occurred whilst decoding.")

            if self.debug:
                response += "\n\nTraceback:\n\n%s" % gateway.format_exception()
            return httpexceptions.HTTPInternalServerError(detail=response)

        if self.logger:
            self.logger.debug("AMF Request: %r" % amf_request)

        # Process the request
        try:
            response = self.getResponse(request, amf_request)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            if self.logger:
                self.logger.exception('Error processing AMF request')

            response = ("500 Internal Server Error\n\nThe request was "
                "unable to be successfully processed.")

            if self.debug:
                response += "\n\nTraceback:\n\n%s" % gateway.format_exception()
            
            return httpexceptions.HTTPInternalServerError(detail=response)

        if self.logger:
            self.logger.debug("AMF Response: %r" % response)

        # Encode the response
        try:
            stream = remoting.encode(response, strict=self.strict,
                timezone_offset=timezone_offset)
        except:
            if self.logger:
                self.logger.exception('Error encoding AMF request')

            response = ("500 Internal Server Error\n\nThe request was "
                "unable to be encoded.")

            if self.debug:
                response += "\n\nTraceback:\n\n%s" % gateway.format_exception()
            
            return httpexceptions.HTTPInternalServerError(detail=response)

        buf = stream.getvalue()
        
        http_response = Response(content_type=remoting.CONTENT_TYPE)
        http_response.headers['Server'] = gateway.SERVER_NAME
        http_response.write(buf)
        return http_response
开发者ID:kabhinav,项目名称:pyramid_rpc,代码行数:84,代码来源:amfgateway.py


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