BaseXMPP

1.0 Documentation

«  ComponentXMPP   ::   Contents   ::   Exceptions  »

BaseXMPP

class sleekxmpp.basexmpp.BaseXMPP(jid=u'', default_ns=u'jabber:client')[source]

The BaseXMPP class adapts the generic XMLStream class for use with XMPP. It also provides a plugin mechanism to easily extend and add support for new XMPP features.

Parameters:default_ns – Ensure that the correct default XML namespace is used during initialization.
Iq(*args, **kwargs)[source]

Create an Iq stanza associated with this stream.

Message(*args, **kwargs)[source]

Create a Message stanza associated with this stream.

Presence(*args, **kwargs)[source]

Create a Presence stanza associated with this stream.

auto_authorize[source]

Auto accept or deny subscription requests.

If True, auto accept subscription requests. If False, auto deny subscription requests. If None, don’t automatically respond.

auto_subscribe[source]

Auto send requests for mutual subscriptions.

If True, auto send mutual subscription requests.

exception(exception)[source]

Process any uncaught exceptions, notably IqError and IqTimeout exceptions.

Parameters:exception – An unhandled Exception object.
fulljid[source]

Attribute accessor for full jid

get(key, default)[source]

Return a plugin given its name, if it has been registered.

jid[source]

Attribute accessor for bare jid

makeIq(id=0, ifrom=None, ito=None, itype=None, iquery=None)

Create a new Iq stanza with a given Id and from JID.

Parameters:
  • id – An ideally unique ID value for this stanza thread. Defaults to 0.
  • ifrom – The from JID to use for this stanza.
  • ito – The destination JID for this stanza.
  • itype – The Iq‘s type, one of: 'get', 'set', 'result', or 'error'.
  • iquery – Optional namespace for adding a query element.
makeIqError(id, type=u'cancel', condition=u'feature-not-implemented', text=None, ito=None, ifrom=None, iq=None)

Create an Iq stanza of type 'error'.

Parameters:
  • id – An ideally unique ID value. May use new_id().
  • type – The type of the error, such as 'cancel' or 'modify'. Defaults to 'cancel'.
  • condition – The error condition. Defaults to 'feature-not-implemented'.
  • text – A message describing the cause of the error.
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
  • iq – Optionally use an existing stanza instead of generating a new one.
makeIqGet(queryxmlns=None, ito=None, ifrom=None, iq=None)

Create an Iq stanza of type 'get'.

Optionally, a query element may be added.

Parameters:
  • queryxmlns – The namespace of the query to use.
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
  • iq – Optionally use an existing stanza instead of generating a new one.
makeIqQuery(iq=None, xmlns=u'', ito=None, ifrom=None)

Create or modify an Iq stanza to use the given query namespace.

Parameters:
  • iq – Optionally use an existing stanza instead of generating a new one.
  • xmlns – The query’s namespace.
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
makeIqResult(id=None, ito=None, ifrom=None, iq=None)

Create an Iq stanza of type 'result' with the given ID value.

Parameters:
  • id – An ideally unique ID value. May use new_id().
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
  • iq – Optionally use an existing stanza instead of generating a new one.
makeIqSet(sub=None, ito=None, ifrom=None, iq=None)

Create an Iq stanza of type 'set'.

Optionally, a substanza may be given to use as the stanza’s payload.

Parameters:
  • sub – Either an ElementBase stanza object or an Element XML object to use as the Iq‘s payload.
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
  • iq – Optionally use an existing stanza instead of generating a new one.
makeMessage(mto, mbody=None, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None)

Create and initialize a new Message stanza.

Parameters:
  • mto – The recipient of the message.
  • mbody – The main contents of the message.
  • msubject – Optional subject for the message.
  • mtype – The message’s type, such as 'chat' or 'groupchat'.
  • mhtml – Optional HTML body content in the form of a string.
  • mfrom – The sender of the message. if sending from a client, be aware that some servers require that the full JID of the sender be used.
  • mnick – Optional nickname of the sender.
makePresence(pshow=None, pstatus=None, ppriority=None, pto=None, ptype=None, pfrom=None, pnick=None)

Create and initialize a new Presence stanza.

