예제 #1
0
    def join(self,
             room,
             nick,
             handler,
             password=None,
             history_maxchars=None,
             history_maxstanzas=None,
             history_seconds=None,
             history_since=None):
        """
        Create and return a new room state object and request joining
        to a MUC room.

        :Parameters:
            - `room`: the name of a room to be joined
            - `nick`: the nickname to be used in the room
            - `handler`: is an object to handle room events.
            - `password`: password for the room, if any
            - `history_maxchars`: limit of the total number of characters in
              history.
            - `history_maxstanzas`: limit of the total number of messages in
              history.
            - `history_seconds`: send only messages received in the last
              `history_seconds` seconds.
            - `history_since`: Send only the messages received since the
              dateTime specified (UTC).

        :Types:
            - `room`: `JID`
            - `nick`: `unicode`
            - `handler`: `MucRoomHandler`
            - `password`: `unicode`
            - `history_maxchars`: `int`
            - `history_maxstanzas`: `int`
            - `history_seconds`: `int`
            - `history_since`: `datetime.datetime`

        :return: the room state object created.
        :returntype: `MucRoomState`
        """

        if not room.node or room.resource:
            raise ValueError, "Invalid room JID"

        room_jid = JID(room.node, room.domain, nick)

        cur_rs = self.rooms.get(room_jid.bare().as_unicode())
        if cur_rs and cur_rs.joined:
            raise RuntimeError, "Room already joined"

        rs = MucRoomState(self, self.stream.me, room_jid, handler)
        self.rooms[room_jid.bare().as_unicode()] = rs
        rs.join(password, history_maxchars, history_maxstanzas,
                history_seconds, history_since)
        return rs
예제 #2
0
파일: muc.py 프로젝트: AdamPrzybyla/pyxmpp
    def join(self, room, nick, handler, password = None, history_maxchars = None,
            history_maxstanzas = None, history_seconds = None, history_since = None):
        """
        Create and return a new room state object and request joining
        to a MUC room.

        :Parameters:
            - `room`: the name of a room to be joined
            - `nick`: the nickname to be used in the room
            - `handler`: is an object to handle room events.
            - `password`: password for the room, if any
            - `history_maxchars`: limit of the total number of characters in
              history.
            - `history_maxstanzas`: limit of the total number of messages in
              history.
            - `history_seconds`: send only messages received in the last
              `history_seconds` seconds.
            - `history_since`: Send only the messages received since the
              dateTime specified (UTC).

        :Types:
            - `room`: `JID`
            - `nick`: `unicode`
            - `handler`: `MucRoomHandler`
            - `password`: `unicode`
            - `history_maxchars`: `int`
            - `history_maxstanzas`: `int`
            - `history_seconds`: `int`
            - `history_since`: `datetime.datetime`

        :return: the room state object created.
        :returntype: `MucRoomState`
        """

        if not room.node or room.resource:
            raise ValueError,"Invalid room JID"

        room_jid = JID(room.node, room.domain, nick)

        cur_rs = self.rooms.get(room_jid.bare().as_unicode())
        if cur_rs and cur_rs.joined:
            raise RuntimeError,"Room already joined"

        rs=MucRoomState(self, self.stream.me, room_jid, handler)
        self.rooms[room_jid.bare().as_unicode()]=rs
        rs.join(password, history_maxchars, history_maxstanzas,
            history_seconds, history_since)
        return rs
예제 #3
0
 def _sender_is_jid(sender, jid):
     cjc = Application.instance
     if not sender:
         return False
     if "@" in sender:
         try:
             sender_jid = JID(sender)
             if sender_jid.bare() == jid.bare():
                 return True
         except ValueError:
             pass
     if sender == cjc.get_user_info(jid, "nick"):
         return True
     if sender == cjc.get_user_info(jid, "rostername"):
         return True
     return sender == jid.node
예제 #4
0
 def _sender_is_jid(sender, jid):
     cjc = Application.instance
     if not sender:
         return False
     if "@" in sender:
         try:
             sender_jid = JID(sender)
             if sender_jid.bare() == jid.bare():
                 return True
         except ValueError:
             pass
     if sender == cjc.get_user_info(jid, "nick"):
         return True
     if sender == cjc.get_user_info(jid, "rostername"):
         return True
     return sender == jid.node