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

Python static.Data类代码示例

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

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



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

示例1: setUp

 def setUp(self):
     root = Data(b'El toro!', 'text/plain')
     root.putChild(b"cookiemirror", CookieMirrorResource())
     root.putChild(b"rawcookiemirror", RawCookieMirrorResource())
     site = server.Site(root, timeout=None)
     self.port = self._listen(site)
     self.portno = self.port.getHost().port
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:7,代码来源:test_webclient.py


示例2: test_getChild

    def test_getChild(self):
        """
        L{NameVirtualHost.getChild} returns correct I{Resource} based off
        the header and modifies I{Request} to ensure proper prepath and
        postpath are set.
        """
        virtualHostResource = NameVirtualHost()
        leafResource = Data(b"leaf data", "")
        leafResource.isLeaf = True
        normResource = Data(b"norm data", "")
        virtualHostResource.addHost(b'leaf.example.org', leafResource)
        virtualHostResource.addHost(b'norm.example.org', normResource)

        request = DummyRequest([])
        request.requestHeaders.addRawHeader(b'host', b'norm.example.org')
        request.prepath = [b'']

        self.assertIsInstance(virtualHostResource.getChild(b'', request),
                              NoResource)
        self.assertEqual(request.prepath, [b''])
        self.assertEqual(request.postpath, [])

        request = DummyRequest([])
        request.requestHeaders.addRawHeader(b'host', b'leaf.example.org')
        request.prepath = [b'']

        self.assertIsInstance(virtualHostResource.getChild(b'', request),
                              Data)
        self.assertEqual(request.prepath,  [])
        self.assertEqual(request.postpath, [b''])
开发者ID:Architektor,项目名称:PySnip,代码行数:30,代码来源:test_vhost.py


示例3: test_resource_tree

 def test_resource_tree(self):
     """
     The agent should traverse the resource tree correctly
     """
     class R(Resource):
         def __init__(self, response):
             Resource.__init__(self)
             self._response = response
         def render_GET(self, request):
             return self._response
     
     a = Data('a', 'text/plain')
     c = Data('c', 'text/plain')
     
     a.putChild('b', Data('b', 'text/plain'))
     a.putChild('c', c)
     
     c.putChild('d', Data('d', 'text/plain'))
     
     agent = self.getAgent(a)
     
     # are these assertions correct?
     yield self.assertBody(agent, 'a', 'GET', 'http://example.com')
     yield self.assertBody(agent, 'a', 'GET', 'http://example.com/')
     yield self.assertBody(agent, 'b', 'GET', 'http://example.com/b')
     yield self.assertBody(agent, 'c', 'GET', 'http://example.com/c')
     yield self.assertBody(agent, 'd', 'GET', 'http://example.com/c/d')
开发者ID:iffy,项目名称:agentforhire,代码行数:27,代码来源:mixin.py


示例4: go

    def go(self, reactor):
        data = Data("Hello world\n", "text/plain")
        data.putChild("", data)
        factory = Site(data)

        # TODO: adoptStreamConnection should really support AF_UNIX
        protocol = ConnectionFromManager(reactor, factory)
        skt = fromfd(MAGIC_FILE_DESCRIPTOR, AF_UNIX, SOCK_STREAM)
        os.close(MAGIC_FILE_DESCRIPTOR)
        serverTransport = UNIXServer(skt, protocol, None, None, 1234, reactor)
        protocol.makeConnection(serverTransport)
        serverTransport.startReading()

        globalLogBeginner.beginLoggingTo([protocol.sendLog])
        factory.doStart()

        return Deferred()
开发者ID:glyph,项目名称:WarpedAlloy,代码行数:17,代码来源:__init__.py


示例5: get_provider_factory

