コード例 #1
0
ファイル: __init__.py プロジェクト: ComradeDOS/twilix
 def leave_room(self, presence, room_jid, nickname):
     """
     Sends 'unavailable'-type presence which leaves client from the room.
     Fails if user not in room.
     
     :param room_jid: JID of room-conference
     :param nickname: string-type client's nickname in conference
     
     """
     reciever = internJID(room_jid)
     
     assert reciever.bare() in self.roster, 'not in room'
     
     reciever.resource = nickname
     
     presence = MyElement.makeFromElement(presence)
     presence = Presence.createFromElement(presence)
     
     presence.to = reciever
     presence.from_ = self.dispatcher.myjid
     presence.type_ = 'unavailable'
     
     msg = ConnectPresence(parent=presence)
     
     self.dispatcher.send(msg.parent)
     
     del self.roster[reciever.bare()]
コード例 #2
0
ファイル: __init__.py プロジェクト: ComradeDOS/twilix
    def enter_room(self, presence, room_jid, nickname):
        """
        Sends 'available'-type presence which allows client to enter the room.
        Fails if user already in room.
        
        :param room_jid: JID of room-conference
        :param nickname: string-type client's nickname in conference
        :param status: string-type client's status message
        
        """
        reciever = internJID(room_jid)
        
        assert reciever.bare() not in self.roster, 'already in room'
        
        reciever.resource = nickname
 
        presence = MyElement.makeFromElement(presence)
        presence = Presence.createFromElement(presence)
 
        presence.to = reciever
        presence.from_ = self.dispatcher.myjid
        
        msg = ConnectPresence(parent=presence)
        
        self.roster[reciever.bare()] = []
        
        self.dispatcher.send(msg.parent)
コード例 #3
0
ファイル: fields.py プロジェクト: malinoff/twilix
 def clean_set(self, value):
     """
     Return MyElement with value as content or EmptyElement if value
     is empty.
     
     :returns:
         MyElement with value as content.
         
         EmptyElement if value is empty.        
         
     """
     if value is None:
         return EmptyElement()
     value = super(StringNode, self).clean_set(value)
     r = MyElement((self.uri, self.xmlnode))
     r.content = unicode(value)
     return r
コード例 #4
0
 def clean_set(self, value):
     """
     Return MyElement with value as content or EmptyElement if value
     is empty.
     
     :returns:
         MyElement with value as content.
         
         EmptyElement if value is empty.        
         
     """
     if value is None:
         return EmptyElement()
     value = super(StringNode, self).clean_set(value)
     r = MyElement((self.uri, self.xmlnode))
     r.content = unicode(value)
     return r
コード例 #5
0
    def clean_set(self, value):
        """

        :returns:
             MyElement if value is exist.
            
             EmptyElement otherwise.
            
        """
        if value:
            return MyElement((None, self.xmlnode))
        return EmptyElement()
コード例 #6
0
ファイル: dispatcher.py プロジェクト: rogovvladimir/twilix
    def dispatch(self, el):
        """
        This function realize incoming data handling.
        
        There is a handling :
        
        -- returns callback/errorback value for result/error-type stanzas
        
        -- calls handlers for other stanzas and then send the results
        
        :param el: is an input stanza
        
        """
        results = []
        el = MyElement.makeFromElement(el)
        for cls in (Iq, Message, Presence):
            try:
                el = cls.createFromElement(el, dont_defer=True)
            except WrongElement:
                pass

        if el.type_ in ('result', 'error') and self._callbacks.has_key(el.id):
            # XXX: check sender here
            id = el.id
            deferred, result_class, error_class = self._callbacks[id]
            if result_class is not None and el.type_ == 'result':
                try:
                    el = result_class.createFromElement(el, host=None)
                # XXX: catch any exception here
                except (WrongElement, ElementParseError), e:
                    deferred.errback(e)
                else:
                    deferred.callback(el)
            elif result_class is None and el.type_ == 'result':
                deferred.callback(el)
            elif el.type_ == 'error':
                exception = None
                try:
                    err = error_class.createFromElement(el,
                                                        host=None,
                                                        dispatcher=self)
                except (WrongElement, ElementParseError), e:
                    exception = e
                if exception is None:
                    exception = errors.exception_by_condition(
                        err.error.condition)
                deferred.errback(exception)
コード例 #7
0
ファイル: dispatcher.py プロジェクト: ComradeDOS/twilix
    def dispatch(self, el):
        """
        This function realize incoming data handling.
        
        There is a handling :
        
        -- returns callback/errorback value for result/error-type stanzas
        
        -- calls handlers for other stanzas and then send the results
        
        :param el: is an input stanza
        
        """
        results = []
        el = MyElement.makeFromElement(el)
        for cls in (Iq, Message, Presence):
            try:
                el = cls.createFromElement(el, dont_defer=True)
            except WrongElement:
                pass

        if el.type_ in ('result', 'error') and self._callbacks.has_key(el.id):
            # XXX: check sender here
            id = el.id
            deferred, result_class, error_class = self._callbacks[id]
            if result_class is not None and el.type_ == 'result':
                try:
                    el = result_class.createFromElement(el, host=None)
                # XXX: catch any exception here
                except (WrongElement, ElementParseError), e:
                    deferred.errback(e)
                else:
                    deferred.callback(el)
            elif result_class is None and el.type_ == 'result':
                deferred.callback(el)
            elif el.type_ == 'error':
                exception = None
                try:
                    err = error_class.createFromElement(el, host=None,
                                                        dispatcher=self)
                except (WrongElement, ElementParseError), e:
                    exception = e
                if exception is None:
                    exception = errors.exception_by_condition(err.error.condition)
                deferred.errback(exception)
コード例 #8
0
ファイル: fields.py プロジェクト: malinoff/twilix
 def clean_set(self, value):
     """Return MyElement with value cast to base64 as content."""
     if value is not None:
         r = MyElement((None, self.xmlnode))
         r.content = base64.b64encode(value)
         return r
コード例 #9
0
 def clean_set(self, value):
     return MyElement((self.cls.elementUri, value))
コード例 #10
0
 def clean_set(self, value):
     """Return MyElement with value cast to base64 as content."""
     if value is not None:
         r = MyElement((None, self.xmlnode))
         r.content = base64.b64encode(value)
         return r