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

Python locks.authority_of函数代码示例

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

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



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

示例1: __init__

    def __init__(self, name, password):
        """
        Create a brand-new player and add it to the database.

        Args:
            name: The player's name.
            password: The player's password, in plaintext, to be discarded
                forever after this method call.
        """
        Object.__init__(self, name, location=get(0), owner=self)
        with locks.authority_of(locks.SYSTEM):
            self.type = 'player'
            self.lock_attr("name", set_lock=locks.Fail())
            self.lock_attr("owner", set_lock=locks.Fail())
            self.password = self.hash(password)
            self.textwrapper = textwrap.TextWrapper()
            # Initialize the mode stack empty, but enter_mode() must be called
            # before any input is handled.
            self.mode_stack = []
            self.lock_attr("mode_stack", set_lock=locks.Owns(self))
            self.last_told = None
        with locks.authority_of(self):
            self.locks.take = locks.Fail()
            self.locks.destroy = locks.Fail()
            # While we're under development, let's assume everybody wants debug
            # information.
            self.debug = True
            # Until there's a command to join a channel, do it automatically.
            channels._channels['Public'].join(self)
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:29,代码来源:db.py


示例2: test_move_insert_remove

 def test_move_insert_remove(self):
     with locks.authority_of(locks.SYSTEM):
         hat = db.Object("hat")
         magician = db.Object("magician")
     db.store(hat)
     db.store(magician)
     try:
         with locks.authority_of(magician):
             rabbit = db.Object("rabbit", hat)
     except locks.LockFailedError as e:
         self.assertEqual(str(e), "You can't put that in hat.")
     else:
         self.fail()
     with locks.authority_of(hat):
         hat.locks.insert = locks.Is(magician)
     with locks.authority_of(magician):
         rabbit = db.Object("rabbit", hat)
         db.store(rabbit)
         try:
             rabbit.location = magician
         except locks.LockFailedError as e:
             self.assertEqual(str(e), "You can't remove that from hat.")
         else:
             self.fail()
         with locks.authority_of(hat):
             hat.locks.remove = locks.Is(magician)
         rabbit.location = magician
     self.assertEqual(rabbit.location, magician)
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:28,代码来源:test_data.py


示例3: test_exit

    def test_exit(self):
        with locks.authority_of(locks.SYSTEM):
            owner = db.Object("owner")
        db.store(owner)
        with locks.authority_of(owner):
            source = db.Room("Source")
            dest = db.Room("Dest")
            db.store(source)
            db.store(dest)
            player = db.Object("Player", location=source)
            player.send = mock.MagicMock()
            db.store(player)
            exit = db.Exit("Exit", source, dest)
            exit.go_message = ("You, {player}, go from {source} to "
                               "{destination} via {exit}.")
            db.store(exit)
            sourceBystander = db.Object("source bystander", location=source)
            sourceBystander.send = mock.MagicMock()
            db.store(sourceBystander)
            destBystander = db.Object("dest bystander", location=dest)
            destBystander.send = mock.MagicMock()
            db.store(destBystander)

            self.assertIs(player.location, source)
            exit.go(player)
            self.assertIs(player.location, dest)
            self.assertEqual(sourceBystander.send.call_count, 1)
            self.assertEqual(destBystander.send.call_count, 1)

            sourceBystander.send.assert_called_once_with(
                "Player leaves through Exit.")
            destBystander.send.assert_called_once_with("Player arrives.")
            player.send.assert_called_with("You, Player, go from Source to "
                                           "Dest via Exit.")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:34,代码来源:test_data.py


示例4: setUp

    def setUp(self):
        super(AttrLockTestCase, self).setUp()

        self.obj_owner = db.Player("Objowner", "password")
        db.store(self.obj_owner)

        self.attr_owner = db.Player("Attrowner", "password")
        db.store(self.attr_owner)

        self.setter = db.Player("Setter", "password")
        db.store(self.setter)

        self.getter = db.Player("Getter", "password")
        db.store(self.getter)

        self.players = [self.obj_owner,
                        self.attr_owner,
                        self.getter,
                        self.setter]

        with locks.authority_of(self.obj_owner):
            self.obj = db.Object("Object")
            db.store(self.obj)
        with locks.authority_of(self.attr_owner):
            self.obj.attr = "value"
            self.obj.lock_attr("attr",
                               get_lock=locks.Is(self.getter),
                               set_lock=locks.Is(self.setter))
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:28,代码来源:test_locks.py


示例5: test_contextmanager_nested

 def test_contextmanager_nested(self):
     self.assertIs(locks._authority, None)
     with locks.authority_of(self.player):
         self.assertIs(locks._authority, self.player)
         with locks.authority_of(self.player2):
             self.assertIs(locks._authority, self.player2)
         self.assertIs(locks._authority, self.player)
     self.assertIs(locks._authority, None)
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:8,代码来源:test_locks.py


示例6: setUp

 def setUp(self):
     super(SocialTestCase, self).setUp()
     self.neighbor = self.new_player("Neighbor")
     self.otherneighbor = self.new_player("OtherNeighbor")
     self.notconnected = self.new_player("NotConnected")
     with locks.authority_of(locks.SYSTEM):
         self.notconnected.mode_stack = []
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:test_social.py


示例7: test_destroy_emit_elsewhere

 def test_destroy_emit_elsewhere(self):
     with locks.authority_of(self.player):
         new_room = db.Room("a room")
     db.store(new_room)
     self.player.send_line("destroy #{}".format(new_room.uid))
     self.assertNotEqual(self.neighbor.last_response(),
                         "Player destroys a room.")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:test_building.py


