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


Python Request.method方法代码示例

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


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

示例1: test_renderRealRequest

# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
 def test_renderRealRequest(self):
     """
     The request managed by L{WebSocketsResource.render} doesn't contain
     unnecessary HTTP headers like I{Content-Type} or I{Transfer-Encoding}.
     """
     channel = DummyChannel()
     channel.transport = StringTransportWithDisconnection()
     channel.transport.protocol = channel
     request = Request(channel, False)
     headers = {
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"}
     for key, value in headers.items():
         request.requestHeaders.setRawHeaders(key, [value])
     request.method = "GET"
     request.clientproto = "HTTP/1.1"
     result = self.resource.render(request)
     self.assertEqual(NOT_DONE_YET, result)
     self.assertEqual(
         [("Connection", ["Upgrade"]),
          ("Upgrade", ["WebSocket"]),
          ("Sec-Websocket-Accept", ["oYBv54i42V5dw6KnZqOFroecUTc="])],
         list(request.responseHeaders.getAllRawHeaders()))
     self.assertEqual(
         "HTTP/1.1 101 Switching Protocols\r\n"
         "Connection: Upgrade\r\n"
         "Upgrade: WebSocket\r\n"
         "Sec-Websocket-Accept: oYBv54i42V5dw6KnZqOFroecUTc=\r\n\r\n",
         channel.transport.value())
     self.assertEqual(101, request.code)
     self.assertIdentical(None, request.transport)
开发者ID:codecats,项目名称:kitty,代码行数:35,代码来源:test_websockets.py

示例2: test_redirectToUnicodeURL

# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
 def test_redirectToUnicodeURL(self) :
     """
     L{redirectTo} will raise TypeError if unicode object is passed in URL
     """
     request = Request(DummyChannel(), True)
     request.method = b'GET'
     targetURL = u'http://target.example.com/4321'
     self.assertRaises(TypeError, redirectTo, targetURL, request)
开发者ID:daweasel27,项目名称:PhobiaEnemy,代码行数:10,代码来源:test_util.py

示例3: makeRequest

# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def makeRequest(method, path, post_data=None):
    req = Request(FakeChannel(), None)
    req.prepath = req.postpath = None
    req.method = method
    req.path = path
    req.content = StringIO(post_data)
    resource = site.getChildWithDefault(path, req)
    return resource.render(req)
开发者ID:adcaes,项目名称:eventer_api,代码行数:10,代码来源:make_request.py

示例4: test_requestFeature

# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
    def test_requestFeature(self):
        self.log.addFeature(request)
        req = Request(DummyChannel(), False)
        req.method = 'GET'
        req.uri = '/foo'

        self.log.request(req).info('handling request')
        self.assertIn('method=GET', self.out.getvalue())
        self.assertIn('uri=/foo', self.out.getvalue())
开发者ID:dreid,项目名称:twixxy,代码行数:11,代码来源:test_features.py

示例5: test_error_in_read_function

# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [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'))
开发者ID:DmitryLoki,项目名称:gorynych,代码行数:13,代码来源:test_base_resource.py

示例6: get_request

# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
    def get_request(self, method, uri, clientproto, headers, data, response):
        self.transport = response.transport

        r = Request(self, False)
        r.method = method
        r.clientproto = clientproto
        r.path = uri
        r.client = response.client
        r.host = self.host
        r.prepath = []
        r.postpath = map(unquote, string.split(r.path[1:], "/"))
        r.content = StringIO.StringIO(data)
        r.transport = response.transport

        return r
开发者ID:isotoma,项目名称:badgerproxy,代码行数:17,代码来源:internalproxy.py

示例7: test_headersAndCode

# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
 def test_headersAndCode(self):
     """
     L{redirectTo} will set the C{Location} and C{Content-Type} headers on
     its request, and set the response code to C{FOUND}, so the browser will
     be redirected.
     """
     request = Request(DummyChannel(), True)
     request.method = b'GET'
     targetURL = b"http://target.example.com/4321"
     redirectTo(targetURL, request)
     self.assertEqual(request.code, FOUND)
     self.assertEqual(
         request.responseHeaders.getRawHeaders(b'location'), [targetURL])
     self.assertEqual(
         request.responseHeaders.getRawHeaders(b'content-type'),
         [b'text/html; charset=utf-8'])
开发者ID:daweasel27,项目名称:PhobiaEnemy,代码行数:18,代码来源:test_util.py

示例8: getRequest

# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def getRequest(method, url):
    req = Request(FakeChannel(), None)
    req.method = method
    req.path = url
    return req
开发者ID:baloo,项目名称:txrestapi,代码行数:7,代码来源:tests.py

示例9: test_resource_renderer

# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
 def test_resource_renderer(self):
     req = Request(DummyChannel(), 1)
     req.method = 'GET'
     result, body = self.api.resource_renderer('res', req)
     self.assertEqual(result.code, 200)
     self.assertEqual(body, 'res::SimpleAPIResource')
开发者ID:DmitryLoki,项目名称:gorynych,代码行数:8,代码来源:test_base_resource.py


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