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


Python DummyRequest.requestHeaders方法代码示例

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


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

示例1: test_renderIProtocol

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
    def test_renderIProtocol(self):
        """
        If the protocol returned by C{lookupProtocol} isn't a
        C{WebSocketsProtocol}, L{WebSocketsResource} wraps it automatically
        with L{WebSocketsProtocolWrapper}.
        """

        def lookupProtocol(names, otherRequest):
            return AccumulatingProtocol(), None

        self.resource = WebSocketsResource(lookupProtocol)

        request = DummyRequest("/")
        request.requestHeaders = Headers()
        transport = StringTransportWithDisconnection()
        transport.protocol = Protocol()
        request.transport = transport
        request.headers.update({
            "upgrade": "Websocket",
            "connection": "Upgrade",
            "sec-websocket-key": "secure",
            "sec-websocket-version": "13"})
        result = self.resource.render(request)
        self.assertEqual(NOT_DONE_YET, result)
        self.assertIsInstance(transport.protocol, WebSocketsProtocolWrapper)
        self.assertIsInstance(transport.protocol.wrappedProtocol,
                              AccumulatingProtocol)
开发者ID:codecats,项目名称:kitty,代码行数:29,代码来源:test_websockets.py

示例2: test_renderSecureRequest

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
 def test_renderSecureRequest(self):
     """
     When the rendered request is over HTTPS, L{WebSocketsResource} wraps
     the protocol of the C{TLSMemoryBIOProtocol} instance.
     """
     request = DummyRequest("/")
     request.requestHeaders = Headers()
     transport = StringTransportWithDisconnection()
     secureProtocol = TLSMemoryBIOProtocol(Factory(), Protocol())
     transport.protocol = secureProtocol
     request.transport = transport
     request.headers.update({
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"})
     result = self.resource.render(request)
     self.assertEqual(NOT_DONE_YET, result)
     self.assertEqual(
         {"connection": "Upgrade",
          "upgrade": "WebSocket",
          "sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
         request.outgoingHeaders)
     self.assertEqual([""], request.written)
     self.assertEqual(101, request.responseCode)
     self.assertIdentical(None, request.transport)
     self.assertIsInstance(
         transport.protocol.wrappedProtocol, WebSocketsProtocol)
     self.assertIsInstance(
         transport.protocol.wrappedProtocol._receiver,
         SavingEchoReceiver)
开发者ID:codecats,项目名称:kitty,代码行数:33,代码来源:test_websockets.py

示例3: test_renderProtocol

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
    def test_renderProtocol(self):
        """
        If protocols are specified via the C{Sec-WebSocket-Protocol} header,
        L{WebSocketsResource} passes them to its C{lookupProtocol} argument,
        which can decide which protocol to return, and which is accepted.
        """

        def lookupProtocol(names, otherRequest):
            self.assertEqual(["foo", "bar"], names)
            self.assertIdentical(request, otherRequest)
            return self.echoProtocol, "bar"

        self.resource = WebSocketsResource(lookupProtocol)

        request = DummyRequest("/")
        request.requestHeaders = Headers(
            {"sec-websocket-protocol": ["foo", "bar"]})
        transport = StringTransportWithDisconnection()
        transport.protocol = Protocol()
        request.transport = transport
        request.headers.update({
            "upgrade": "Websocket",
            "connection": "Upgrade",
            "sec-websocket-key": "secure",
            "sec-websocket-version": "13"})
        result = self.resource.render(request)
        self.assertEqual(NOT_DONE_YET, result)
        self.assertEqual(
            {"connection": "Upgrade",
             "upgrade": "WebSocket",
             "sec-websocket-protocol": "bar",
             "sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
            request.outgoingHeaders)
        self.assertEqual([""], request.written)
        self.assertEqual(101, request.responseCode)
开发者ID:codecats,项目名称:kitty,代码行数:37,代码来源:test_websockets.py

示例4: test_render

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
 def test_render(self):
     """
     When rendering a request, L{WebSocketsResource} uses the
     C{Sec-WebSocket-Key} header to generate a C{Sec-WebSocket-Accept}
     value. It creates a L{WebSocketsProtocol} instance connected to the
     protocol provided by the user factory.
     """
     request = DummyRequest("/")
     request.requestHeaders = Headers()
     transport = StringTransportWithDisconnection()
     transport.protocol = Protocol()
     request.transport = transport
     request.headers.update({
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"})
     result = self.resource.render(request)
     self.assertEqual(NOT_DONE_YET, result)
     self.assertEqual(
         {"connection": "Upgrade",
          "upgrade": "WebSocket",
          "sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
         request.outgoingHeaders)
     self.assertEqual([""], request.written)
     self.assertEqual(101, request.responseCode)
     self.assertIdentical(None, request.transport)
     self.assertIsInstance(transport.protocol._receiver,
                           SavingEchoReceiver)
开发者ID:codecats,项目名称:kitty,代码行数:31,代码来源:test_websockets.py

示例5: request_generator

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
def request_generator(url, method='GET', content=True, headers=True):
    request = DummyRequest(url)
    request.method = method
    if content:
        request.content = StringIO()
    if headers:
        request.requestHeaders = Headers()

    return request
开发者ID:DamnWidget,项目名称:mamba,代码行数:11,代码来源:test_web.py

示例6: test_renderNoProtocol

# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
 def test_renderNoProtocol(self):
     """
     If the underlying factory doesn't return any protocol,
     L{WebSocketsResource} returns a failed request with a C{502} code.
     """
     request = DummyRequest("/")
     request.requestHeaders = Headers()
     request.transport = StringTransportWithDisconnection()
     self.echoProtocol = None
     request.headers.update({
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"})
     result = self.resource.render(request)
     self.assertEqual("", result)
     self.assertEqual({}, request.outgoingHeaders)
     self.assertEqual([], request.written)
     self.assertEqual(502, request.responseCode)
开发者ID:codecats,项目名称:kitty,代码行数:21,代码来源:test_websockets.py


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