示例8: execute

 def execute(self, player, args):
     if getattr(player, "debug"):
         line = args["line"]
         with locks.authority_of(locks.SYSTEM):
             player.mode.handle(player, line)
     else:
         player.send("You're not set for debugging!")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:admin.py


示例9: send_line

 def send_line(self, command):
     """
     Send a string to this player's current mode, as if they'd
     typed it in at the console.
     """
     with locks.authority_of(self):
         self.mode.handle(self, command)
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:common_tools.py


示例10: test_neighbors

    def test_neighbors(self):
        with locks.authority_of(locks.SYSTEM):
            container = db.Object("container")
            foo = db.Object("foo", location=container)
            neighbor = db.Object("neighbor", location=container)
            containee = db.Object("containee", location=foo)
            distant = db.Object("distant")
            inside_neighbor = db.Object("inside neighbor", location=neighbor)
            inside_containee = db.Object("inside containee", location=containee)
        db.store(container)
        db.store(foo)
        db.store(neighbor)
        db.store(containee)
        db.store(distant)
        db.store(inside_neighbor)
        db.store(inside_containee)

        neighbors = foo.neighbors()
        self.assertIn(container, neighbors)
        self.assertIn(foo, neighbors)
        self.assertIn(neighbor, neighbors)
        self.assertIn(containee, neighbors)
        self.assertNotIn(distant, neighbors)
        self.assertNotIn(inside_neighbor, neighbors)
        self.assertNotIn(inside_containee, neighbors)
        self.assertEqual(len(neighbors), 4)
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:26,代码来源:test_data.py


示例11: test_many_exits_one_nospace

 def test_many_exits_one_nospace(self):
     with locks.authority_of(locks.SYSTEM):
         self.exit_zzza = db.Exit("zzza", self.lobby, self.lobby)
         self.exit_zzzb = db.Exit("zzzb", self.lobby, self.lobby)
     db.store(self.exit_zzza)
     db.store(self.exit_zzzb)
     self.assert_response("zzz foo", "Spaaaaaaaaaaaaaace. (foo).")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:test_handler.py


示例12: test_retrieve_none

    def test_retrieve_none(self):
        with locks.authority_of(locks.SYSTEM):
            foo = db.Object("foo")

        self.assertRaises(KeyError, db.find, lambda obj: obj.name == "bar")
        found = db.find_all(lambda obj: obj.name == "bar")
        self.assertEqual(len(found), 0)
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:test_data.py


示例13: test_position_string

 def test_position_string(self):
     with locks.authority_of(locks.SYSTEM):
         model = db.Object("model")
     db.store(model)
     model.position = "vogueing for the camera"
     self.assertEqual(model.position_string(),
                      "model (vogueing for the camera)")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:test_data.py


示例14: test_many_exits_and_commands

 def test_many_exits_and_commands(self):
     with locks.authority_of(locks.SYSTEM):
         self.exit_s1 = db.Exit("s1", self.lobby, self.lobby)
         self.exit_s2 = db.Exit("s2", self.lobby, self.lobby)
     db.store(self.exit_s1)
     db.store(self.exit_s2)
     self.assert_response("s", startswith="Which command do you mean")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:test_handler.py


示例15: test_many_exits_one_command

 def test_many_exits_one_command(self):
     with locks.authority_of(locks.SYSTEM):
         self.exit_h1 = db.Exit("h1", self.lobby, self.lobby)
         self.exit_h2 = db.Exit("h2", self.lobby, self.lobby)
     db.store(self.exit_h1)
     db.store(self.exit_h2)
     self.assert_response("h", startswith="Available commands:")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:test_handler.py


示例16: test_exit_nospace

 def test_exit_nospace(self):
     with locks.authority_of(locks.SYSTEM):
         self.foyer = db.Room("foyer")
         self.zzzfoo = db.Exit("zzzfoo", self.lobby, self.foyer)
     db.store(self.foyer)
     db.store(self.zzzfoo)
     self.assert_response("zzzfoo", "Spaaaaaaaaaaaaaace. (foo).")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:7,代码来源:test_handler.py


示例17: run_command

 def run_command(self, command, string):
     """
     Parse the string against the command's argument pattern, then
     execute the command on behalf of the player.
     """
     args = command.args(self.player).parseString(string)
     with locks.authority_of(self.player):
         command().execute(self.player, args)
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:8,代码来源:common_tools.py


示例18: setUp

 def setUp(self):
     self.patch(db, "_objects", {})
     self.patch(db, "_nextUid", 0)
     with locks.authority_of(locks.SYSTEM):
         self.lobby = db.Room("lobby")
     db.store(self.lobby)
     self.player = self.new_player("Player")
     self.neighbor = self.new_player("PlayersNeighbor")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:8,代码来源:common_tools.py


示例19: test_ambiguous_exit

 def test_ambiguous_exit(self):
     with locks.authority_of(locks.SYSTEM):
         self.foyer = db.Room("foyer")
         self.exit_ju = db.Exit("jump", self.lobby, self.foyer)
         self.exit_jo = db.Exit("joust", self.lobby, self.foyer)
     for obj in self.foyer, self.exit_ju, self.exit_jo:
         db.store(obj)
     self.assert_response("j", "Which exit do you mean? (joust, jump)")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:8,代码来源:test_handler.py


示例20: test_others_cannot_set

 def test_others_cannot_set(self):
     with locks.authority_of(self.getter):
         try:
             self.set()
         except locks.LockFailedError:
             pass
         else:
             self.fail("Expected LockFailedError when setting attribute")
开发者ID:mongolsamurai,项目名称:MUSS,代码行数:8,代码来源:test_locks.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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