def disable_avatar(self): """ Temporarily disable the avatar. If :attr:`synchronize_vcard` is true, the vCard avatar is disabled (even if disabling the PEP avatar fails). This is done by setting the avatar metadata node empty and if :attr:`synchronize_vcard` is true, downloading the vCard, removing the avatar data and re-uploading the vCard. This method does not error if neither protocol is active. :raises aioxmpp.errors.GatherError: if an exception is raised by the spawned tasks. """ with (yield from self._publish_lock): todo = [] if self._synchronize_vcard: todo.append(self._disable_vcard_avatar()) if (yield from self._pep.available()): todo.append(self._pep.publish( namespaces.xep0084_metadata, avatar_xso.Metadata() )) yield from gather_reraise_multi(*todo, message="disable_avatar")
def disable_avatar(self): """ Temporarily disable the avatar. If :attr:`synchronize_vcard` is true, the vCard avatar is disabled (even if disabling the PEP avatar fails). This is done by setting the avatar metadata node empty and if :attr:`synchronize_vcard` is true, downloading the vCard, removing the avatar data and re-uploading the vCard. This method does not error if neither protocol is active. :raises aioxmpp.errors.GatherError: if an exception is raised by the spawned tasks. """ with (yield from self._publish_lock): todo = [] if self._synchronize_vcard: todo.append(self._disable_vcard_avatar()) if (yield from self._pep.available()): todo.append( self._pep.publish(namespaces.xep0084_metadata, avatar_xso.Metadata())) yield from gather_reraise_multi(*todo, message="disable_avatar")
def test_with_one_successful_task(self): @asyncio.coroutine def foo(): return True self.assertEqual(run_coroutine(utils.gather_reraise_multi(foo())), [True])
def wipe_avatar(self): """ Remove all avatar data stored on the server. If :attr:`synchronize_vcard` is true, the vCard avatar is disabled even if disabling the PEP avatar fails. This is equivalent to :meth:`disable_avatar` for vCard-based avatars, but will also remove the data PubSub node for PEP avatars. This method does not error if neither protocol is active. :raises aioxmpp.errors.GatherError: if an exception is raised by the spawned tasks. """ @asyncio.coroutine def _wipe_pep_avatar(): yield from self._pep.publish(namespaces.xep0084_metadata, avatar_xso.Metadata()) yield from self._pep.publish(namespaces.xep0084_data, avatar_xso.Data(b'')) with (yield from self._publish_lock): todo = [] if self._synchronize_vcard: todo.append(self._disable_vcard_avatar()) if (yield from self._pep.available()): todo.append(_wipe_pep_avatar()) yield from gather_reraise_multi(*todo, message="wipe_avatar")
def test_with_one_failing_task(self): @asyncio.coroutine def foo(): raise RuntimeError try: run_coroutine(utils.gather_reraise_multi(foo())) except errors.GatherError as e: self.assertIs(type(e.exceptions[0]), RuntimeError)
def test_with_one_successful_task(self): @asyncio.coroutine def foo(): return True self.assertEqual( run_coroutine(utils.gather_reraise_multi(foo())), [True] )
def test_with_two_successful_tasks(self): async def foo(): return True async def bar(): return False self.assertEqual( run_coroutine(utils.gather_reraise_multi(foo(), bar())), [True, False] )
def test_with_two_successful_tasks(self): @asyncio.coroutine def foo(): return True @asyncio.coroutine def bar(): return False self.assertEqual( run_coroutine(utils.gather_reraise_multi(foo(), bar())), [True, False] )
def test_with_two_tasks_one_failing(self): async def foo(): raise RuntimeError async def bar(): return False try: run_coroutine(utils.gather_reraise_multi(foo(), bar())) except errors.GatherError as e: self.assertIs(type(e.exceptions[0]), RuntimeError) else: self.fail()
def test_with_two_tasks_both_failing(self): @asyncio.coroutine def foo(): raise RuntimeError @asyncio.coroutine def bar(): raise Exception try: run_coroutine(utils.gather_reraise_multi(foo(), bar())) except errors.GatherError as e: self.assertIs(type(e.exceptions[0]), RuntimeError) self.assertIs(type(e.exceptions[1]), Exception)
def wipe_avatar(self): """ Remove all avatar data stored on the server. If :attr:`synchronize_vcard` is true, the vCard avatar is disabled even if disabling the PEP avatar fails. This is equivalent to :meth:`disable_avatar` for vCard-based avatars, but will also remove the data PubSub node for PEP avatars. This method does not error if neither protocol is active. :raises aioxmpp.errors.GatherError: if an exception is raised by the spawned tasks. """ @asyncio.coroutine def _wipe_pep_avatar(): yield from self._pep.publish( namespaces.xep0084_metadata, avatar_xso.Metadata() ) yield from self._pep.publish( namespaces.xep0084_data, avatar_xso.Data(b'') ) with (yield from self._publish_lock): todo = [] if self._synchronize_vcard: todo.append(self._disable_vcard_avatar()) if (yield from self._pep.available()): todo.append(_wipe_pep_avatar()) yield from gather_reraise_multi(*todo, message="wipe_avatar")
def test_with_empty_list(self): self.assertEqual(run_coroutine(utils.gather_reraise_multi()), [])
def test_with_empty_list(self): self.assertEqual( run_coroutine(utils.gather_reraise_multi()), [] )