• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python _util._render函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.web.test._util._render函数的典型用法代码示例。如果您正苦于以下问题:Python _render函数的具体用法?Python _render怎么用?Python _render使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_pathInfo

    def test_pathInfo(self):
        """
        L{twcgi.CGIScript.render} sets the process environment I{PATH_INFO} from
        the request path.
        """
        class FakeReactor:
            """
            A fake reactor recording the environment passed to spawnProcess.
            """
            def spawnProcess(self, process, filename, args, env, wdir):
                """
                Store the C{env} L{dict} to an instance attribute.

                @param process: Ignored
                @param filename: Ignored
                @param args: Ignored
                @param env: The environment L{dict} which will be stored
                @param wdir: Ignored
                """
                self.process_env = env

        _reactor = FakeReactor()
        resource = twcgi.CGIScript(self.mktemp(), reactor=_reactor)
        request = DummyRequest(['a', 'b'])
        _render(resource, request)

        self.assertEqual(_reactor.process_env["PATH_INFO"],
                         "/a/b")
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:28,代码来源:test_cgi.py


示例2: test_useReactorArgument

    def test_useReactorArgument(self):
        """
        L{twcgi.FilteredScript.runProcess} uses the reactor passed as an
        argument to the constructor.
        """
        class FakeReactor:
            """
            A fake reactor recording whether spawnProcess is called.
            """
            called = False
            def spawnProcess(self, *args, **kwargs):
                """
                Set the C{called} flag to C{True} if C{spawnProcess} is called.

                @param args: Positional arguments.
                @param kwargs: Keyword arguments.
                """
                self.called = True

        fakeReactor = FakeReactor()
        request = DummyRequest(['a', 'b'])
        resource = twcgi.FilteredScript("dummy-file", reactor=fakeReactor)
        _render(resource, request)

        self.assertTrue(fakeReactor.called)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:25,代码来源:test_cgi.py


示例3: test_renderWithHost

    def test_renderWithHost(self):
        """
        L{NameVirtualHost.render} returns the result of rendering the resource
        which is the value in the instance's C{host} dictionary corresponding
        to the key indicated by the value of the I{Host} header in the request.
        """
        virtualHostResource = NameVirtualHost()
        virtualHostResource.addHost(b'example.org', Data(b"winner", ""))

        request = DummyRequest([b''])
        request.requestHeaders.addRawHeader(b'host', b'example.org')
        d = _render(virtualHostResource, request)
        def cbRendered(ignored, request):
            self.assertEqual(b''.join(request.written), b"winner")
        d.addCallback(cbRendered, request)

        # The port portion of the Host header should not be considered.
        requestWithPort = DummyRequest([b''])
        requestWithPort.requestHeaders.addRawHeader(b'host', b'example.org:8000')
        dWithPort = _render(virtualHostResource, requestWithPort)
        def cbRendered(ignored, requestWithPort):
            self.assertEqual(b''.join(requestWithPort.written), b"winner")
        dWithPort.addCallback(cbRendered, requestWithPort)

        return gatherResults([d, dWithPort])
开发者ID:Architektor,项目名称:PySnip,代码行数:25,代码来源:test_vhost.py


示例4: test_render

    def test_render(self):
        """
        L{UserDirectory} renders a list of links to available user content
        in response to a I{GET} request.
        """
        public_html = filepath.FilePath(self.alice[-2]).child('public_html')
        public_html.makedirs()
        web = filepath.FilePath(self.bob[-2])
        web.makedirs()
        # This really only works if it's a unix socket, but the implementation
        # doesn't currently check for that.  It probably should someday, and
        # then skip users with non-sockets.
        web.child('.twistd-web-pb').setContent("")

        request = DummyRequest([''])
        result = _render(self.directory, request)
        def cbRendered(ignored):
            document = parseString(''.join(request.written))

            # Each user should have an li with a link to their page.
            [alice, bob] = document.getElementsByTagName('li')
            self.assertEqual(alice.firstChild.tagName, 'a')
            self.assertEqual(alice.firstChild.getAttribute('href'), 'alice/')
            self.assertEqual(alice.firstChild.firstChild.data, 'Alice (file)')
            self.assertEqual(bob.firstChild.tagName, 'a')
            self.assertEqual(bob.firstChild.getAttribute('href'), 'bob.twistd/')
            self.assertEqual(bob.firstChild.firstChild.data, 'Bob (twistd)')

        result.addCallback(cbRendered)
        return result
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:30,代码来源:test_distrib.py


示例5: test_unknown_request_id

    def test_unknown_request_id(self):
        self.request.addArg('request_id', 'xxx')

        def on_rendered(_):
            self.assertEqual(self.request.responseCode, 503)
            self.assertEqual(['Request not found'], self.request.written)

        return _render(self.resource, self.request).addCallback(on_rendered)
开发者ID:jaxer,项目名称:thinking-exercise,代码行数:8,代码来源:test_callback_resource.py


