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

Python defer.wFD函数代码示例

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

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



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

示例1: testGroupMessage

    def testGroupMessage(self):
        user = wFD(self._loggedInUser(u'useruser'))
        yield user
        user = user.getResult()

        add = wFD(self.realm.createGroup(u"somechannel"))
        yield add
        somechannel = add.getResult()

        user.write("JOIN #somechannel\r\n")

        other = wFD(self._loggedInUser(u'otheruser'))
        yield other
        other = other.getResult()

        other.write("JOIN #somechannel\r\n")

        user.transport.clear()
        other.transport.clear()

        user.write('PRIVMSG #somechannel :Hello, world.\r\n')

        response = self._response(user)
        event = self._response(other)

        self.failIf(response)
        self.assertEqual(len(event), 1)
        self.assertEqual(event[0][0], '[email protected]')
        self.assertEqual(event[0][1], 'PRIVMSG', -1)
        self.assertEqual(event[0][2], ['#somechannel', 'Hello, world.'])
开发者ID:GunioRobot,项目名称:twisted,代码行数:30,代码来源:test_service.py


示例2: testPrivateMessage

    def testPrivateMessage(self):
        user = wFD(self._loggedInUser(u'useruser'))
        yield user
        user = user.getResult()

        other = wFD(self._loggedInUser(u'otheruser'))
        yield other
        other = other.getResult()

        user.transport.clear()
        other.transport.clear()

        user.write('PRIVMSG otheruser :Hello, monkey.\r\n')

        response = self._response(user)
        event = self._response(other)

        self.failIf(response)
        self.assertEqual(len(event), 1)
        self.assertEqual(event[0][0], '[email protected]')
        self.assertEqual(event[0][1], 'PRIVMSG')
        self.assertEqual(event[0][2], ['otheruser', 'Hello, monkey.'])

        user.write('PRIVMSG nousernamedthis :Hello, monkey.\r\n')

        response = self._response(user)

        self.assertEqual(len(response), 1)
        self.assertEqual(response[0][0], 'realmname')
        self.assertEqual(response[0][1], '401')
        self.assertEqual(response[0][2], ['useruser', 'nousernamedthis', 'No such nick/channel.'])
开发者ID:GunioRobot,项目名称:twisted,代码行数:31,代码来源:test_service.py


示例3: testWhois

    def testWhois(self):
        user = wFD(self._loggedInUser(u'someguy'))
        yield user
        user = user.getResult()

        otherguy = service.User("otherguy")
        otherguy.itergroups = lambda: iter([
            service.Group('groupA'),
            service.Group('groupB')])
        otherguy.signOn = 10
        otherguy.lastMessage = time.time() - 15

        add = wFD(self.realm.addUser(otherguy))
        yield add
        add.getResult()

        user.transport.clear()
        user.write('WHOIS otherguy\r\n')
        r = self._response(user)

        self.assertEqual(len(r), 5)
        wuser, wserver, idle, channels, end = r

        self.assertEqual(wuser[0], 'realmname')
        self.assertEqual(wuser[1], '311')
        self.assertEqual(wuser[2][0], 'someguy')
        self.assertEqual(wuser[2][1], 'otherguy')
        self.assertEqual(wuser[2][2], 'otherguy')
        self.assertEqual(wuser[2][3], 'realmname')
        self.assertEqual(wuser[2][4], '*')
        self.assertEqual(wuser[2][5], 'otherguy')

        self.assertEqual(wserver[0], 'realmname')
        self.assertEqual(wserver[1], '312')
        self.assertEqual(wserver[2][0], 'someguy')
        self.assertEqual(wserver[2][1], 'otherguy')
        self.assertEqual(wserver[2][2], 'realmname')
        self.assertEqual(wserver[2][3], 'Hi mom!')

        self.assertEqual(idle[0], 'realmname')
        self.assertEqual(idle[1], '317')
        self.assertEqual(idle[2][0], 'someguy')
        self.assertEqual(idle[2][1], 'otherguy')
        self.assertEqual(idle[2][2], '15')
        self.assertEqual(idle[2][3], '10')
        self.assertEqual(idle[2][4], "seconds idle, signon time")

        self.assertEqual(channels[0], 'realmname')
        self.assertEqual(channels[1], '319')
        self.assertEqual(channels[2][0], 'someguy')
        self.assertEqual(channels[2][1], 'otherguy')
        self.assertEqual(channels[2][2], '#groupA #groupB')

        self.assertEqual(end[0], 'realmname')
        self.assertEqual(end[1], '318')
        self.assertEqual(end[2][0], 'someguy')
        self.assertEqual(end[2][1], 'otherguy')
        self.assertEqual(end[2][2], 'End of WHOIS list.')
