本文整理汇总了Python中twisted.web.server.Request.setResponseCode方法的典型用法代码示例。如果您正苦于以下问题:Python Request.setResponseCode方法的具体用法?Python Request.setResponseCode怎么用?Python Request.setResponseCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.server.Request
的用法示例。
在下文中一共展示了Request.setResponseCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handle_error
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import setResponseCode [as 别名]
def test_handle_error(self):
import json
request = Request(DummyChannel(), 1)
request.gotLength(0)
self.api_resource.write_request = mock.Mock()
result = self.api_resource._handle_error(request,
500, 'Error', 'Big mistake')
request.setResponseCode(500)
body = json.dumps({'error': 'Error', 'message': 'Big mistake'})
self.api_resource.write_request.assert_called_with((request, body))
示例2: test_error_in_read_function
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import setResponseCode [as 别名]
def test_error_in_read_function(self):
req = Request(DummyChannel(), 1)
req.setResponseCode(200)
req.method = 'GET'
def error_function(a, b):
raise Exception("boom")
self.api.read_GET = error_function
self.api._handle_error = mock.Mock()
result, body = self.api.resource_renderer('res', req)
self.api._handle_error.assert_called_with(req, 500, "ReadError",
"Error %r in resource reading function." % Exception('boom'))
示例3: setResponseCode
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import setResponseCode [as 别名]
def setResponseCode(self, code, message):
invoked.append(get_ident())
return Request.setResponseCode(self, code, message)