XEP-0047: In-band Bytestreams#

class slixmpp.plugins.xep_0047.XEP_0047(xmpp, config=None)[source]#

XEP-0047: In-Band Bytestreams

Events registered by this plugin:

Plugin Parameters:

async open_stream(jid, *, block_size=None, sid=None, use_messages=False, ifrom=None, **iqkwargs)[source]#

Open an IBB stream with a peer JID.

Changed in version 1.8.0: This function is now a coroutine and must be awaited. All parameters except jid are keyword-args only.

Parameters
  • jid (JID) – The remote JID to initiate the stream with.

  • block_size (Optional[int]) – The block size to advertise.

  • sid (Optional[str]) – The IBB stream id (if not provided, will be auto-generated).

  • use_messages (bool) – If the stream should use message stanzas instead of iqs.

Return type

IBBytestream

Returns

The opened byte stream with the remote JID

Raises

.IqError – When the remote entity denied the stream.

class slixmpp.plugins.xep_0047.IBBytestream(xmpp, sid, block_size, jid, peer, use_messages=False)[source]#

XEP-0047 Stream abstraction. Created by the ibb plugin automatically.

Provides send methods and triggers ibb_stream_data events.

close(timeout=None)[source]#

Close the stream.

Return type

Future

async gather(max_data=None, timeout=3600)[source]#

Gather all data sent on a stream until it is closed, and return it.

New in version 1.8.0.

Parameters
  • max_data (Optional[int]) – Max number of bytes to receive. (received data may be over this limit depending on block_size)

  • timeout (int) – Timeout after which an error will be raised.

Raises

.IqTimeout – If the timeout is reached.

Return type

bytes

Returns

All bytes accumulated in the stream.

async send(data, timeout=None)[source]#

Send a single block of data.

Parameters

data (bytes) – Data to send (will be truncated if above block size).

Return type

int

Returns

Number of bytes sent.

async sendall(data, timeout=None)[source]#

Send all the contents of data in chunks.

Parameters

data (bytes) – Raw data to send.

async sendfile(file, timeout=None)[source]#

Send the contents of a file over the wire, in chunks.

Parameters

file (IO[bytes]) – The opened file (or file-like) object, in bytes mode.

Internal API methods#

The API here is used to manage streams and authorize. The default handlers work with the config parameters.

authorized_sid (0047 version)#
  • jid: JID receiving the stream initiation.

  • node: stream id

  • ifrom: who the stream is from.

  • args: Iq of the stream request.

  • returns: True if the stream should be accepted, False otherwise.

Check if the stream should be accepted. Uses the information setup by preauthorize_sid (0047 version) by default.

authorized (0047 version)#
  • jid: JID receiving the stream initiation.

  • node: stream id

  • ifrom: who the stream is from.

  • args: Iq of the stream request.

  • returns: True if the stream should be accepted, False otherwise.

A fallback handler (run after authorized_sid (0047 version)) to check if a stream should be accepted. Uses the auto_accept parameter by default.

preauthorize_sid (0047 version)#
  • jid: JID receiving the stream initiation.

  • node: stream id

  • ifrom: who the stream will be from.

  • args: Unused.

Register a stream id to be accepted automatically (called from other plugins such as XEP-0095).

get_stream#
  • jid: JID of local receiver.

  • node: stream id

  • ifrom: who the stream is from.

  • args: unused

  • returns: IBBytestream

Return a currently opened stream between two JIDs.

set_stream#
  • jid: JID of local receiver.

  • node: stream id

  • ifrom: who the stream is from.

  • args: unused

Register an opened stream between two JIDs.

del_stream#
  • jid: JID of local receiver.

  • node: stream id

  • ifrom: who the stream is from.

  • args: unused

Delete a stream between two JIDs.

Stanza elements#

class slixmpp.plugins.xep_0047.stanza.Close(xml=None, parent=None)[source]#
interfaces: ClassVar[Set[str]] = {'sid'}#

The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the plugin_attrib value of any registered stanza plugins.

iterables: List[ElementBase]#

A list of child stanzas whose class is included in plugin_iterables.

loaded_plugins: Set[str]#
name: ClassVar[str] = 'close'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'http://jabber.org/protocol/ibb'#