开发者ID:GunioRobot,项目名称:twisted,代码行数:58,代码来源:test_service.py


示例4: testJoin

    def testJoin(self):
        firstuser = wFD(self.realm.lookupUser(u'firstuser'))
        yield firstuser
        firstuser = firstuser.getResult()

        somechannel = wFD(self.realm.createGroup(u"somechannel"))
        yield somechannel
        somechannel = somechannel.getResult()

        somechannel.meta['topic'] = 'some random topic'

        # Bring in one user, make sure he gets into the channel sanely
        user = TestCaseUserAgg(firstuser, self.realm, self.factory)
        self._login(user, "firstuser")
        user.transport.clear()
        user.write('JOIN #somechannel\r\n')

        response = self._response(user)
        self.assertEqual(len(response), 5)

        # Join message
        self.assertEqual(response[0][0], '[email protected]')
        self.assertEqual(response[0][1], 'JOIN')
        self.assertEqual(response[0][2], ['#somechannel'])

        # User list
        self.assertEqual(response[1][1], '353')
        self.assertEqual(response[2][1], '366')

        # Topic (or lack thereof, as the case may be)
        self.assertEqual(response[3][1], '332')
        self.assertEqual(response[4][1], '333')


        # Hook up another client!  It is a CHAT SYSTEM!!!!!!!
        other = wFD(self._loggedInUser(u'otheruser'))
        yield other
        other = other.getResult()

        other.transport.clear()
        user.transport.clear()
        other.write('JOIN #somechannel\r\n')

        # At this point, both users should be in the channel
        response = self._response(other)

        event = self._response(user)
        self.assertEqual(len(event), 1)
        self.assertEqual(event[0][0], '[email protected]')
        self.assertEqual(event[0][1], 'JOIN')
        self.assertEqual(event[0][2], ['#somechannel'])

        self.assertEqual(response[1][0], 'realmname')
        self.assertEqual(response[1][1], '353')
        self.assertEqual(response[1][2], ['otheruser', '=', '#somechannel', 'firstuser otheruser'])
开发者ID:GunioRobot,项目名称:twisted,代码行数:55,代码来源:test_service.py


示例5: testGroupAddition

    def testGroupAddition(self):
        realm = service.InMemoryWordsRealm("realmname")

        p = service.Group("testgroup")
        d = wFD(realm.addGroup(p))
        yield d
        d.getResult()

        d = wFD(realm.getGroup(u"testGroup"))
        yield d
        group = d.getResult()

        self.assertIdentical(p, group)
开发者ID:GunioRobot,项目名称:twisted,代码行数:13,代码来源:test_service.py


示例6: testGroupUsernameCollision

    def testGroupUsernameCollision(self):
        """
        Try creating a group with the same name as an existing user and
        assert that it succeeds, since users and groups should not be in the
        same namespace and collisions should be impossible.
        """
        realm = service.InMemoryWordsRealm("realmname")

        d = wFD(realm.createUser(u"test"))
        yield d
        user = d.getResult()

        d = wFD(realm.createGroup(u"test"))
        yield d
        group = d.getResult()
开发者ID:GunioRobot,项目名称:twisted,代码行数:15,代码来源:test_service.py


