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

Python resource.getChildForRequest函数代码示例

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

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



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

示例1: test_putNamedChild_django_static_override

 def test_putNamedChild_django_static_override(self):
     "check that overridden resources work"
     with mock.patch('hendrix.facilities.resources.WSGIResource') as wsgi:
         static_dir = os.path.join(os.path.dirname(__file__),'testproject','static')
         
         # Django finders import in order of INSTALLED_APPS so overrides must happen first
         overridden_media = DjangoStaticResource(static_dir+'/override/css','/static/base/css') # Same rel_url -> overrides
         self.hr.putNamedChild(overridden_media)
         base_media = DjangoStaticResource(static_dir+'/base/css','/static/base/css')
         self.hr.putNamedChild(base_media)
         
         # main.css file should be the same as it is not overridden
         request = DummyRequest(['static', 'base', 'css','main.css'])
         actual_res = getChildForRequest(self.hr, request)
         with actual_res.open() as f:
             actual_content = f.read() 
             
         with open(static_dir+'/base/css/main.css') as f:
             expected_content = f.read()
         self.assertEqual(expected_content,actual_content)
         
         # form.css should be the same as the overridden folder 
         request = DummyRequest(['static', 'base', 'css','form.css'])
         actual_res = getChildForRequest(self.hr, request)
         with actual_res.open() as f:
             actual_content = f.read()
         with open(static_dir+'/override/css/form.css') as f:
             expected_content = f.read()
         self.assertEqual(expected_content,actual_content)
开发者ID:frmdstryr,项目名称:hendrix,代码行数:29,代码来源:test_resources.py


示例2: testDeferredResource

 def testDeferredResource(self):
     r = resource.Resource()
     r.isLeaf = 1
     s = SDResource(r)
     d = DummyRequest(["foo", "bar", "baz"])
     resource.getChildForRequest(s, d)
     self.assertEqual(d.postpath, ["bar", "baz"])
开发者ID:mrader11,项目名称:vodafone-mobile-connect,代码行数:7,代码来源:test_web.py


示例3: test_putNamedChild_duplicate

 def test_putNamedChild_duplicate(self):
     "check that duplicate resources work"
     with mock.patch('hendrix.facilities.resources.WSGIResource') as wsgi:
         request = DummyRequest(['path', 'to', 'child'])
         actual_res = getChildForRequest(self.hr, request)
         self.assertEqual(self.res, actual_res) # Before duplicate
         
         duplicate = NamedResource(self.res.namespace)
         self.hr.putNamedChild(duplicate)
         request = DummyRequest(['path', 'to', 'child'])
         actual_duplicate_res = getChildForRequest(self.hr, request)
         self.assertEqual(duplicate, actual_duplicate_res) # After duplicate
开发者ID:citruspi,项目名称:hendrix,代码行数:12,代码来源:test_resources.py


示例4: test_get_blobs_enabled

 def test_get_blobs_enabled(self):
     blobs_resource = BlobsResource("filesystem", '/tmp')
     streaming_resource = StreamingResource("filesystem", '/tmp')
     resource = PublicResource(
         blobs_resource=blobs_resource,
         streaming_resource=streaming_resource,
         sync_pool=_pool)
     request = DummyRequest(['blobs'])
     child = getChildForRequest(resource, request)
     self.assertIsInstance(child, BlobsResource)
     request = DummyRequest(['stream'])
     child = getChildForRequest(resource, request)
     self.assertIsInstance(child, StreamingResource)
开发者ID:leapcode,项目名称:soledad,代码行数:13,代码来源:test__resource.py


示例5: test_get_root

 def test_get_root(self):
     blobs_resource = None  # doesn't matter
     resource = PublicResource(
         blobs_resource=blobs_resource, sync_pool=_pool)
     request = DummyRequest([''])
     child = getChildForRequest(resource, request)
     self.assertIsInstance(child, ServerInfo)
开发者ID:leapcode,项目名称:soledad,代码行数:7,代码来源:test__resource.py


示例6: test_unexpectedDecodeError

    def test_unexpectedDecodeError(self):
        """
        Any unexpected exception raised by the credential factory's C{decode}
        method results in a 500 response code and causes the exception to be
        logged.
        """
        class UnexpectedException(Exception):
            pass

        class BadFactory(object):
            scheme = 'bad'

            def getChallenge(self, client):
                return {}

            def decode(self, response, request):
                raise UnexpectedException()

        self.credentialFactories.append(BadFactory())
        request = self.makeRequest([self.childName])
        request.headers['authorization'] = 'Bad abc'
        child = getChildForRequest(self.wrapper, request)
        request.render(child)
        self.assertEqual(request.responseCode, 500)
        self.assertEqual(len(self.flushLoggedErrors(UnexpectedException)), 1)