Parameters:
  • pshow – The presence’s show value.
  • pstatus – The presence’s status message.
  • ppriority – This connection’s priority.
  • pto – The recipient of a directed presence.
  • ptype – The type of presence, such as 'subscribe'.
  • pfrom – The sender of the presence.
  • pnick – Optional nickname of the presence’s sender.
makeQueryRoster(iq=None)

Create a roster query element.

Parameters:iq – Optionally use an existing stanza instead of generating a new one.
make_iq(id=0, ifrom=None, ito=None, itype=None, iquery=None)[source]

Create a new Iq stanza with a given Id and from JID.

Parameters:
  • id – An ideally unique ID value for this stanza thread. Defaults to 0.
  • ifrom – The from JID to use for this stanza.
  • ito – The destination JID for this stanza.
  • itype – The Iq‘s type, one of: 'get', 'set', 'result', or 'error'.
  • iquery – Optional namespace for adding a query element.
make_iq_error(id, type=u'cancel', condition=u'feature-not-implemented', text=None, ito=None, ifrom=None, iq=None)[source]

Create an Iq stanza of type 'error'.

Parameters:
  • id – An ideally unique ID value. May use new_id().
  • type – The type of the error, such as 'cancel' or 'modify'. Defaults to 'cancel'.
  • condition – The error condition. Defaults to 'feature-not-implemented'.
  • text – A message describing the cause of the error.
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
  • iq – Optionally use an existing stanza instead of generating a new one.
make_iq_get(queryxmlns=None, ito=None, ifrom=None, iq=None)[source]

Create an Iq stanza of type 'get'.

Optionally, a query element may be added.

Parameters:
  • queryxmlns – The namespace of the query to use.
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
  • iq – Optionally use an existing stanza instead of generating a new one.
make_iq_query(iq=None, xmlns=u'', ito=None, ifrom=None)[source]

Create or modify an Iq stanza to use the given query namespace.

Parameters:
  • iq – Optionally use an existing stanza instead of generating a new one.
  • xmlns – The query’s namespace.
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
make_iq_result(id=None, ito=None, ifrom=None, iq=None)[source]

Create an Iq stanza of type 'result' with the given ID value.

Parameters:
  • id – An ideally unique ID value. May use new_id().
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
  • iq – Optionally use an existing stanza instead of generating a new one.
make_iq_set(sub=None, ito=None, ifrom=None, iq=None)[source]

Create an Iq stanza of type 'set'.

Optionally, a substanza may be given to use as the stanza’s payload.

Parameters:
  • sub – Either an ElementBase stanza object or an Element XML object to use as the Iq‘s payload.
  • ito – The destination JID for this stanza.
  • ifrom – The 'from' JID to use for this stanza.
  • iq – Optionally use an existing stanza instead of generating a new one.
make_message(mto, mbody=None, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None)[source]

Create and initialize a new Message stanza.

Parameters:
  • mto – The recipient of the message.
  • mbody – The main contents of the message.
  • msubject – Optional subject for the message.
  • mtype – The message’s type, such as 'chat' or 'groupchat'.
  • mhtml – Optional HTML body content in the form of a string.
  • mfrom – The sender of the message. if sending from a client, be aware that some servers require that the full JID of the sender be used.
  • mnick – Optional nickname of the sender.
make_presence(pshow=None, pstatus=None, ppriority=None, pto=None, ptype=None, pfrom=None, pnick=None)[source]

Create and initialize a new Presence stanza.

Parameters:
  • pshow – The presence’s show value.
  • pstatus – The presence’s status message.
  • ppriority – This connection’s priority.
  • pto – The recipient of a directed presence.
  • ptype – The type of presence, such as 'subscribe'.
  • pfrom – The sender of the presence.
  • pnick – Optional nickname of the presence’s sender.
make_query_roster(iq=None)[source]

Create a roster query element.

Parameters:iq – Optionally use an existing stanza instead of generating a new one.
process(*args, **kwargs)[source]

Initialize plugins and begin processing the XML stream.

The number of threads used for processing stream events is determined by HANDLER_THREADS.

Parameters:
  • block (bool) – If False, then event dispatcher will run in a separate thread, allowing for the stream to be used in the background for another application. Otherwise, process(block=True) blocks the current thread. Defaults to False.
  • threaded (bool) – DEPRECATED If True, then event dispatcher will run in a separate thread, allowing for the stream to be used in the background for another application. Defaults to True. This does not mean that no threads are used at all if threaded=False.