示例7: testLeave

    def testLeave(self):
        user = wFD(self._loggedInUser(u'useruser'))
        yield user
        user = user.getResult()

        somechannel = wFD(self.realm.createGroup(u"somechannel"))
        yield somechannel
        somechannel = somechannel.getResult()

        user.write('JOIN #somechannel\r\n')
        user.transport.clear()

        other = wFD(self._loggedInUser(u'otheruser'))
        yield other
        other = other.getResult()

        other.write('JOIN #somechannel\r\n')

        user.transport.clear()
        other.transport.clear()

        user.write('PART #somechannel\r\n')

        response = self._response(user)
        event = self._response(other)

        self.assertEqual(len(response), 1)
        self.assertEqual(response[0][0], '[email protected]')
        self.assertEqual(response[0][1], 'PART')
        self.assertEqual(response[0][2], ['#somechannel', 'leaving'])
        self.assertEqual(response, event)

        # Now again, with a part message
        user.write('JOIN #somechannel\r\n')

        user.transport.clear()
        other.transport.clear()

        user.write('PART #somechannel :goodbye stupidheads\r\n')

        response = self._response(user)
        event = self._response(other)

        self.assertEqual(len(response), 1)
        self.assertEqual(response[0][0], '[email protected]')
        self.assertEqual(response[0][1], 'PART')
        self.assertEqual(response[0][2], ['#somechannel', 'goodbye stupidheads'])
        self.assertEqual(response, event)
开发者ID:GunioRobot,项目名称:twisted,代码行数:48,代码来源:test_service.py


示例8: testGroupRetrieval

    def testGroupRetrieval(self):
        realm = service.InMemoryWordsRealm("realmname")

        d = wFD(realm.createGroup(u"testgroup"))
        yield d
        group = d.getResult()

        d = wFD(realm.getGroup(u"testgroup"))
        yield d
        retrieved = d.getResult()

        self.assertIdentical(group, retrieved)

        d = wFD(realm.getGroup(u"nosuchgroup"))
        yield d
        self.assertRaises(ewords.NoSuchGroup, d.getResult)
开发者ID:GunioRobot,项目名称:twisted,代码行数:16,代码来源:test_service.py


示例9: _loggedInUser

 def _loggedInUser(self, name):
     d = wFD(self.realm.lookupUser(name))
     yield d
     user = d.getResult()
     agg = TestCaseUserAgg(user, self.realm, self.factory)
     self._login(agg, name)
     yield agg
开发者ID:GunioRobot,项目名称:twisted,代码行数:7,代码来源:test_service.py


示例10: testSetTopic

    def testSetTopic(self):
        user = wFD(self._loggedInUser(u'useruser'))
        yield user
        user = user.getResult()

        add = wFD(self.realm.createGroup(u"somechannel"))
        yield add
        somechannel = add.getResult()

        user.write("JOIN #somechannel\r\n")

        other = wFD(self._loggedInUser(u'otheruser'))
        yield other
        other = other.getResult()

        other.write("JOIN #somechannel\r\n")

        user.transport.clear()
        other.transport.clear()

        other.write('TOPIC #somechannel :This is the new topic.\r\n')

        response = self._response(other)
        event = self._response(user)

        self.assertEqual(response, event)

        self.assertEqual(response[0][0], '[email protected]')
        self.assertEqual(response[0][1], 'TOPIC')
        self.assertEqual(response[0][2], ['#somechannel', 'This is the new topic.'])

        other.transport.clear()

        somechannel.meta['topic_date'] = 12345
        other.write('TOPIC #somechannel\r\n')

        response = self._response(other)
        self.assertEqual(response[0][1], '332')
        self.assertEqual(response[0][2], ['otheruser', '#somechannel', 'This is the new topic.'])
        self.assertEqual(response[1][1], '333')
        self.assertEqual(response[1][2], ['otheruser', '#somechannel', 'otheruser', '12345'])

        other.transport.clear()
        other.write('TOPIC #asdlkjasd\r\n')

        response = self._response(other)
        self.assertEqual(response[0][1], '403')
开发者ID:GunioRobot,项目名称:twisted,代码行数:47,代码来源:test_service.py


