Package pyxmpp :: Module client :: Class Client
[hide private]

Class Client

source code

Known Subclasses:

Base class for an XMPP-IM client.

This class does not provide any JSF extensions to the XMPP protocol, including legacy authentication methods.

Instance Methods [hide private]
 
__init__(self, jid=None, password=None, server=None, port=5222, auth_methods=('sasl:DIGEST-MD5'), tls_settings=None, keepalive=0)
Initialize a Client object.
source code
 
__roster_error(self, iq)
Process roster request failure.
source code
 
__roster_push(self, iq)
Process a "roster push" (change notification) received.
source code
 
__roster_result(self, iq)
Process roster request success.
source code
 
__roster_timeout(self)
Process roster request time out.
source code
 
__session_error(self, iq)
Process session request failure.
source code
 
__session_result(self, _unused)
Process session request success.
source code
 
__session_timeout(self)
Process session request time out.
source code
 
__stream_state_change(self, state, arg)
Handle stream state changes.
source code
 
_session_started(self)
Called when session is started.
source code
 
authenticated(self)
Handle "authenticated" event.
source code
 
authorized(self)
Handle "authorized" event.
source code
 
connect(self, register=False)
Connect to the server and set up the stream.
source code
 
connected(self)
Handle "connected" event.
source code
 
disconnect(self)
Disconnect from the server.
source code
 
disconnected(self)
Handle "disconnected" event.
source code
socket.socket
get_socket(self)
Get the socket object of the active connection.
source code
pyxmpp.ClientStream
get_stream(self)
Get the connected stream object.
source code
 
idle(self)
Do some "housekeeping" work like cache expiration or timeout handling.
source code
 
loop(self, timeout=1)
Simple "main loop" for the client.
source code
 
request_roster(self)
Request the user's roster.
source code
 
request_session(self)
Request an IM session.
source code
 
roster_updated(self, item=None)
Handle roster update event.
source code
 
session_started(self)
Handle session started event.
source code
 
stream_closed(self, stream)
Handle stream closure event.
source code
 
stream_created(self, stream)
Handle stream creation event.
source code
 
stream_error(self, err)
Handle stream error received.
source code
 
stream_state_changed(self, state, arg)
Handle any stream state change.
source code
Instance Variables [hide private]
: list of str auth_methods
: methods allowed for stream authentication.
: list interface_providers
: list of object providing interfaces that could be used by the Client object.
: pyxmpp.JID jid
: configured JID of the client (current actual JID is avialable as self.stream.jid).
: int keepalive
: keepalive interval for the stream or 0 when keepalive is disabled.
: threading.RLock lock
: lock for synchronizing Client attributes access.
: unicode password
: authentication password.
: int port
: port number on the server to use if non-standard and not discoverable by SRV lookups.
: pyxmpp.Roster roster
: user's roster or None if the roster is not yet retrieved.
: unicode server
: server to use if non-standard and not discoverable by SRV lookups.
: bool session_established
: True when an IM session is established.
: threading.Condition state_changed
: condition notified the the object state changes (stream becomes connected, session established etc.).
: pyxmpp.ClientStream stream
: current stream when the client is connected, None otherwise.
Method Details [hide private]

__init__(self, jid=None, password=None, server=None, port=5222, auth_methods=('sasl:DIGEST-MD5'), tls_settings=None, keepalive=0)
(Constructor)

source code 
Initialize a Client object.
Parameters:
  • jid (: pyxmpp.JID) - : user full JID for the connection.
  • password (: unicode) - : user password.
  • server (: unicode) - : server to use. If not given then address will be derived form the JID.
  • port (: int) - : port number to use. If not given then address will be derived form the JID.
  • auth_methods (: sequence of str) - : sallowed authentication methods. SASL authentication mechanisms in the list should be prefixed with "sasl:" string.
  • tls_settings (: pyxmpp.TLSSettings) - : settings for StartTLS -- TLSSettings instance.
  • keepalive (: int) - : keepalive output interval. 0 to disable.

