Merge branch 'develop' into stream_features
This commit is contained in:
		| @@ -1,2 +1,10 @@ | ||||
| """ | ||||
|     SleekXMPP: The Sleek XMPP Library | ||||
|     Copyright (C) 2011 Nathanael C. Fritz, Dalek | ||||
|     This file is part of SleekXMPP. | ||||
|  | ||||
|     See the file LICENSE for copying permission. | ||||
| """ | ||||
|  | ||||
| from sleekxmpp.plugins.xep_0249.stanza import Invite | ||||
| from sleekxmpp.plugins.xep_0249.invite import xep_0249 | ||||
|   | ||||
| @@ -1,5 +1,10 @@ | ||||
| """Direct MUC Invitation.""" | ||||
| """ | ||||
|     SleekXMPP: The Sleek XMPP Library | ||||
|     Copyright (C) 2011 Nathanael C. Fritz, Dalek | ||||
|     This file is part of SleekXMPP. | ||||
|  | ||||
|     See the file LICENSE for copying permission. | ||||
| """ | ||||
|  | ||||
| import logging | ||||
|  | ||||
| @@ -11,6 +16,7 @@ from sleekxmpp.xmlstream.handler import Callback | ||||
| from sleekxmpp.xmlstream.matcher import StanzaPath | ||||
| from sleekxmpp.plugins.xep_0249 import Invite | ||||
|  | ||||
|  | ||||
| log = logging.getLogger(__name__) | ||||
|  | ||||
|  | ||||
| @@ -34,15 +40,14 @@ class xep_0249(base_plugin): | ||||
|  | ||||
|     def post_init(self): | ||||
|         base_plugin.post_init(self) | ||||
|         self.xmpp.plugin['xep_0030'].add_feature(Invite.namespace) | ||||
|         self.xmpp['xep_0030'].add_feature(Invite.namespace) | ||||
|  | ||||
|     def _handle_invite(self, message): | ||||
|     def _handle_invite(self, msg): | ||||
|         """ | ||||
|         Raise an event for all invitations received. | ||||
|  | ||||
|         """ | ||||
|         log.debug("Received direct muc invitation from %s to room %s", | ||||
|                   message['from'], message['groupchat_invite']['jid']) | ||||
|                   msg['from'], msg['groupchat_invite']['jid']) | ||||
|  | ||||
|         self.xmpp.event('groupchat_direct_invite', message) | ||||
|  | ||||
| @@ -52,24 +57,23 @@ class xep_0249(base_plugin): | ||||
|         Send a direct MUC invitation to an XMPP entity. | ||||
|  | ||||
|         Arguments: | ||||
|             jid         -- The jid of the entity to which the inviation | ||||
|                            is sent | ||||
|             jid      -- The JID of the entity that will receive | ||||
|                         the invitation | ||||
|             roomjid  -- the address of the groupchat room to be joined | ||||
|             password -- a password needed for entry into a | ||||
|                         password-protected room (OPTIONAL). | ||||
|             reason   -- a human-readable purpose for the invitation | ||||
|                         (OPTIONAL). | ||||
|  | ||||
|         """ | ||||
|  | ||||
|         message = self.xmpp.Message() | ||||
|         message['to'] = jid | ||||
|         msg = self.xmpp.Message() | ||||
|         msg['to'] = jid | ||||
|         if ifrom is not None: | ||||
|             message['from'] = ifrom | ||||
|         message['groupchat_invite']['jid'] = roomjid | ||||
|             msg['from'] = ifrom | ||||
|         msg['groupchat_invite']['jid'] = roomjid | ||||
|         if password is not None: | ||||
|             message['groupchat_invite']['password'] = password | ||||
|             msg['groupchat_invite']['password'] = password | ||||
|         if reason is not None: | ||||
|             message['groupchat_invite']['reason'] = reason | ||||
|             msg['groupchat_invite']['reason'] = reason | ||||
|  | ||||
|         return message.send() | ||||
|         return msg.send() | ||||
|   | ||||
| @@ -1,7 +1,16 @@ | ||||
| """ | ||||
|     SleekXMPP: The Sleek XMPP Library | ||||
|     Copyright (C) 2011 Nathanael C. Fritz, Dalek | ||||
|     This file is part of SleekXMPP. | ||||
|  | ||||
|     See the file LICENSE for copying permission. | ||||
| """ | ||||
|  | ||||
| from sleekxmpp.xmlstream import ElementBase | ||||
|  | ||||
|  | ||||
| class Invite(ElementBase): | ||||
|  | ||||
|     """ | ||||
|     XMPP allows for an agent in an MUC room to directly invite another | ||||
|     user to join the chat room (as opposed to a mediated invitation | ||||
| @@ -23,6 +32,7 @@ class Invite(ElementBase): | ||||
|         reason   -- The reason for the invitation (optional) | ||||
|  | ||||
|     """ | ||||
|  | ||||
|     name = "x" | ||||
|     namespace = "jabber:x:conference" | ||||
|     plugin_attrib = "groupchat_invite" | ||||
|   | ||||
							
								
								
									
										64
									
								
								tests/test_stream_xep_0249.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								tests/test_stream_xep_0249.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | ||||
| import sys | ||||
| import time | ||||
| import threading | ||||
|  | ||||
| from sleekxmpp.test import * | ||||
| from sleekxmpp.xmlstream import ElementBase | ||||
|  | ||||
|  | ||||
| class TestStreamDirectInvite(SleekTest): | ||||
|  | ||||
|     """ | ||||
|     Test using the XEP-0249 plugin. | ||||
|     """ | ||||
|  | ||||
|     def tearDown(self): | ||||
|         sys.excepthook = sys.__excepthook__ | ||||
|         self.stream_close() | ||||
|  | ||||
|     def testReceiveInvite(self): | ||||
|         self.stream_start(mode='client', | ||||
|                           plugins=['xep_0030', | ||||
|                                    'xep_0249']) | ||||
|  | ||||
|         events = [] | ||||
|  | ||||
|         def handle_invite(msg): | ||||
|             events.append(True) | ||||
|  | ||||
|         self.xmpp.add_event_handler('groupchat_direct_invite', | ||||
|                                     handle_invite) | ||||
|  | ||||
|         self.recv(""" | ||||
|           <message> | ||||
|             <x xmlns="jabber:x:conference" | ||||
|                jid="sleek@conference.jabber.org" | ||||
|                password="foo" | ||||
|                reason="For testing" /> | ||||
|           </message> | ||||
|         """) | ||||
|  | ||||
|         time.sleep(.5) | ||||
|  | ||||
|         self.failUnless(events == [True], | ||||
|                 "Event not raised: %s" % events) | ||||
|  | ||||
|     def testSentDirectInvite(self): | ||||
|         self.stream_start(mode='client', | ||||
|                           plugins=['xep_0030', | ||||
|                                    'xep_0249']) | ||||
|  | ||||
|         self.xmpp['xep_0249'].send_invitation('user@example.com', | ||||
|                                               'sleek@conference.jabber.org', | ||||
|                                               reason='Need to test Sleek') | ||||
|  | ||||
|         self.send(""" | ||||
|           <message to="user@example.com"> | ||||
|             <x xmlns="jabber:x:conference" | ||||
|                jid="sleek@conference.jabber.org" | ||||
|                reason="Need to test Sleek" /> | ||||
|           </message> | ||||
|         """) | ||||
|  | ||||
|  | ||||
| suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamDirectInvite) | ||||
							
								
								
									
										15
									
								
								todo1.0
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								todo1.0
									
									
									
									
									
								
							| @@ -10,8 +10,6 @@ Plugins: | ||||
|         PEP8 | ||||
|         Documentation | ||||
|         Stream/Unit tests | ||||
|     0030 | ||||
|         Done | ||||
|     0033 | ||||
|         PEP8 | ||||
|         Documentation | ||||
| @@ -22,8 +20,6 @@ Plugins: | ||||
|         Stream/Unit tests | ||||
|     0050 | ||||
|         Review replacement in github.com/legastero/adhoc | ||||
|     0059 | ||||
|         Done | ||||
|     0060 | ||||
|         PEP8 | ||||
|         Documentation | ||||
| @@ -41,21 +37,10 @@ Plugins: | ||||
|         PEP8 | ||||
|         Documentation | ||||
|         Consider any simplifications. | ||||
|     0092 | ||||
|         Done | ||||
|     0128 | ||||
|         Needs complete rewrite to work with new 0030 plugin. | ||||
|     0199 | ||||
|         PEP8 | ||||
|         Documentation | ||||
|         Stream/Unit tests | ||||
|         Needs to use scheduler instead of its own thread. | ||||
|     0202 | ||||
|         PEP8 | ||||
|         Documentation | ||||
|         Stream/Unit tests | ||||
|     0249 | ||||
|         Review, minor cleanup | ||||
|     gmail_notify | ||||
|         PEP8 | ||||
|         Documentation | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Lance Stout
					Lance Stout