开发者ID:jxta,项目名称:cc,代码行数:25,代码来源:test_httpauth.py


示例7: test_locateChildSpinneretResource

    def test_locateChildSpinneretResource(self):
        """
        If ``locateChild`` returns something adaptable to `ISpinneretResource`
        it is adapted to an `IResource`.
        """
        @implementer(ISpinneretResource)
        class _ResultingResource(object):
            def render_GET(zelf, request):
                request.setResponseCode(http.OK)
                return b'hello world'

        @implementer(ISpinneretResource)
        class _TestResource(object):
            def locateChild(zelf, request, segments):
                return _ResultingResource(), []

        resource = SpinneretResource(_TestResource())
        request = InMemoryRequest([''])
        request.method = b'GET'
        result = getChildForRequest(resource, request)
        request.render(result)
        self.assertThat(
            b''.join(request.written),
            Equals(b'hello world'))
        self.assertThat(
            http.OK,
            Equals(request.responseCode))
        self.assertThat(
            request.postpath,
            Equals([]))
开发者ID:mithrandi,项目名称:txspinneret,代码行数:30,代码来源:test_resource.py


示例8: test_locateChildRenderable

    def test_locateChildRenderable(self):
        """
        If ``locateChild`` returns something adaptable to `IRenderable` it is
        rendered.
        """
        class _TestElement(Element):
            loader = TagLoader(tags.span(u'Hello ', tags.em(u'World')))

        @implementer(ISpinneretResource)
        class _TestResource(object):
            def locateChild(zelf, request, segments):
                return _TestElement(), []

        resource = SpinneretResource(_TestResource())
        request = InMemoryRequest([''])
        result = getChildForRequest(resource, request)
        request.render(result)
        self.assertThat(
            b''.join(request.written),
            Equals(b'<!DOCTYPE html>\n<span>Hello <em>World</em></span>'))
        self.assertThat(
            http.OK,
            Equals(request.responseCode))
        self.assertThat(
            request.postpath,
            Equals([]))
开发者ID:mithrandi,项目名称:txspinneret,代码行数:26,代码来源:test_resource.py


示例9: test_getChallengeCalledWithRequest

    def test_getChallengeCalledWithRequest(self):
        """
        When L{HTTPAuthSessionWrapper} finds an L{ICredentialFactory} to issue
        a challenge, it calls the C{getChallenge} method with the request as an
        argument.
        """
        class DumbCredentialFactory(object):
            implements(ICredentialFactory)
            scheme = 'dumb'

            def __init__(self):
                self.requests = []

            def getChallenge(self, request):
                self.requests.append(request)
                return {}

        factory = DumbCredentialFactory()
        self.credentialFactories.append(factory)
        request = self.makeRequest([self.childName])
        child = getChildForRequest(self.wrapper, request)
        d = request.notifyFinish()
        def cbFinished(ignored):
            self.assertEqual(factory.requests, [request])
        d.addCallback(cbFinished)
        request.render(child)
        return d
开发者ID:jxta,项目名称:cc,代码行数:27,代码来源:test_httpauth.py


示例10: test_locateChildResource

    def test_locateChildResource(self):
        """
        If ``locateChild`` returns something adaptable to `IResource` it is
        returned.
        """
        class _ResultingResource(Resource):
            isLeaf = True
            def render(zelf, request):
                request.setResponseCode(http.OK)
                return b'hello world'

        class _TestResource(SpinneretResource):
            def locateChild(zelf, request, segments):
                return _ResultingResource(), segments

        resource = _TestResource()
        request = InMemoryRequest([''])
        result = getChildForRequest(resource, request)
        request.render(result)
        self.assertThat(
            b''.join(request.written),
            Equals(b'hello world'))
        self.assertThat(
            http.OK,
            Equals(request.responseCode))
开发者ID:jerith,项目名称:txspinneret,代码行数:25,代码来源:test_resource.py


示例11: process

        def process(r):
            if IResource.providedBy(r):
                return request.render(getChildForRequest(r, request))

            if IRenderable.providedBy(r):
                return flattenString(request, r).addCallback(process)

            return r
开发者ID:russellhaering,项目名称:klein,代码行数:8,代码来源:resource.py