__roster_error(self, iq)

source code 
Process roster request failure.
Parameters:
  • iq (: pyxmpp.Iq) - : IQ error stanza received as result of the roster request.
Raises:

__roster_push(self, iq)

source code 
Process a "roster push" (change notification) received.
Parameters:
  • iq (: pyxmpp.Iq) - : IQ result stanza received.

__roster_result(self, iq)

source code 
Process roster request success.
Parameters:
  • iq (: pyxmpp.Iq) - : IQ result stanza received in reply to the roster request.

__roster_timeout(self)

source code 
Process roster request time out.
Raises:

__session_error(self, iq)

source code 
Process session request failure.
Parameters:
  • iq (: pyxmpp.Iq) - : IQ error stanza received as result of the session request.
Raises:

__session_result(self, _unused)

source code 
Process session request success.
Parameters:
  • _unused (: pyxmpp.Iq) - : IQ result stanza received in reply to the session request.

__session_timeout(self)

source code 
Process session request time out.
Raises:

__stream_state_change(self, state, arg)

source code 

Handle stream state changes.

Call apopriate methods of self.

Parameters:
  • state (: str) - : the new state.
  • arg - : state change argument.

_session_started(self)

source code 

Called when session is started.

Activates objects from self.interface_provides by installing their stanza handlers, etc.

authenticated(self)

source code 
Handle "authenticated" event. May be overriden in derived classes. This one does nothing.

authorized(self)

source code 
Handle "authorized" event. May be overriden in derived classes. This one requests an IM session.

connect(self, register=False)

source code 

Connect to the server and set up the stream.

Set self.stream and notify self.state_changed when connection succeeds.

connected(self)

source code 
Handle "connected" event. May be overriden in derived classes. This one does nothing.

disconnected(self)

source code 
Handle "disconnected" event. May be overriden in derived classes. This one does nothing.

get_socket(self)

source code 
Get the socket object of the active connection.
Returns: socket.socket
socket used by the stream.

get_stream(self)

source code 
Get the connected stream object.
Returns: pyxmpp.ClientStream
stream object or None if the client is not connected.

idle(self)

source code 
Do some "housekeeping" work like cache expiration or timeout handling. Should be called periodically from the application main loop. May be overriden in derived classes.

loop(self, timeout=1)

source code 

Simple "main loop" for the client.

By default just call the pyxmpp.Stream.loop_iter method of self.stream, which handles stream input and self.idle for some "housekeeping" work until the stream is closed.

This usually will be replaced by something more sophisticated. E.g. handling of other input sources.

roster_updated(self, item=None)

source code 
Handle roster update event. May be overriden in derived classes. This one does nothing.
Parameters:
  • item (: pyxmpp.RosterItem) - : the roster item changed or None if whole roster was received.

session_started(self)

source code 
Handle session started event. May be overriden in derived classes. This one requests the user's roster and sends the initial presence.

stream_closed(self, stream)

source code 
Handle stream closure event. May be overriden in derived classes. This one does nothing.
Parameters:

stream_created(self, stream)

source code 
Handle stream creation event. May be overriden in derived classes. This one does nothing.
Parameters:

stream_error(self, err)

source code 
Handle stream error received. May be overriden in derived classes. This one passes an error messages to logging facilities.
Parameters:

stream_state_changed(self, state, arg)

source code 
Handle any stream state change. May be overriden in derived classes. This one does nothing.
Parameters:
  • state (: str) - : the new state.
  • arg - : state change argument.

Instance Variable Details [hide private]

auth_methods

: methods allowed for stream authentication. SASL mechanism names should be preceded with "sasl:" prefix.
Type:
: list of str

interface_providers

: list of object providing interfaces that could be used by the Client object. Initialized to [self] by the constructor if not set earlier. Put objects providing IPresenceHandlersProvider, IMessageHandlersProvider, IIqHandlersProvider or IStanzaHandlersProvider into this list.
Type:
: list