本文整理汇总了Python中muss.locks.authority_of函数的典型用法代码示例。如果您正苦于以下问题:Python authority_of函数的具体用法?Python authority_of怎么用?Python authority_of使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了authority_of函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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.")
示例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))
示例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)
示例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 = []
示例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.")
示例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!")
示例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)
示例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)
示例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).")
示例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)
示例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)")
示例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")
示例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:")