test_static.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码
def test_processors(self):
        """
        If a request is made which encounters a L{File} before a final segment
        which names a file with an extension which is in the L{File}'s
        C{processors} mapping, the processor associated with that extension is
        used to serve the response to the request.
        """
        base = FilePath(self.mktemp())
        base.makedirs()
        base.child("foo.bar").setContent(
            b"from twisted.web.static import Data\n"
            b"resource = Data(b'dynamic world', 'text/plain')\n")

        file = static.File(base.path)
        file.processors = {b'.bar': script.ResourceScript}
        request = DummyRequest([b"foo.bar"])
        child = resource.getChildForRequest(file, request)

        d = self._render(child, request)
        def cbRendered(ignored):
            self.assertEqual(b''.join(request.written), b'dynamic world')
            self.assertEqual(
                request.responseHeaders.getRawHeaders(b'content-length')[0],
                b'13')
        d.addCallback(cbRendered)
        return d
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号