示例12: test_get_sync

 def test_get_sync(self):
     blobs_resource = None  # doesn't matter
     resource = PublicResource(
         blobs_resource=blobs_resource, sync_pool=_pool)
     request = DummyRequest(['user-db', 'sync-from', 'source-id'])
     child = getChildForRequest(resource, request)
     self.assertIsInstance(child, WSGIResource)
     self.assertIsInstance(child._application, GzipMiddleware)
开发者ID:leapcode,项目名称:soledad,代码行数:8,代码来源:test__resource.py


示例13: test_info

    def test_info(self):
        '''The Info resource must be accessible as the "info" child of the
        TxDarn resource.

        '''
        self.request.postpath = [b'info']
        resrc = getChildForRequest(self.txdarn, self.request)
        self.assertIs(resrc, self.txdarn.info)
开发者ID:hhco,项目名称:txdarn,代码行数:8,代码来源:test_resources.py


示例14: render_GET

 def render_GET(self, request):
     try:
         index = request.args["code"][0]
         self.main.removeMessage(index)
         request.render(getChildForRequest(Index(self.main), request))
         return NOT_DONE_YET
     except:
         return "Error"
开发者ID:HapPiNeHsSs,项目名称:hideout,代码行数:8,代码来源:push_server.py


示例15: getChild

 def getChild(self, child, request ):
     if not self.static:
         return self.prepareWSGI(child, request)
     else:
         resource = getChildForRequest(self.static, request)
         if not hasattr(resource, "isdir") or resource.isdir() or not resource.exists():
             return self.prepareWSGI(child, request)
         else:
             return resource
开发者ID:nanonyme,项目名称:twisted-django,代码行数:9,代码来源:twisted_django_plugin.py


示例16: _authorizedBasicLogin

 def _authorizedBasicLogin(self, request):
     """
     Add an I{basic authorization} header to the given request and then
     dispatch it, starting from C{self.wrapper} and returning the resulting
     L{IResource}.
     """
     authorization = b64encode(self.username + ':' + self.password)
     request.headers['authorization'] = 'Basic ' + authorization
     return getChildForRequest(self.wrapper, request)
开发者ID:jxta,项目名称:cc,代码行数:9,代码来源:test_httpauth.py


示例17: test_locateChildSetPostpath

    def test_locateChildSetPostpath(self):
        """
        The second elements in ``locateChild`` return value is the new request
        postpath.
        """
        class _TestResource(SpinneretResource):
            def locateChild(zelf, request, segments):
                return None, [b'quux']

        resource = _TestResource()
        request = InMemoryRequest([b'foo', b'bar'])
        self.assertThat(
            request.postpath,
            Equals([b'foo', b'bar']))
        getChildForRequest(resource, request)
        self.assertThat(
            request.postpath,
            Equals([b'quux']))
开发者ID:jerith,项目名称:txspinneret,代码行数:18,代码来源:test_resource.py


示例18: test_greeting_trailing_slash

    def test_greeting_trailing_slash(self):
        '''The Greeting resource must be accessible as the direct child of the
        TxDarn resource (i.e., with a trailing slash).

        '''
        # a trailing slash -- empty string in postpath
        self.request.postpath = [b'']
        resrc = getChildForRequest(self.txdarn, self.request)
        self.assertIs(resrc, self.txdarn.greeting)
开发者ID:hhco,项目名称:txdarn,代码行数:9,代码来源:test_resources.py


示例19: test_exhaustedPostPath

 def test_exhaustedPostPath(self):
     """
     L{getChildForRequest} returns whatever resource has been reached by the
     time the request's C{postpath} is empty.
     """
     request = DummyRequest([])
     resource = Resource()
     result = getChildForRequest(resource, request)
     self.assertIdentical(resource, result)
开发者ID:Architektor,项目名称:PySnip,代码行数:9,代码来源:test_resource.py


示例20: test_get_blobs_disabled

 def test_get_blobs_disabled(self):
     blobs_resource = None
     resource = PublicResource(
         blobs_resource=blobs_resource, sync_pool=_pool)
     request = DummyRequest(['blobs'])
     child = getChildForRequest(resource, request)
     # if blobs is disabled, the request should be routed to sync
     self.assertIsInstance(child, WSGIResource)
     self.assertIsInstance(child._application, GzipMiddleware)
开发者ID:leapcode,项目名称:soledad,代码行数:9,代码来源:test__resource.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python resource.NoResource类代码示例发布时间:2022-05-27
下一篇:
Python proxy.ProxyClient类代码示例发布时间: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