docs: remove yield from and fix some old changes
This commit is contained in:
parent
92c3f69829
commit
a50bffae89
2 changed files with 25 additions and 32 deletions
|
@ -172,14 +172,14 @@ the `XEP-0059 <http://xmpp.org/extensions/xep-0059.html>`_ plug-in.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
info = yield from self['xep_0030'].get_info(jid='foo@example.com',
|
info = await self['xep_0030'].get_info(jid='foo@example.com',
|
||||||
node='bar',
|
node='bar',
|
||||||
ifrom='baz@mycomponent.example.com',
|
ifrom='baz@mycomponent.example.com',
|
||||||
timeout=30)
|
timeout=30)
|
||||||
|
|
||||||
items = self['xep_0030'].get_info(jid='foo@example.com',
|
items = await self['xep_0030'].get_items(jid='foo@example.com',
|
||||||
node='bar',
|
node='bar',
|
||||||
iterator=True)
|
iterator=True)
|
||||||
|
|
||||||
For more examples on how to use basic disco queries, check the ``disco_browser.py``
|
For more examples on how to use basic disco queries, check the ``disco_browser.py``
|
||||||
example in the ``examples`` directory.
|
example in the ``examples`` directory.
|
||||||
|
@ -194,7 +194,7 @@ a full Iq stanza.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
info = self['xep_0030'].get_info(node='foo', local=True)
|
info = await self['xep_0030'].get_info(node='foo', local=True)
|
||||||
items = self['xep_0030'].get_items(jid='somejid@mycomponent.example.com',
|
items = await self['xep_0030'].get_items(jid='somejid@mycomponent.example.com',
|
||||||
node='bar',
|
node='bar',
|
||||||
local=True)
|
local=True)
|
||||||
|
|
|
@ -11,7 +11,7 @@ Block on IQ sending
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
result = yield from iq.send()
|
result = await iq.send()
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
|
@ -28,13 +28,7 @@ The same changes from the SleekXMPP API apply, so you can do:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
iq_info = yield from self.xmpp['xep_0030'].get_info(jid)
|
iq_info = await self.xmpp['xep_0030'].get_info(jid)
|
||||||
|
|
||||||
But the following will only return a Future:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
iq_info = self.xmpp['xep_0030'].get_info(jid)
|
|
||||||
|
|
||||||
|
|
||||||
Callbacks, Event Handlers, and Stream Handlers
|
Callbacks, Event Handlers, and Stream Handlers
|
||||||
|
@ -42,7 +36,7 @@ Callbacks, Event Handlers, and Stream Handlers
|
||||||
|
|
||||||
IQ callbacks and :term:`Event Handlers <event handler>` can be coroutine
|
IQ callbacks and :term:`Event Handlers <event handler>` can be coroutine
|
||||||
functions; in this case, they will be scheduled in the event loop using
|
functions; in this case, they will be scheduled in the event loop using
|
||||||
:meth:`.asyncio.async` and not ran immediately.
|
:meth:`.asyncio.ensure_future` and not ran immediately.
|
||||||
|
|
||||||
A :class:`.CoroutineCallback` class has been added as well for
|
A :class:`.CoroutineCallback` class has been added as well for
|
||||||
:term:`Stream Handlers <stream handler>`, which will use
|
:term:`Stream Handlers <stream handler>`, which will use
|
||||||
|
@ -94,18 +88,18 @@ a simple <message>.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
import asyncio, aiohttp, slixmpp
|
import aiohttp, slixmpp
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def get_pythonorg(event):
|
||||||
def get_pythonorg(event):
|
async with aiohttp.ClientSession() as session:
|
||||||
req = yield from aiohttp.request('get', 'http://www.python.org')
|
async with session.get('http://www.python.org') as resp:
|
||||||
text = yield from req.text
|
text = await req.text()
|
||||||
client.send_message(mto='jid2@example', mbody=text)
|
client.send_message(mto='jid2@example', mbody=text)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def get_asyncioorg(event):
|
||||||
def get_asyncioorg(event):
|
async with aiohttp.ClientSession() as session:
|
||||||
req = yield from aiohttp.request('get', 'http://www.asyncio.org')
|
async with session.get('http://www.asyncio.org') as resp:
|
||||||
text = yield from req.text
|
text = await req.text()
|
||||||
client.send_message(mto='jid3@example', mbody=text)
|
client.send_message(mto='jid3@example', mbody=text)
|
||||||
|
|
||||||
client = slixmpp.ClientXMPP('jid@example', 'password')
|
client = slixmpp.ClientXMPP('jid@example', 'password')
|
||||||
|
@ -132,11 +126,10 @@ JID indicating its findings.
|
||||||
self.register_plugin('xep_0092')
|
self.register_plugin('xep_0092')
|
||||||
self.add_event_handler('message', self.on_message)
|
self.add_event_handler('message', self.on_message)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def on_message(self, event):
|
||||||
def on_message(self, event):
|
|
||||||
# You should probably handle IqError and IqTimeout exceptions here
|
# You should probably handle IqError and IqTimeout exceptions here
|
||||||
# but this is an example.
|
# but this is an example.
|
||||||
version = yield from self['xep_0092'].get_version(message['from'])
|
version = await self['xep_0092'].get_version(message['from'])
|
||||||
text = "%s sent me a message, he runs %s" % (message['from'],
|
text = "%s sent me a message, he runs %s" % (message['from'],
|
||||||
version['software_version']['name'])
|
version['software_version']['name'])
|
||||||
self.send_message(mto='master@example.tld', mbody=text)
|
self.send_message(mto='master@example.tld', mbody=text)
|
||||||
|
|
Loading…
Reference in a new issue