示例11: testEnumeration

    def testEnumeration(self):
        realm = service.InMemoryWordsRealm("realmname")
        d = wFD(realm.createGroup(u"groupone"))
        yield d
        d.getResult()

        d = wFD(realm.createGroup(u"grouptwo"))
        yield d
        d.getResult()

        groups = wFD(realm.itergroups())
        yield groups
        groups = groups.getResult()

        n = [g.name for g in groups]
        n.sort()
        self.assertEqual(n, ["groupone", "grouptwo"])
开发者ID:GunioRobot,项目名称:twisted,代码行数:17,代码来源:test_service.py


示例12: testSetGroupMode

    def testSetGroupMode(self):
        user = wFD(self._loggedInUser(u'useruser'))
        yield user
        user = user.getResult()

        group = wFD(self.realm.createGroup(u"groupname"))
        yield group
        group = group.getResult()

        user.write('JOIN #groupname\r\n')

        user.transport.clear()
        user.write('MODE #groupname +abcd\r\n')

        response = self._response(user)
        self.assertEqual(len(response), 1)
        self.assertEqual(response[0][1], '472')
开发者ID:GunioRobot,项目名称:twisted,代码行数:17,代码来源:test_service.py


示例13: testList

    def testList(self):
        user = wFD(self._loggedInUser(u"someuser"))
        yield user
        user = user.getResult()
        user.transport.clear()

        somegroup = wFD(self.realm.createGroup(u"somegroup"))
        yield somegroup
        somegroup = somegroup.getResult()
        somegroup.size = lambda: succeed(17)
        somegroup.meta['topic'] = 'this is the topic woo'

        # Test one group
        user.write('LIST #somegroup\r\n')

        r = self._response(user)
        self.assertEqual(len(r), 2)
        resp, end = r

        self.assertEqual(resp[0], 'realmname')
        self.assertEqual(resp[1], '322')
        self.assertEqual(resp[2][0], 'someuser')
        self.assertEqual(resp[2][1], 'somegroup')
        self.assertEqual(resp[2][2], '17')
        self.assertEqual(resp[2][3], 'this is the topic woo')

        self.assertEqual(end[0], 'realmname')
        self.assertEqual(end[1], '323')
        self.assertEqual(end[2][0], 'someuser')
        self.assertEqual(end[2][1], 'End of /LIST')

        user.transport.clear()
        # Test all groups

        user.write('LIST\r\n')
        r = self._response(user)
        self.assertEqual(len(r), 2)

        fg1, end = r

        self.assertEqual(fg1[1], '322')
        self.assertEqual(fg1[2][1], 'somegroup')
        self.assertEqual(fg1[2][2], '17')
        self.assertEqual(fg1[2][3], 'this is the topic woo')

        self.assertEqual(end[1], '323')
开发者ID:GunioRobot,项目名称:twisted,代码行数:46,代码来源:test_service.py


示例14: testGetGroupMode

    def testGetGroupMode(self):
        user = wFD(self._loggedInUser(u'useruser'))
        yield user
        user = user.getResult()

        add = wFD(self.realm.createGroup(u"somechannel"))
        yield add
        somechannel = add.getResult()

        user.write('JOIN #somechannel\r\n')

        user.transport.clear()
        user.write('MODE #somechannel\r\n')

        response = self._response(user)
        self.assertEqual(len(response), 1)
        self.assertEqual(response[0][1], '324')
开发者ID:GunioRobot,项目名称:twisted,代码行数:17,代码来源:test_service.py


示例15: testGroups

    def testGroups(self):
        mindone = TestMind()
        one = wFD(self._loggedInAvatar(u"one", "p1", mindone))
        yield one
        one = one.getResult()

        mindtwo = TestMind()
        two = wFD(self._loggedInAvatar(u"two", "p2", mindtwo))
        yield two
        two = two.getResult()

        add = wFD(self.realm.createGroup(u"foobar"))
        yield add
        add.getResult()

        groupone = wFD(one.join(u"foobar"))
        yield groupone
        groupone = groupone.getResult()

        grouptwo = wFD(two.join(u"foobar"))
        yield grouptwo
        grouptwo = grouptwo.getResult()

        msg = wFD(groupone.send({"text": "hello, monkeys"}))
        yield msg
        msg = msg.getResult()

        leave = wFD(groupone.leave())
        yield leave
        leave = leave.getResult()