def get_provider_factory():
    """
    Instantiates a Site that serves the resources
    that we expect from a valid provider.
    Listens on:
    * port 8000 for http connections
    * port 8443 for https connections

    :rparam: factory for a site
    :rtype: Site instance
    """
    root = Data("", "")
    root.putChild("", root)
    root.putChild("provider.json", FileModified(
        os.path.join(_here,
                     "test_provider.json")))
    config = Resource()
    config.putChild(
        "eip-service.json",
        FileModified(
            os.path.join(_here, "eip-service.json")))
    apiv1 = Resource()
    apiv1.putChild("config", config)
    apiv1.putChild("sessions", API_Sessions())
    apiv1.putChild("users", FakeUsers(None))
    apiv1.putChild("cert", FileModified(
        os.path.join(_here,
                     'openvpn.pem')))
    root.putChild("1", apiv1)

    factory = Site(root)
    return factory
开发者ID:irregulator,项目名称:bitmask_client,代码行数:32,代码来源:fake_provider.py


示例6: setUp

    def setUp(self):
        self.avatar_content = b"avatar content"
        self.child_content = b"child content"
        self.grandchild_content = b"grandchild content"

        grandchild = Data(self.grandchild_content, b"text/plain")

        child = Data(self.child_content, b"text/plain")
        child.putChild(b"grandchild", grandchild)

        self.avatar = Data(self.avatar_content, b"text/plain")
        self.avatar.putChild(b"child", child)

        self.realm = OneIResourceAvatarRealm(self.avatar)
        self.portal = Portal(
            self.realm,
            [AllowAnonymousAccess()],
        )
        self.guard = HTTPAuthSessionWrapper(
            self.portal,
            [BasicCredentialFactory("example.com")],
        )
开发者ID:twisted,项目名称:nevow,代码行数:22,代码来源:test_appserver.py


示例7: setUp

 def setUp(self):
     self.username = b'foo bar'
     self.password = b'bar baz'
     self.avatarContent = b"contents of the avatar resource itself"
     self.childName = b"foo-child"
     self.childContent = b"contents of the foo child of the avatar"
     self.checker = InMemoryUsernamePasswordDatabaseDontUse()
     self.checker.addUser(self.username, self.password)
     self.avatar = Data(self.avatarContent, 'text/plain')
     self.avatar.putChild(
         self.childName, Data(self.childContent, 'text/plain'))
     self.avatars = {self.username: self.avatar}
     self.realm = Realm(self.avatars.get)
     self.portal = portal.Portal(self.realm, [self.checker])
     self.wrapper = SoledadSession(self.portal)
开发者ID:leapcode,项目名称:soledad,代码行数:15,代码来源:test_session.py


示例8: setUp

 def setUp(self):
     """
     Create a realm, portal, and L{HTTPAuthSessionWrapper} to use in the tests.
     """
     self.username = 'foo bar'
     self.password = 'bar baz'
     self.avatarContent = "contents of the avatar resource itself"
     self.childName = "foo-child"
     self.childContent = "contents of the foo child of the avatar"
     self.checker = InMemoryUsernamePasswordDatabaseDontUse()
     self.checker.addUser(self.username, self.password)
     self.avatar = Data(self.avatarContent, 'text/plain')
     self.avatar.putChild(
         self.childName, Data(self.childContent, 'text/plain'))
     self.avatars = {self.username: self.avatar}
     self.realm = Realm(self.avatars.get)
     self.portal = portal.Portal(self.realm, [self.checker])
     self.credentialFactories = []
     self.wrapper = HTTPAuthSessionWrapper(
         self.portal, self.credentialFactories)
开发者ID:jxta,项目名称:cc,代码行数:20,代码来源:test_httpauth.py


示例9: makeResource

 def makeResource(expected):
     resource = Data(expected, b"text/plain")
     intermediate = Data(b"incorrect intermediate", b"text/plain")
     intermediate.putChild(b"child", resource)
     return DeferredResource(succeed(intermediate))
开发者ID:twisted,项目名称:nevow,代码行数:5,代码来源:test_appserver.py


示例10: __init__

 def __init__(self, data, type, status=OK):
     Data.__init__(self, data, type)
     self._status = status
开发者ID:oubiwann,项目名称:txaws,代码行数:3,代码来源:test_route53.py


示例11: len

        self.sendClose()