The XML namespace for the element. Given <foo xmlns="bar" />, then namespace = "bar" should be used. The default namespace is jabber:client since this is being used in an XMPP library.

parent: Optional[ReferenceType[ElementBase]]#

A weakref.weakref to the parent stanza, if there is one. If not, then parent is None.

plugin_attrib: ClassVar[str] = 'ibb_close'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
plugins: Dict[Tuple[str, Optional[str]], ElementBase]#

An ordered dictionary of plugin stanzas, mapped by their plugin_attrib value.

tag: str#

The name of the tag for the stanza’s root element. It is the same as calling tag_name() and is formatted as '{namespace}elementname'.

xml: ET.Element#

The underlying XML object for the stanza. It is a standard xml.etree.ElementTree object.

class slixmpp.plugins.xep_0047.stanza.Data(xml=None, parent=None)[source]#
del_data()[source]#
get_data()[source]#
get_seq()[source]#
interfaces: ClassVar[Set[str]] = {'data', 'seq', 'sid'}#

The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the plugin_attrib value of any registered stanza plugins.

iterables: List[ElementBase]#

A list of child stanzas whose class is included in plugin_iterables.

loaded_plugins: Set[str]#
name: ClassVar[str] = 'data'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'http://jabber.org/protocol/ibb'#

The XML namespace for the element. Given <foo xmlns="bar" />, then namespace = "bar" should be used. The default namespace is jabber:client since this is being used in an XMPP library.

parent: Optional[ReferenceType[ElementBase]]#

A weakref.weakref to the parent stanza, if there is one. If not, then parent is None.

plugin_attrib: ClassVar[str] = 'ibb_data'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
plugins: Dict[Tuple[str, Optional[str]], ElementBase]#

An ordered dictionary of plugin stanzas, mapped by their plugin_attrib value.

set_data(value)[source]#
set_seq(value)[source]#
sub_interfaces: ClassVar[Set[str]] = {'data'}#

A subset of interfaces which maps interfaces to direct subelements of the underlying XML object. Using this set, the text of these subelements may be set, retrieved, or removed without needing to define custom methods.

tag: str#

The name of the tag for the stanza’s root element. It is the same as calling tag_name() and is formatted as '{namespace}elementname'.

xml: ET.Element#

The underlying XML object for the stanza. It is a standard xml.etree.ElementTree object.

class slixmpp.plugins.xep_0047.stanza.Open(xml=None, parent=None)[source]#
del_block_size()[source]#
get_block_size()[source]#
interfaces: ClassVar[Set[str]] = {'block_size', 'sid', 'stanza'}#

The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the plugin_attrib value of any registered stanza plugins.

iterables: List[ElementBase]#

A list of child stanzas whose class is included in plugin_iterables.

loaded_plugins: Set[str]#
name: ClassVar[str] = 'open'#

The XML tag name of the element, not including any namespace prefixes. For example, an ElementBase object for <message /> would use name = 'message'.

namespace: str = 'http://jabber.org/protocol/ibb'#

The XML namespace for the element. Given <foo xmlns="bar" />, then namespace = "bar" should be used. The default namespace is jabber:client since this is being used in an XMPP library.

parent: Optional[ReferenceType[ElementBase]]#

A weakref.weakref to the parent stanza, if there is one. If not, then parent is None.

plugin_attrib: ClassVar[str] = 'ibb_open'#

For ElementBase subclasses which are intended to be used as plugins, the plugin_attrib value defines the plugin name. Plugins may be accessed by using the plugin_attrib value as the interface. An example using plugin_attrib = 'foo':

register_stanza_plugin(Message, FooPlugin)
msg = Message()
msg['foo']['an_interface_from_the_foo_plugin']
plugins: Dict[Tuple[str, Optional[str]], ElementBase]#

An ordered dictionary of plugin stanzas, mapped by their plugin_attrib value.

set_block_size(value)[source]#
tag: str#

The name of the tag for the stanza’s root element. It is the same as calling tag_name() and is formatted as '{namespace}elementname'.

xml: ET.Element#

The underlying XML object for the stanza. It is a standard xml.etree.ElementTree object.

slixmpp.plugins.xep_0047.stanza.from_b64(data)[source]#
slixmpp.plugins.xep_0047.stanza.to_b64(data)[source]#