comparison src/plugins/plugin_misc_room_game.py @ 849:c5a8f602662b

plugin room_game, radiocol: RoomGame.send returns a Deferred.
author souliane <souliane@mailoo.org>
date Tue, 18 Feb 2014 17:49:33 +0100
parents f3513c8cc2e6
children 3c270d691e56
comparison
equal deleted inserted replaced
848:d40306d1da70 849:c5a8f602662b
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from logging import debug, warning, error 21 from logging import debug, warning, error
22 from twisted.words.protocols.jabber.jid import JID 22 from twisted.words.protocols.jabber.jid import JID
23 from twisted.words.xish import domish 23 from twisted.words.xish import domish
24 from twisted.internet import defer
24 from time import time 25 from time import time
25 from wokkel import disco, iwokkel 26 from wokkel import disco, iwokkel
26 from zope.interface import implements 27 from zope.interface import implements
27 import copy 28 import copy
28 try: 29 try:
615 - unicode name or couple (uri, name) to create a new domish.Element 616 - unicode name or couple (uri, name) to create a new domish.Element
616 and add it as a child to the message (see domish.Element.addElement) 617 and add it as a child to the message (see domish.Element.addElement)
617 - attrs: dictionary of attributes for the new child 618 - attrs: dictionary of attributes for the new child
618 - content: unicode that is appended to the child content 619 - content: unicode that is appended to the child content
619 @param profile: the profile from which the message is sent 620 @param profile: the profile from which the message is sent
621 @return: a Deferred instance
620 """ 622 """
621 if profile is None: 623 if profile is None:
622 error(_("Message can not be sent without a sender profile")) 624 error(_("Message can not be sent without a sender profile"))
623 return 625 return defer.fail(None)
624 msg = self._createGameElt(to_jid) 626 msg = self._createGameElt(to_jid)
625 for elem, attrs, content in data: 627 for elem, attrs, content in data:
626 if elem is not None: 628 if elem is not None:
627 if isinstance(elem, domish.Element): 629 if isinstance(elem, domish.Element):
628 msg.firstChildElement().addChild(elem) 630 msg.firstChildElement().addChild(elem)
631 if attrs is not None: 633 if attrs is not None:
632 elem.attributes.update(attrs) 634 elem.attributes.update(attrs)
633 if content is not None: 635 if content is not None:
634 elem.addContent(content) 636 elem.addContent(content)
635 self.host.profiles[profile].xmlstream.send(msg) 637 self.host.profiles[profile].xmlstream.send(msg)
638 return defer.succeed(None)
636 639
637 def send(self, to_jid, elem=None, attrs=None, content=None, profile=None): 640 def send(self, to_jid, elem=None, attrs=None, content=None, profile=None):
638 """ 641 """
639 @param to_jid: recipient JID 642 @param to_jid: recipient JID
640 @param elem: domish.Element, unicode or a couple: 643 @param elem: domish.Element, unicode or a couple:
642 - unicode name or couple (uri, name) to create a new domish.Element 645 - unicode name or couple (uri, name) to create a new domish.Element
643 and add it as a child to the message (see domish.Element.addElement) 646 and add it as a child to the message (see domish.Element.addElement)
644 @param attrs: dictionary of attributes for the new child 647 @param attrs: dictionary of attributes for the new child
645 @param content: unicode that is appended to the child content 648 @param content: unicode that is appended to the child content
646 @param profile: the profile from which the message is sent 649 @param profile: the profile from which the message is sent
647 """ 650 @return: a Deferred instance
648 self._sendElements(to_jid, [(elem, attrs, content)], profile) 651 """
652 return self._sendElements(to_jid, [(elem, attrs, content)], profile)
649 653
650 def getHandler(self, profile): 654 def getHandler(self, profile):
651 return RoomGameHandler(self) 655 return RoomGameHandler(self)
652 656
653 657