if __name__ == '__main__':
    if len(sys.argv) > 1 and sys.argv[1] == 'debug':
        log.startLogging(sys.stdout)
        debug = True
    else:
        debug = False

    factorySave = WebSocketServerFactory("ws://localhost:{0}".format(LOCAL_PROXY_PORT), debug = debug)
    factorySave.protocol = RemoteControlSaveProtocol
    resourceSave = WebSocketResource(factorySave)

    factoryLoad = WebSocketServerFactory("ws://localhost:{0}".format(LOCAL_PROXY_PORT), debug = debug)
    factoryLoad.protocol = RemoteControlLoadProtocol
    resourceLoad = WebSocketResource(factoryLoad)

    # Establish a dummy root resource
    root = Data("", "text/plain")

    # and our WebSocket servers under different paths ..
    root.putChild("save", resourceSave)
    root.putChild("load", resourceLoad)

    # both under one Twisted Web Site
    site = Site(root)
    reactor.listenTCP(LOCAL_PROXY_PORT, site)

    reactor.run()
开发者ID:Tinkerforge,项目名称:internet-of-things,代码行数:29,代码来源:server.py


示例12: render_POST

 def render_POST(self, request):
     request.setResponseCode(self._status)
     self.posted += (request.content.read(),)
     return Data.render_GET(self, request)
开发者ID:oubiwann,项目名称:txaws,代码行数:4,代码来源:test_route53.py


示例13: SoledadSessionTestCase

class SoledadSessionTestCase(unittest.TestCase):
    """
    Tests adapted from for
    L{twisted.web.test.test_httpauth.HTTPAuthSessionWrapper}.
    """

    def makeRequest(self, *args, **kwargs):
        request = DummyRequest(*args, **kwargs)
        request.path = '/'
        return request

    def setUp(self):
        self.username = b'foo bar'
        self.password = b'bar baz'
        self.avatarContent = b"contents of the avatar resource itself"
        self.childName = b"foo-child"
        self.childContent = b"contents of the foo child of the avatar"
        self.checker = InMemoryUsernamePasswordDatabaseDontUse()
        self.checker.addUser(self.username, self.password)
        self.avatar = Data(self.avatarContent, 'text/plain')
        self.avatar.putChild(
            self.childName, Data(self.childContent, 'text/plain'))
        self.avatars = {self.username: self.avatar}
        self.realm = Realm(self.avatars.get)
        self.portal = portal.Portal(self.realm, [self.checker])
        self.wrapper = SoledadSession(self.portal)

    def _authorizedTokenLogin(self, request):
        authorization = b64encode(
            self.username + b':' + self.password)
        request.requestHeaders.addRawHeader(b'authorization',
                                            b'Token ' + authorization)
        return getChildForRequest(self.wrapper, request)

    def test_getChildWithDefault(self):
        request = self.makeRequest([self.childName])
        child = getChildForRequest(self.wrapper, request)
        d = request.notifyFinish()

        def cbFinished(result):
            self.assertEqual(request.responseCode, 401)

        d.addCallback(cbFinished)
        request.render(child)
        return d

    def _invalidAuthorizationTest(self, response):
        request = self.makeRequest([self.childName])
        request.requestHeaders.addRawHeader(b'authorization', response)
        child = getChildForRequest(self.wrapper, request)
        d = request.notifyFinish()

        def cbFinished(result):
            self.assertEqual(request.responseCode, 401)

        d.addCallback(cbFinished)
        request.render(child)
        return d

    def test_getChildWithDefaultUnauthorizedUser(self):
        return self._invalidAuthorizationTest(
            b'Basic ' + b64encode(b'foo:bar'))

    def test_getChildWithDefaultUnauthorizedPassword(self):
        return self._invalidAuthorizationTest(
            b'Basic ' + b64encode(self.username + b':bar'))

    def test_getChildWithDefaultUnrecognizedScheme(self):
        return self._invalidAuthorizationTest(b'Quux foo bar baz')

    def test_getChildWithDefaultAuthorized(self):
        request = self.makeRequest([self.childName])
        child = self._authorizedTokenLogin(request)
        d = request.notifyFinish()

        def cbFinished(ignored):
            self.assertEqual(request.written, [self.childContent])

        d.addCallback(cbFinished)
        request.render(child)
        return d

    def test_renderAuthorized(self):
        # Request it exactly, not any of its children.
        request = self.makeRequest([])
        child = self._authorizedTokenLogin(request)
        d = request.notifyFinish()

        def cbFinished(ignored):
            self.assertEqual(request.written, [self.avatarContent])

        d.addCallback(cbFinished)
        request.render(child)
        return d

    def test_decodeRaises(self):
        request = self.makeRequest([self.childName])
        request.requestHeaders.addRawHeader(b'authorization',
                                            b'Token decode should fail')
        child = getChildForRequest(self.wrapper, request)
