Changeset 173:6b0eb01b5744 for wokkel/xmppim.py
- Timestamp:
- May 9, 2012, 2:24:28 PM (10 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/xmppim.py
r172 r173 749 749 @ivar item: Roster item to be set or pushed. 750 750 @type item: L{RosterItem}. 751 752 @ivar version: Roster version identifier for roster pushes and 753 retrieving the roster as a delta from a known cached version. This 754 should only be set if the recipient is known to support roster 755 versioning. 756 @type version: C{unicode} 751 757 """ 752 758 item = None 759 version = None 753 760 754 761 def parseRequest(self, element): 762 self.version = element.getAttribute('ver') 763 755 764 for child in element.elements(NS_ROSTER, 'item'): 756 765 self.item = RosterItem.fromElement(child) … … 761 770 element = Request.toElement(self) 762 771 query = element.addElement((NS_ROSTER, 'query')) 772 if self.version is not None: 773 query['ver'] = self.version 763 774 if self.item: 764 775 query.addChild(self.item.toElement()) … … 775 786 result in a C{'service-unavailable'} error being sent in return. 776 787 """ 788 789 790 791 class Roster(dict): 792 """ 793 In-memory roster container. 794 795 This provides a roster as a mapping from L{JID} to L{RosterItem}. If 796 roster versioning is used, the C{version} attribute holds the version 797 identifier for this version of the roster. 798 799 @ivar version: Roster version identifier. 800 @type version: C{unicode}. 801 """ 802 803 version = None 777 804 778 805 … … 797 824 pushes from untrusted senders. 798 825 826 If roster versioning is supported by the server, the roster and 827 subsequent pushes are annotated with a version identifier. This can be 828 used to cache the roster on the client side. Upon reconnect, the client 829 can request the roster with the version identifier of the cached version. 830 The server may then choose to only send roster pushes for the changes 831 since that version, instead of a complete roster. 832 799 833 @cvar allowAnySender: Flag to allow roster pushes from any sender. 800 834 C{False} by default. … … 810 844 811 845 812 def getRoster(self ):846 def getRoster(self, version=None): 813 847 """ 814 848 Retrieve contact list. 849 850 The returned deferred fires with the result of the roster request as 851 L{Roster}, a mapping from contact JID to L{RosterItem}. 852 853 If roster versioning is supported, the recipient responds with either 854 a the complete roster or with an empty result. In case of complete 855 roster, the L{Roster} is annotated with a C{version} attribute that 856 holds the version identifier for this version of the roster. This 857 identifier should be used for caching. 858 859 If the recipient responds with an empty result, the returned deferred 860 fires with C{None}. This indicates that any roster modifications 861 since C{version} will be sent as roster pushes. 862 863 Note that the empty result (C{None}) is different from an empty 864 roster (L{Roster} with no items). 865 866 @param version: Optional version identifier of the last cashed 867 version of the roster. This shall only be set if the recipient is 868 known to support roster versioning. If there is no (valid) cached 869 version of the roster, but roster versioning is desired, 870 C{version} should be set to the empty string (C{u''}). 871 @type version: C{unicode} 815 872 816 873 @return: Roster as a mapping from L{JID} to L{RosterItem}. … … 819 876 820 877 def processRoster(result): 821 roster = {} 822 for element in domish.generateElementsQNamed(result.query.children, 823 'item', NS_ROSTER): 824 item = RosterItem.fromElement(element) 825 roster[item.entity] = item 826 827 return roster 878 if result.query is not None: 879 roster = Roster() 880 roster.version = result.query.getAttribute('ver') 881 for element in result.query.elements(NS_ROSTER, 'item'): 882 item = RosterItem.fromElement(element) 883 roster[item.entity] = item 884 return roster 885 else: 886 return None 828 887 829 888 request = RosterRequest(stanzaType='get') 889 request.version = version 830 890 d = self.request(request) 831 891 d.addCallback(processRoster)
Note: See TracChangeset
for help on using the changeset viewer.