示例6: test_success

    def test_success(self):
        self.request.addArg('request_id', 'xxx')
        self.resource.factory.requests['xxx'] = DecoupledRequest(
            self.resource.factory, 'xxx', DummyRequest(['']))

        def on_rendered(_):
            self.assertEqual(['ok'], self.request.written)

        return _render(self.resource, self.request).addCallback(on_rendered)
开发者ID:jaxer,项目名称:thinking-exercise,代码行数:9,代码来源:test_callback_resource.py


示例7: test00_render

 def test00_render(self):
     tree = CardstoriesTree(self.service)
     request = DummyRequest(['agpl'])
     child = resource.getChildForRequest(tree, request)
     self.assertTrue(isinstance(child, AGPLResource))
     d = _render(child, request)
     def finish(result):
         self.assertEquals('PK', request.written[0][:2])
     d.addCallback(finish)
     return d
开发者ID:B-Rich,项目名称:cardstories,代码行数:10,代码来源:test_site.py


示例8: test_success

    def test_success(self):
        def on_rendered(_):
            self.assertEqual(['backend reply'], self.request.written)

        d = _render(self.resource, self.request).addCallback(on_rendered)

        callback_request = DummyRequest([''])
        callback_request.content = StringIO('backend reply')

        self.resource.factory.requests.values()[0].notify(callback_request)
        return d
开发者ID:jaxer,项目名称:thinking-exercise,代码行数:11,代码来源:test_exported_resource.py


示例9: test_notFoundRender

 def test_notFoundRender(self):
     """
     If the source file a L{PythonScript} is initialized with doesn't exist,
     L{PythonScript.render} sets the HTTP response code to I{NOT FOUND}.
     """
     resource = PythonScript(self.mktemp(), None)
     request = DummyRequest([''])
     d = _render(resource, request)
     def cbRendered(ignored):
         self.assertEqual(request.responseCode, NOT_FOUND)
     d.addCallback(cbRendered)
     return d
开发者ID:0004c,项目名称:VTK,代码行数:12,代码来源:test_script.py


示例10: test_render

 def test_render(self):
     """
     L{twcgi.CGIDirectory.render} sets the HTTP response code to I{NOT
     FOUND}.
     """
     resource = twcgi.CGIDirectory(self.mktemp())
     request = DummyRequest([''])
     d = _render(resource, request)
     def cbRendered(ignored):
         self.assertEqual(request.responseCode, NOT_FOUND)
     d.addCallback(cbRendered)
     return d
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:12,代码来源:test_cgi.py


示例11: _404Test

 def _404Test(self, name):
     """
     Verify that requesting the C{name} child of C{self.directory} results
     in a 404 response.
     """
     request = DummyRequest([name])
     result = self.directory.getChild(name, request)
     d = _render(result, request)
     def cbRendered(ignored):
         self.assertEqual(request.responseCode, 404)
     d.addCallback(cbRendered)
     return d
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:12,代码来源:test_distrib.py


示例12: test_renderWithoutHostNoDefault

 def test_renderWithoutHostNoDefault(self):
     """
     L{NameVirtualHost.render} returns a response with a status of I{NOT
     FOUND} if the instance's C{default} is C{None} and there is no I{Host}
     header in the request.
     """
     virtualHostResource = NameVirtualHost()
     request = DummyRequest([''])
     d = _render(virtualHostResource, request)
     def cbRendered(ignored):
         self.assertEqual(request.responseCode, NOT_FOUND)
     d.addCallback(cbRendered)
     return d
开发者ID:Architektor,项目名称:PySnip,代码行数:13,代码来源:test_vhost.py


示例13: test_renderWithUnknownHostNoDefault

 def test_renderWithUnknownHostNoDefault(self):
     """
     L{NameVirtualHost.render} returns a response with a status of I{NOT
     FOUND} if the instance's C{default} is C{None} and there is no host
     matching the value of the I{Host} header in the request.
     """
     virtualHostResource = NameVirtualHost()
     request = DummyRequest([''])
     request.requestHeaders.addRawHeader(b'host', b'example.com')
     d = _render(virtualHostResource, request)
     def cbRendered(ignored):
         self.assertEqual(request.responseCode, NOT_FOUND)
     d.addCallback(cbRendered)
     return d
开发者ID:Architektor,项目名称:PySnip,代码行数:14,代码来源:test_vhost.py


示例14: test_childrenNotFound

 def test_childrenNotFound(self):
     """
     Any child resource of L{static.DirectoryLister} renders an HTTP
     I{NOT FOUND} response code.
     """
     path = FilePath(self.mktemp())
     path.makedirs()
     lister = static.DirectoryLister(path.path)
     request = self._request('')
     child = resource.getChildForRequest(lister, request)
     result = _render(child, request)
     def cbRendered(ignored):
         self.assertEquals(request.responseCode, http.NOT_FOUND)
     result.addCallback(cbRendered)
     return result
开发者ID:MatthewTurk,项目名称:codenode,代码行数:15,代码来源:test_static.py