#.........这里部分代码省略.........
开发者ID:leapcode,项目名称:soledad,代码行数:101,代码来源:test_session.py


示例14: len

   if len(sys.argv) > 1 and sys.argv[1] == 'debug':
      log.startLogging(sys.stdout)
      debug = True
   else:
      debug = False

   factory1 = WebSocketServerFactory("ws://localhost:9000",
                                     debug = debug,
                                     debugCodePaths = debug)
   factory1.protocol = Echo1ServerProtocol
   resource1 = WebSocketResource(factory1)

   factory2 = WebSocketServerFactory("ws://localhost:9000",
                                     debug = debug,
                                     debugCodePaths = debug)
   factory2.protocol = Echo2ServerProtocol
   resource2 = WebSocketResource(factory2)

   ## Establish a dummy root resource
   root = Data("", "text/plain")

   ## and our WebSocket servers under different paths ..
   root.putChild("echo1", resource1)
   root.putChild("echo2", resource2)

   ## both under one Twisted Web Site
   site = Site(root)
   reactor.listenTCP(9000, site)

   reactor.run()
开发者ID:Aerobota,项目名称:autobahn_rce,代码行数:30,代码来源:server2.py


示例15: GuardTests

class GuardTests(TestCase):
    """
    Tests for interaction with L{twisted.web.guard}.
    """
    def setUp(self):
        self.avatar_content = b"avatar content"
        self.child_content = b"child content"
        self.grandchild_content = b"grandchild content"

        grandchild = Data(self.grandchild_content, b"text/plain")

        child = Data(self.child_content, b"text/plain")
        child.putChild(b"grandchild", grandchild)

        self.avatar = Data(self.avatar_content, b"text/plain")
        self.avatar.putChild(b"child", child)

        self.realm = OneIResourceAvatarRealm(self.avatar)
        self.portal = Portal(
            self.realm,
            [AllowAnonymousAccess()],
        )
        self.guard = HTTPAuthSessionWrapper(
            self.portal,
            [BasicCredentialFactory("example.com")],
        )

    def test_avatar(self):
        """
        A request for exactly the guarded resource results in the avatar returned
        by cred.
        """
        root = Page()
        root.child_guarded = self.guard

        actual = self.successResultOf(
            renderResourceReturnTransport(
                root,
                b"/guarded",
                b"GET",
            ),
        )
        self.assertIn(self.avatar_content, actual)

    def test_child(self):
        """
        A request for a direct child of the guarded resource results in that child
        of the avatar returned by cred.
        """
        root = Page()
        root.child_guarded = self.guard

        actual = self.successResultOf(
            renderResourceReturnTransport(
                root,
                b"/guarded/child",
                b"GET",
            ),
        )
        self.assertIn(self.child_content, actual)

    def test_grandchild(self):
        """
        A request for a grandchild of the guarded resource results in that
        grandchild of the avatar returned by cred.

        Ideally this test would be redundant with L{test_child} but the
        implementation of L{IResource} support results in different codepaths
        for the 1st descendant vs the Nth descendant.
        """
        root = Page()
        root.child_guarded = self.guard

        actual = self.successResultOf(
            renderResourceReturnTransport(
                root,
                b"/guarded/child/grandchild",
                b"GET",
            ),
        )
        self.assertIn(self.grandchild_content, actual)
