pyxmpp.jabberd.component.Component

Package pyxmpp :: Package jabberd :: Module component :: Class Component |
[show private | hide private]
[frames | no frames]

## Class Component

Jabber external component ("jabber:component:accept" protocol) interface implementation.

Override this class to build your components.

Method Summary
| ``__init__`(self, jid, secret, server, port, disco_name, disco_category, disco_type, keepalive)` Initialize a `Component` object.
| ``authenticated`(self)` Handle successful authentication event.
| ``authorized`(self)` Handle successful authorization event.
| ``connect`(self)` Establish a connection with the server.
| ``connected`(self)` Handle stream connection event.
| ``disco_get_info`(self, node, iq)` Get disco#info data for a node.
| ``disco_get_items`(self, node, iq)` Get disco#items data for a node.
| ``disconnect`(self)` Disconnect from the server.
| ``disconnected`(self)` Handle stream disconnection (connection closed by peer) event.
`pyxmpp.jabberd.ComponentStream` | ``get_stream`(self)` Get the stream of the component in a safe way.
| ``idle`(self)` Do some "housekeeping" work like <iq/> result expiration.
| ``loop`(self, timeout)` Simple 'main loop' for a component.
| ``register_feature`(self, feature_name)` Register a feature to be announced by Service Discovery.
`socket.socket` | ``socket`(self)` Get the socket of the connection to the server.
| ``stream_closed`(self, stream)` Handle stream closure event.
| ``stream_created`(self, stream)` Handle stream creation event.
| ``stream_error`(self, err)` Handle a stream error received.
| ``stream_state_changed`(self, state, arg)` Handle a stream state change.
| ``unregister_feature`(self, feature_name)` Unregister a feature to be announced by Service Discovery.
| ``__disco_info`(self, iq)` Handle a disco-info query.
| ``__disco_items`(self, iq)` Handle a disco-items query.
| ``__stream_state_change`(self, state, arg)` Handle various stream state changes and call right methods of `self`.

Instance Variable Summary
`str` | `disco_category`: disco category to be used to create `disco_identity`.
`pyxmpp.jabber.DiscoIdentity` | `disco_identity`: disco identity (part of disco info) announced by the component.
`pyxmpp.jabber.DiscoInfo` | `disco_info`: disco info announced by the component.
`pyxmpp.jabber.DiscoItems` | `disco_items`: disco items announced by the component.
`str` | `disco_type`: disco type to be used to create `disco_identity`.
`pyxmpp.JID` | `jid`: component JID (should contain only the domain part).
`int` | `keepalive`: keepalive interval for the stream.
`int` | `port`: port number on the server to which the commonent will connect.
`unicode` | `secret`: the authentication secret.
`unicode` | `server`: server to which the commonent will connect.
`pyxmpp.jabberd.ComponentStream` | `stream`: the XMPP stream object for the active connection or `None` if no connection is active.

Method Details

### __init__(self, jid=None, secret=None, server=None, port=5347, disco_name=u'PyXMPP based component', disco_category=u'x-service', disco_type=u'x-unknown', keepalive=0) (Constructor) Initialize a `Component` object. Parameters: `jid` - component JID (should contain only the domain part). (type=`pyxmpp.JID`) `secret` - the authentication secret. (type=`unicode`) `server` - server name or address the component should connect. (type=`str` or `unicode`) `port` - port number on the server where the component should connect. (type=`int`) `disco_name` - disco identity name to be used in the disco#info responses. (type=`unicode`) `disco_category` - disco identity category to be used in the disco#info responses. Use the categories registered by Jabber Registrar (type=`unicode`) `disco_type` - disco identity type to be used in the component's disco#info responses. Use the types registered by Jabber Registrar (type=`unicode`) `keepalive` - keepalive interval for the stream. (type=`int`)

### authenticated(self) Handle successful authentication event. A good place to register stanza handlers and disco features. [should be overriden in derived classes] By default: set disco#info and disco#items handlers.

### authorized(self) Handle successful authorization event.

