Skip to content
Back to top
View this page

# XEP-0047: In-band Bytestreams

class slixmpp.plugins.xep_0047.XEP_0047(xmpp, config=None)

  XEP-0047: In-Band Bytestreams

  Events registered by this plugin:

  - ibb_stream_start

  - ibb_stream_end

  - ibb_stream_data

  - stream:[stream id]:[peer jid]

  Plugin Parameters:

  - `block_size` (default: `4096`): default block size to negotiate

  - `max_block_size` (default: `8192`): max block size to accept

  - `auto_accept` (default: `False`): if incoming streams should be

      accepted automatically.

  - authorized (0047 version)

  - authorized_sid (0047 version)

  - preauthorize_sid (0047 version)

  - get_stream

  - set_stream

  - del_stream

  default_config: ClassVar[dict[str, Any]] = {'auto_accept': False, 'block_size': 4096, 'max_block_size': 8192}

    The basic, standard configuration for the plugin, which may be overridden when initializing the plugin. The configuration fields included here may be accessed directly as attributes of the plugin. For example, including the configuration field ‘foo’ would mean accessing plugin.foo returns the current value of plugin.config[‘foo’].

  dependencies: ClassVar[set[str]] = {'xep_0030'}

    Some plugins may depend on others in order to function properly. Any plugin names included in `dependencies` will be initialized as needed if this plugin is enabled.

  description: str = 'XEP-0047: In-Band Bytestreams'

    A longer name for the plugin, describing its purpose. For example, a plugin for XEP-0030 would use ‘Service Discovery’ as its description value.

  name: str = 'xep_0047'

    A short name for the plugin based on the implemented specification. For example, a plugin for XEP-0030 would use ‘xep_0030’.

  async open_stream(jid, *, block_size=None, sid=None, use_messages=False, ifrom=None, **iqkwargs)

    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 (`int` | `None`) – The block size to advertise.

      - sid (`str` | `None`) – 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)

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

  Provides send methods and triggers ibb_stream_data events.

  close(timeout=None)

    Close the stream.

    Return type:

      `Future`

  async gather(max_data=None, timeout=3600)

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

    Added in version 1.8.0.

    Parameters:

      - max_data (`int` | `None`) – 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)

    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)

    Send all the contents of `data` in chunks.

    Parameters:

      data (`bytes`) – Raw data to send.

  async sendfile(file, timeout=None)

    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)
  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.

  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.

  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']

class slixmpp.plugins.xep_0047.stanza.Data(xml=None, parent=None)
  del_data()
  get_data()
  get_seq()
  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.

  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.

  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']

  set_data(value)
  set_seq(value)
  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.

class slixmpp.plugins.xep_0047.stanza.Open(xml=None, parent=None)
  del_block_size()
  get_block_size()
  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.

  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.

  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']

  set_block_size(value)

slixmpp.plugins.xep_0047.stanza.from_b64(data)

slixmpp.plugins.xep_0047.stanza.to_b64(data)