开发者ID:twisted,项目名称:nevow,代码行数:81,代码来源:test_appserver.py


示例16: render_POST

 def render_POST(self, request):
     self.posted += (request.content.read(),)
     return Data.render_GET(self, request)
开发者ID:mithrandi,项目名称:txaws,代码行数:3,代码来源:test_route53.py


示例17: HTTPAuthHeaderTests

class HTTPAuthHeaderTests(unittest.TestCase):
    """
    Tests for L{HTTPAuthSessionWrapper}.
    """
    makeRequest = DummyRequest

    def setUp(self):
        """
        Create a realm, portal, and L{HTTPAuthSessionWrapper} to use in the tests.
        """
        self.username = 'foo bar'
        self.password = 'bar baz'
        self.avatarContent = "contents of the avatar resource itself"
        self.childName = "foo-child"
        self.childContent = "contents of the foo child of the avatar"
        self.checker = InMemoryUsernamePasswordDatabaseDontUse()
        self.checker.addUser(self.username, self.password)
        self.avatar = Data(self.avatarContent, 'text/plain')
        self.avatar.putChild(
            self.childName, Data(self.childContent, 'text/plain'))
        self.avatars = {self.username: self.avatar}
        self.realm = Realm(self.avatars.get)
        self.portal = portal.Portal(self.realm, [self.checker])
        self.credentialFactories = []
        self.wrapper = HTTPAuthSessionWrapper(
            self.portal, self.credentialFactories)


    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)


    def test_getChildWithDefault(self):
        """
        Resource traversal which encounters an L{HTTPAuthSessionWrapper}
        results in an L{UnauthorizedResource} instance when the request does
        not have the required I{Authorization} headers.
        """
        request = self.makeRequest([self.childName])
        child = getChildForRequest(self.wrapper, request)
        d = request.notifyFinish()
        def cbFinished(result):
            self.assertEquals(request.responseCode, 401)
        d.addCallback(cbFinished)
        request.render(child)
        return d


    def _invalidAuthorizationTest(self, response):
        """
        Create a request with the given value as the value of an
        I{Authorization} header and perform resource traversal with it,
        starting at C{self.wrapper}.  Assert that the result is a 401 response
        code.  Return a L{Deferred} which fires when this is all done.
        """
        self.credentialFactories.append(BasicCredentialFactory('example.com'))
        request = self.makeRequest([self.childName])
        request.headers['authorization'] = response
        child = getChildForRequest(self.wrapper, request)
        d = request.notifyFinish()
        def cbFinished(result):
            self.assertEqual(request.responseCode, 401)
        d.addCallback(cbFinished)
        request.render(child)
        return d


    def test_getChildWithDefaultUnauthorizedUser(self):
        """
        Resource traversal which enouncters an L{HTTPAuthSessionWrapper}
        results in an L{UnauthorizedResource} when the request has an
        I{Authorization} header with a user which does not exist.
        """
        return self._invalidAuthorizationTest('Basic ' + b64encode('foo:bar'))


    def test_getChildWithDefaultUnauthorizedPassword(self):
        """
        Resource traversal which enouncters an L{HTTPAuthSessionWrapper}
        results in an L{UnauthorizedResource} when the request has an
        I{Authorization} header with a user which exists and the wrong
        password.
        """
        return self._invalidAuthorizationTest(
            'Basic ' + b64encode(self.username + ':bar'))


    def test_getChildWithDefaultUnrecognizedScheme(self):
        """
        Resource traversal which enouncters an L{HTTPAuthSessionWrapper}
        results in an L{UnauthorizedResource} when the request has an
        I{Authorization} header with an unrecognized scheme.
        """
#.........这里部分代码省略.........
开发者ID:jxta,项目名称:cc,代码行数:101,代码来源:test_httpauth.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python static.File类代码示例发布时间:2022-05-27
下一篇:
Python server.Site类代码示例发布时间: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