开发者ID:GunioRobot,项目名称:twisted,代码行数:30,代码来源:test_service.py


示例16: testWho

    def testWho(self):
        group = service.Group('groupname')
        add = wFD(self.realm.addGroup(group))
        yield add
        add.getResult()

        users = []
        for nick in u'userone', u'usertwo', u'userthree':
            u = wFD(self._loggedInUser(nick))
            yield u
            u = u.getResult()
            users.append(u)
            users[-1].write('JOIN #groupname\r\n')
        for user in users:
            user.transport.clear()

        users[0].write('WHO #groupname\r\n')

        r = self._response(users[0])
        self.failIf(self._response(users[1]))
        self.failIf(self._response(users[2]))

        wantusers = ['userone', 'usertwo', 'userthree']
        for (prefix, code, stuff) in r[:-1]:
            self.assertEqual(prefix, 'realmname')
            self.assertEqual(code, '352')

            (myname, group, theirname, theirhost, theirserver, theirnick, flag, extra) = stuff
            self.assertEqual(myname, 'userone')
            self.assertEqual(group, '#groupname')
            self.failUnless(theirname in wantusers)
            self.assertEqual(theirhost, 'realmname')
            self.assertEqual(theirserver, 'realmname')
            wantusers.remove(theirnick)
            self.assertEqual(flag, 'H')
            self.assertEqual(extra, '0 ' + theirnick)
        self.failIf(wantusers)

        prefix, code, stuff = r[-1]
        self.assertEqual(prefix, 'realmname')
        self.assertEqual(code, '315')
        myname, channel, extra = stuff
        self.assertEqual(myname, 'userone')
        self.assertEqual(channel, '#groupname')
        self.assertEqual(extra, 'End of /WHO list.')
开发者ID:GunioRobot,项目名称:twisted,代码行数:45,代码来源:test_service.py


示例17: testFailedLogin

    def testFailedLogin(self):
        firstuser = wFD(self.realm.lookupUser(u'firstuser'))
        yield firstuser
        firstuser = firstuser.getResult()

        user = TestCaseUserAgg(firstuser, self.realm, self.factory)
        self._login(user, "firstuser", "wrongpass")
        response = self._response(user, "PRIVMSG")
        self.assertEqual(len(response), 1)
        self.assertEqual(response[0][2], ['firstuser', 'Login failed.  Goodbye.'])
开发者ID:GunioRobot,项目名称:twisted,代码行数:10,代码来源:test_service.py


示例18: testSetUserMode

    def testSetUserMode(self):
        user = wFD(self._loggedInUser(u'useruser'))
        yield user
        user = user.getResult()

        user.transport.clear()
        user.write('MODE useruser +abcd\r\n')

        response = self._response(user)
        self.assertEqual(len(response), 1)
        self.assertEqual(response[0][1], '472')
开发者ID:GunioRobot,项目名称:twisted,代码行数:11,代码来源:test_service.py


示例19: testOper

    def testOper(self):
        user = wFD(self._loggedInUser(u'useruser'))
        yield user
        user = user.getResult()

        user.transport.clear()
        user.write('OPER user pass\r\n')
        response = self._response(user)

        self.assertEqual(len(response), 1)
        self.assertEqual(response[0][1], '491')
开发者ID:GunioRobot,项目名称:twisted,代码行数:11,代码来源:test_service.py


示例20: testLogout

    def testLogout(self):
        logout = []
        firstuser = wFD(self.realm.lookupUser(u'firstuser'))
        yield firstuser
        firstuser = firstuser.getResult()

        user = TestCaseUserAgg(firstuser, self.realm, self.factory)
        self._login(user, "firstuser")
        user.protocol.logout = lambda: logout.append(True)
        user.write('QUIT\r\n')
        self.assertEqual(logout, [True])
开发者ID:GunioRobot,项目名称:twisted,代码行数:11,代码来源:test_service.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python defer.waitForDeferred函数代码示例发布时间:2022-05-27
下一篇:
Python defer.succeed函数代码示例发布时间: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