本文整理汇总了Python中twisted.internet.defer.Deferred.notifying方法的典型用法代码示例。如果您正苦于以下问题:Python Deferred.notifying方法的具体用法?Python Deferred.notifying怎么用?Python Deferred.notifying使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.defer.Deferred
的用法示例。
在下文中一共展示了Deferred.notifying方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tell
# 需要导入模块: from twisted.internet.defer import Deferred [as 别名]
# 或者: from twisted.internet.defer.Deferred import notifying [as 别名]
def tell(self, about, receivers, command, **kwargs):
"""send info about player 'about' to users 'receivers'"""
def encodeKwargs():
"""those values are classes like Meld, Tile etc.
Convert to str(python2) or bytes(python3"""
for keyword in ('tile', 'tiles', 'meld', 'melds'):
if keyword in kwargs:
kwargs[keyword] = str(kwargs[keyword]).encode()
encodeKwargs()
if about.__class__.__name__ == 'User':
about = self.playerForUser(about)
if not isinstance(receivers, list):
receivers = list([receivers])
assert receivers, 'DeferredBlock.tell(%s) has no receiver' % command
self.__enrichMessage(self.table.game, about, command, kwargs)
aboutName = about.name if about else None
if self.table.running and len(receivers) in [1, 4]:
# messages are either identical for all 4 players
# or identical for 3 players and different for 1 player. And
# we want to capture each message exactly once.
self.table.game.appendMove(about, command, kwargs)
localDeferreds = []
for rec in self.__convertReceivers(receivers):
isClient = rec.__class__.__name__.endswith('Client')
if Debug.traffic and not isClient:
message = u'-> {receiver:<15} about {about} {command}{kwargs}'.format(
receiver=rec.name[:15], about=about, command=command,
kwargs=Move.prettyKwargs(kwargs))
logDebug(message)
if isClient:
defer = Deferred()
defer.addCallback(rec.remote_move, command, **kwargs)
else:
defer = self.table.server.callRemote(
rec,
'move',
aboutName,
command.name,
**kwargs)
if defer:
defer.command = command.name
defer.notifying = 'notifying' in kwargs
self.__addRequest(defer, rec, about)
else:
msg = m18nE('The game server lost connection to player %1')
self.table.abort(msg, rec.name)
if isClient:
localDeferreds.append(defer)
for defer in localDeferreds:
defer.callback(aboutName) # callback needs an argument !