示例15: test_renderWithUnknownHost

 def test_renderWithUnknownHost(self):
     """
     L{NameVirtualHost.render} returns the result of rendering the
     instance's C{default} if it is not C{None} and there is no host
     matching the value of the I{Host} header in the request.
     """
     virtualHostResource = NameVirtualHost()
     virtualHostResource.default = Data(b"correct data", "")
     request = DummyRequest([b''])
     request.requestHeaders.addRawHeader(b'host', b'example.com')
     d = _render(virtualHostResource, request)
     def cbRendered(ignored):
         self.assertEqual(b''.join(request.written), b"correct data")
     d.addCallback(cbRendered)
     return d
开发者ID:Architektor,项目名称:PySnip,代码行数:15,代码来源:test_vhost.py


示例16: test00_render_static

    def test00_render_static(self):
        file = "file"
        fd = open(file, "w")
        fd.write('CONTENT')
        fd.close()

        tree = CardstoriesTree(self.service)
        request = DummyRequest(['static', 'file'])
        child = resource.getChildForRequest(tree, request)

        self.assertTrue(isinstance(child, filepath.FilePath))
        d = _render(child, request)
        def finish(result):
            self.assertEquals(['CONTENT'], request.written)
        d.addCallback(finish)
        return d
开发者ID:B-Rich,项目名称:cardstories,代码行数:16,代码来源:test_site.py


示例17: test_renderException

 def test_renderException(self):
     """
     L{ResourceScriptDirectory.getChild} returns a resource which renders a
     response with the HTTP 200 status code and the content of the rpy's
     C{request} global.
     """
     tmp = FilePath(self.mktemp())
     tmp.makedirs()
     child = tmp.child("test.epy")
     child.setContent(b'raise Exception("nooo")')
     resource = PythonScript(child._asBytesPath(), None)
     request = DummyRequest([b''])
     d = _render(resource, request)
     def cbRendered(ignored):
         self.assertIn(b"nooo", b"".join(request.written))
     d.addCallback(cbRendered)
     return d
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:17,代码来源:test_script.py


示例18: test_notFoundChild

 def test_notFoundChild(self):
     """
     L{twcgi.CGIDirectory.getChild} returns a resource which renders an
     response with the HTTP I{NOT FOUND} status code if the indicated child
     does not exist as an entry in the directory used to initialized the
     L{twcgi.CGIDirectory}.
     """
     path = self.mktemp()
     os.makedirs(path)
     resource = twcgi.CGIDirectory(path)
     request = DummyRequest(['foo'])
     child = resource.getChild("foo", request)
     d = _render(child, request)
     def cbRendered(ignored):
         self.assertEqual(request.responseCode, NOT_FOUND)
     d.addCallback(cbRendered)
     return d
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:17,代码来源:test_cgi.py


示例19: renderResource

def renderResource(resource, path, params=None, method=b"GET", body=b"", isSecure=False,
                   headers=None, sign=False, signKey=None, signSecret=None):

    params = {} if params is None else params
    headers = {} if params is None else headers

    def _cb(result, request):
        return request

    if sign:
        params = makeSignedArguments(params, signKey, signSecret, body)

    req = request(path, args=params, method=method, isSecure=isSecure,
                  headers=headers, body=body)

    d = _render(resource, req)
    d.addCallback(_cb, req)
    return d
开发者ID:crossbario,项目名称:crossbar,代码行数:18,代码来源:__init__.py


示例20: test_connectionLost

    def test_connectionLost(self):
        """
        If there is an error issuing the request to the remote publisher, an
        error response is returned.
        """
        # Using pb.Root as a publisher will cause request calls to fail with an
        # error every time.  Just what we want to test.
        self.f1 = serverFactory = PBServerFactory(pb.Root())
        self.port1 = serverPort = reactor.listenTCP(0, serverFactory)

        self.sub = subscription = distrib.ResourceSubscription(
            "127.0.0.1", serverPort.getHost().port)
        request = DummyRequest([''])
        d = _render(subscription, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, 500)
            # This is the error we caused the request to fail with.  It should
            # have been logged.
            errors = self.flushLoggedErrors(pb.NoSuchMethod)
            self.assertEqual(len(errors), 1)
            # The error page is rendered as HTML.
            expected = [
                '',
                '<html>',
                '  <head><title>500 - Server Connection Lost</title></head>',
                '  <body>',
                '    <h1>Server Connection Lost</h1>',
                '    <p>Connection to distributed server lost:'
                    '<pre>'
                    '[Failure instance: Traceback from remote host -- '
                    'Traceback unavailable',
                'twisted.spread.flavors.NoSuchMethod: '
                    'No such method: remote_request',
                ']</pre></p>',
                '  </body>',
                '</html>',
                ''
                ]
            self.assertEqual(['\n'.join(expected)], request.written)

        d.addCallback(cbRendered)
        return d
开发者ID:Architektor,项目名称:PySnip,代码行数:42,代码来源:test_distrib.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python requesthelper.DummyChannel类代码示例发布时间:2022-05-27
下一篇:
Python tags.span函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap