Resolved by always normalizing JIDs to bare form, regardless of if they
are JID objects or strings.
Also simplified related code to prefer use of JID objects instead of
strings so they don't need to be parsed multiple times.
Using the special language value '*' will return a dictionary of all
such elements keyed by language.
>>> msg = Message()
>>> msg['body'] = 'Hi!'
>>> msg['body|sv'] = 'Hej!'
>>> print(msg)
'<message xmlns="jabber:client">
<body>Hi!</body>
<body xml:lang="sv">Hej!</body>
</message>'
>>> print(msg['body|*'])
OrderedDict(
('', 'Hi!'),
('sv', 'Hej!'))
Remaining items:
- Stanza path matching does not support language specifiers for normal
interfaces, only for plugins.
Certificate host names are now matched (using DNS, SRV, XMPPAddr, and
Common Name), along with expiration check.
Scheduled event to reset the stream once the server's cert expires.
Handle invalid cert trust chains gracefully now.
All event handlers which call disconnect() MUST be registered using
`add_event_handler(..., threaded=True)` in order to prevent temporarily
deadlocking until a timeout occurs.
This is required because disconnect() waits for the main threads to
exit before returning, including the event processing thread. Since
handlers registered without `threaded=True` run in the event processing
thread, the disconnect() call will deadlock.
If calling disconnect() from a non-threaded event handler, deadlock can
happen as disconnect() is waiting for threads to close, but the event
runner is blocked by a handler waiting for disconnect() to return.
It is best to specify threaded=True for event handlers which may call
disconnect().
- Add option for disconnecting without sending </stream>:
self.disconnect(send_close=False)
- Optionally distinguish between session_end and disconnected based
on if </stream> was sent.
self.end_session_on_disconnect = False
The set of bool_interfaces provides default behaviour for
checking/setting the presence of empty subelements.
The prime example of this would be:
bool_interfaces = set(['required'])
This would mean that ``stanza['required']`` would return ``True`` for:
<stanza>
<required />
</stanza>
and ``False`` for:
<stanza />
Likewise, assigning ``stanza['required'] = True`` would add an empty
``<required />`` element, and setting it to ``False`` would remove
such an element if it exists.
Added option to XMLStream.send() to skip applying filters.
Filters in the out_sync group are synced with placing stanza content
either on the wire directly or into the send queue. Because of this,
out_sync filters should not block.
Setting self.reconnect_max_attempts to a non-None value will limit
the number of times a connection attempt will be made before quiting
and raising a 'connection_failed' event.
The payload is a dictionary of parsed cert data, as provided by
Python's getpeercert() socket method. It unfortunately does not
provide much detail beyond basic info.
The parsing and namespace cleaning isn't terribly expensive, but it does
add up. It was adding an extra 5sec when processing 100,000 basic
message stanzas.
Based on profiling, using around 35 stream handlers quarters the number
of basic message stanzas that can be processed in a second, in
comparison to only using the bare minimum of four handlers.
To help, we can drop handlers for stream features once the session
has started. So that we can re-enable these handlers when a stream
must restart, the 'stream_start' event has been added which fires
whenever a stream header is received.
The 'stream_start' event is a more generic replacement for the
existing start_stream_handler() method.
This allows applications to filter out sensitive information, such
as passwords, so that it won't appear in the logs.
It does mean that the debug logs will not show the actual received
data, and there will be no indication of tampering, unless the
filter author explicitly logs and notes that a change was made.
A filter accepts and returns a stanza, but potentially modified.
To prevent sending/receiving a stanza, a filter may return None.
Incoming:
self.add_filter('in', in_filter)
Outgoing:
self.add_filter('out', out_filter)
Filters are applied in the order thay are added. However, you may
add an order parameter, which is the place in the list to insert the
filter:
self.add_filter('in', in_filter, order=0)
May set self.disconnect_wait=True so that all disconnect
calls wait for the send queue to empty, unless explicitly
overridden with wait=False.
The session_end now fires before closing the socket so
that final stanzas may be sent, such as unavailable presences
for components.