Changeset 121:e74ad91e5c6f
- Timestamp:
- Oct 20, 2008, 10:28:22 PM (14 years ago)
- Branch:
- wokkel-muc-client-support-24
- Convert:
- svn:b33ecbfc-034c-dc11-8662-000475d9059e/branches/wokkel-muc-client-support-24@117
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/muc.py
r120 r121 117 117 mucCondition = 'forbidden' 118 118 119 class Conflict(Exception): 120 """ 121 """ 122 condition = 'cancel' 123 mucCondition = 'conflict' 124 125 class NotFound(Exception): 126 """ 127 """ 128 condition = 'cancel' 129 mucCondition = 'not-found' 130 131 class ServiceUnavailable(Exception): 132 """ 133 """ 134 condition = 'wait' 135 mucCondition = 'service-unavailable' 136 137 119 138 120 139 MUC_EXCEPTIONS = { … … 123 142 'not-authorized': NotAuthorized, 124 143 'exception': Exception, 144 'conflict': Conflict, 145 'service-unavailable': ServiceUnavailable, 146 'not-found': NotFound, 125 147 } 126 148 … … 316 338 d['from'] = h_frm 317 339 340 class HistoryOptions(object): 341 """A history configuration object. 342 343 @ivar maxchars: Limit the total number of characters in the history to "X" 344 (where the character count is the characters of the complete XML stanzas, not only their XML character data). 345 @itype maxchars: L{int} 346 347 @ivar maxstanzas: Limit the total number of messages in the history to "X". 348 @itype mazstanzas: L{int} 349 350 @ivar seconds: Send only the messages received in the last "X" seconds. 351 @itype seconds: L{int} 352 353 @ivar since: Send only the messages received since the datetime specified (which MUST conform to the DateTime profile specified in XMPP Date and Time Profiles [14]). 354 @itype since: L{datetime.datetime} 355 356 """ 357 attributes = ['maxchars', 'maxstanzas', 'seconds', 'since'] 358 359 def __init__(self, maxchars=None, maxstanzas=None, seconds=None, since=None): 360 self.maxchars = maxchars 361 self.maxstanzas = maxstanzas 362 self.seconds = seconds 363 self.since = since 364 365 def toElement(self): 366 h = domish.Element((None, 'history')) 367 for key in self.attributes: 368 a = getattr(self, key, a) 369 if a is not None: 370 h[key] = str(a) 371 372 return h 373 318 374 class User(object): 319 375 """ … … 516 572 self._userLeavesRoom(room_jid) 517 573 518 def _getExceptionFrom Presence(self, prs):574 def _getExceptionFromElement(self, stanza): 519 575 muc_condition = 'exception' 520 576 521 error = getattr( prs, 'error', None)577 error = getattr(stanza, 'error', None) 522 578 if error is not None: 523 579 for e in error.elements(): … … 629 685 # check for errors 630 686 if prs.hasAttribute('type') and prs['type'] == 'error': 631 d.errback(self._getExceptionFrom Presence(prs))687 d.errback(self._getExceptionFromElement(prs)) 632 688 else: 633 689 # change the state of the room 634 690 r = self._getRoom(room_jid) 635 691 if r is None: 636 raise Exception, 'Room Not Found'692 raise NotFound 637 693 r.state = 'joined' 638 694 … … 652 708 # check for errors 653 709 if prs.hasAttribute('type') and prs['type'] == 'error': 654 d.errback( prs)710 d.errback(self._getExceptionFromElement(prs)) 655 711 else: 656 712 # change the state of the room 657 713 r = self._getRoom(room_jid) 658 714 if r is None: 659 raise Exception, 'Room Not Found'715 raise NotFound 660 716 self._removeRoom(room_jid) 661 717 … … 764 820 765 821 766 def join(self, server, room, nick ):822 def join(self, server, room, nick, history = None): 767 823 """ Join a MUC room by sending presence to it. Returns a defered that is called when 768 824 the entity is in the room or an error has occurred. … … 777 833 @type nick: L{unicode} 778 834 835 @param history: The maximum number of history stanzas you would like. 836 779 837 """ 780 838 r = Room(room, server, nick, state='joining') … … 782 840 783 841 p = BasicPresence(to=r.entity_id) 842 if history is not None: 843 p.x.addChild(history.toElement()) 844 784 845 d = self.sendDeferred(p, timeout=DEFER_TIMEOUT) 785 846 … … 815 876 r = self._getRoom(room_jid) 816 877 if r is None: 817 raise Exception, 'Room not found'878 raise NotFound 818 879 r.nick = new_nick # change the nick 819 880 # create presence … … 862 923 r = self._getRoom(room_jid) 863 924 if r is None: 864 raise Exception, 'Room not found'925 raise NotFound 865 926 866 927 p = BasicPresence(to=r.entityId())
Note: See TracChangeset
for help on using the changeset viewer.