### connect(self) Establish a connection with the server. Set `self.stream` to the `pyxmpp.jabberd.ComponentStream` when initial connection succeeds. Raises: `ComponentError` - when some of the component properties (`self.jid`, `self.secret`,`self.server` or `self.port`) are wrong.

### connected(self) Handle stream connection event. [may be overriden in derived classes] By default: do nothing.

### disco_get_info(self, node, iq) Get disco#info data for a node. [may be overriden in derived classes] By default: return `self.disco_info` if no specific node name is provided. Parameters: `node` - name of the node queried. (type=`unicode`) `iq` - the stanza received. (type=`pyxmpp.Iq`)

### disco_get_items(self, node, iq) Get disco#items data for a node. [may be overriden in derived classes] By default: return `self.disco_items` if no specific node name is provided. Parameters: `node` - name of the node queried. (type=`unicode`) `iq` - the stanza received. (type=`pyxmpp.Iq`)

### disconnect(self) Disconnect from the server.

### disconnected(self) Handle stream disconnection (connection closed by peer) event. [may be overriden in derived classes] By default: do nothing.

### get_stream(self) Get the stream of the component in a safe way. Returns: Stream object for the component or `None` if no connection is active. (type=`pyxmpp.jabberd.ComponentStream`)

### idle(self) Do some "housekeeping" work like <iq/> result expiration. Should be called on a regular basis, usually when the component is idle.

### loop(self, timeout=1) Simple 'main loop' for a component. This usually will be replaced by something more sophisticated. E.g. handling of other input sources.

### register_feature(self, feature_name) Register a feature to be announced by Service Discovery. Parameters: `feature_name` - feature namespace or name. (type=`unicode`)

### socket(self) Get the socket of the connection to the server. Returns: the socket. (type=`socket.socket`)

### stream_closed(self, stream) Handle stream closure event. [may be overriden in derived classes] By default: do nothing. Parameters: `stream` - the stream just created. (type=`pyxmpp.jabberd.ComponentStream`)

### stream_created(self, stream) Handle stream creation event. [may be overriden in derived classes] By default: do nothing. Parameters: `stream` - the stream just created. (type=`pyxmpp.jabberd.ComponentStream`)

### stream_error(self, err) Handle a stream error received. [may be overriden in derived classes] By default: just log it. The stream will be closed anyway. Parameters: `err` - the error element received. (type=`pyxmpp.error.StreamErrorNode`)

### stream_state_changed(self, state, arg) Handle a stream state change. [may be overriden in derived classes] By default: do nothing. Parameters: `state` - state name. (type=`string`) `arg` - state parameter. (type=any object)

### unregister_feature(self, feature_name) Unregister a feature to be announced by Service Discovery. Parameters: `feature_name` - feature namespace or name. (type=`unicode`)

### __disco_info(self, iq) Handle a disco-info query. Types: `iq`: `pyxmpp.Iq` Parameters: `iq` - the stanza received.

### __disco_items(self, iq) Handle a disco-items query. Types: `iq`: `pyxmpp.Iq` Parameters: `iq` - the stanza received.

### __stream_state_change(self, state, arg) Handle various stream state changes and call right methods of `self`. Parameters: `state` - state name. (type=`string`) `arg` - state parameter. (type=any object)

Instance Variable Details

### disco_category disco category to be used to create `disco_identity`. Type: `str`

### disco_identity disco identity (part of disco info) announced by the component. Created when a stream is connected. Type: `pyxmpp.jabber.DiscoIdentity`

### disco_info disco info announced by the component. Created when a stream is connected. Type: `pyxmpp.jabber.DiscoInfo`

### disco_items disco items announced by the component. Created when a stream is connected. Type: `pyxmpp.jabber.DiscoItems`

### disco_type disco type to be used to create `disco_identity`. Type: `str`

### jid component JID (should contain only the domain part). Type: `pyxmpp.JID`

### keepalive keepalive interval for the stream. Type: `int`

### port port number on the server to which the commonent will connect. Type: `int`

### secret the authentication secret. Type: `unicode`

### server server to which the commonent will connect. Type: `unicode`

### stream the XMPP stream object for the active connection or `None` if no connection is active. Type: `pyxmpp.jabberd.ComponentStream`