Regardless of these threading options, these threads will always exist:

  • The event queue processor
  • The send queue processor
  • The scheduler
registerPlugin(plugin, pconfig={}, module=None)

Register and configure a plugin for use in this stream.

Parameters:
  • plugin – The name of the plugin class. Plugin names must be unique.
  • pconfig – A dictionary of configuration data for the plugin. Defaults to an empty dictionary.
  • module – Optional refence to the module containing the plugin class if using custom plugins.
register_plugin(plugin, pconfig={}, module=None)[source]

Register and configure a plugin for use in this stream.

Parameters:
  • plugin – The name of the plugin class. Plugin names must be unique.
  • pconfig – A dictionary of configuration data for the plugin. Defaults to an empty dictionary.
  • module – Optional refence to the module containing the plugin class if using custom plugins.
register_plugins()[source]

Register and initialize all built-in plugins.

Optionally, the list of plugins loaded may be limited to those contained in plugin_whitelist.

Plugin configurations stored in plugin_config will be used.

resource[source]

Attribute accessor for jid resource

sendMessage(mto, mbody, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None)

Create, initialize, and send a new Message stanza.

Parameters:
  • mto – The recipient of the message.
  • mbody – The main contents of the message.
  • msubject – Optional subject for the message.
  • mtype – The message’s type, such as 'chat' or 'groupchat'.
  • mhtml – Optional HTML body content in the form of a string.
  • mfrom – The sender of the message. if sending from a client, be aware that some servers require that the full JID of the sender be used.
  • mnick – Optional nickname of the sender.
sendPresence(pshow=None, pstatus=None, ppriority=None, pto=None, pfrom=None, ptype=None, pnick=None)

Create, initialize, and send a new Presence stanza.

Parameters:
  • pshow – The presence’s show value.
  • pstatus – The presence’s status message.
  • ppriority – This connection’s priority.
  • pto – The recipient of a directed presence.
  • ptype – The type of presence, such as 'subscribe'.
  • pfrom – The sender of the presence.
  • pnick – Optional nickname of the presence’s sender.
sendPresenceSubscription(pto, pfrom=None, ptype=u'subscribe', pnick=None)

Create, initialize, and send a new Presence stanza of type 'subscribe'.

Parameters:
  • pto – The recipient of a directed presence.
  • pfrom – The sender of the presence.
  • ptype – The type of presence, such as 'subscribe'.
  • pnick – Optional nickname of the presence’s sender.
send_message(mto, mbody, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None)[source]

Create, initialize, and send a new Message stanza.

Parameters:
  • mto – The recipient of the message.
  • mbody – The main contents of the message.
  • msubject – Optional subject for the message.
  • mtype – The message’s type, such as 'chat' or 'groupchat'.
  • mhtml – Optional HTML body content in the form of a string.
  • mfrom – The sender of the message. if sending from a client, be aware that some servers require that the full JID of the sender be used.
  • mnick – Optional nickname of the sender.
send_presence(pshow=None, pstatus=None, ppriority=None, pto=None, pfrom=None, ptype=None, pnick=None)[source]

Create, initialize, and send a new Presence stanza.

Parameters:
  • pshow – The presence’s show value.
  • pstatus – The presence’s status message.
  • ppriority – This connection’s priority.
  • pto – The recipient of a directed presence.
  • ptype – The type of presence, such as 'subscribe'.
  • pfrom – The sender of the presence.
  • pnick – Optional nickname of the presence’s sender.
send_presence_subscription(pto, pfrom=None, ptype=u'subscribe', pnick=None)[source]

Create, initialize, and send a new Presence stanza of type 'subscribe'.

Parameters:
  • pto – The recipient of a directed presence.
  • pfrom – The sender of the presence.
  • ptype – The type of presence, such as 'subscribe'.
  • pnick – Optional nickname of the presence’s sender.
server[source]

Attribute accessor for jid host

set_jid(jid)[source]

Rip a JID apart and claim it as our own.

start_stream_handler(xml)[source]

Save the stream ID once the streams have been established.

Parameters:xml – The incoming stream’s root element.
username[source]

Attribute accessor for jid usernode

«  ComponentXMPP   ::   Contents   ::   Exceptions  »

From &yet