Commit graph

213 commits

Author SHA1 Message Date
Lance Stout
3918ddb075 Merge branch 'develop' into stream_features 2011-08-03 17:02:33 -07:00
Lance Stout
5efb170e1d Added wait parameter to disconnect.
If wait=True, then the disconnect call will block until
the send queue has emptied.

WARNING: Using wait=True when more stanzas are being added to the
queue than can be processed such that the queue is never empty
will cause the disconnect call to block indefinitely without actually
disconnecting.
2011-07-04 18:47:57 -07:00
Lance Stout
04def6d925 Merge branch 'develop' into stream_features 2011-07-01 15:19:37 -07:00
Lance Stout
2a2ac73845 So using sys.excepthook to catch errors only works once.
The error bubbles through the event processing loop, breaking it and
hanging the application.

Instead, there is now a .exception(e) method on XMLStream which may
be overridden or reassigned that will receive all unhandled exceptions
(read: not XMPPError) from event and stream handlers.
2011-07-01 15:18:10 -07:00
Lance Stout
fa716457a5 Merge branch 'develop' into stream_features 2011-06-20 16:27:55 -07:00
Lance Stout
d8d9e8df16 Fix stanza clobbering when replying to errors.
If a stanza handler raised an exception, the exception was processed
and replied by the modified stanza, not a stanza with the original
content.

A copy is now made before handler processing, and if an exception occurs
it is the copy that processes the exception using the original content.
2011-06-20 16:25:56 -07:00
Lance Stout
7a60e4b458 Merge branch 'develop' into stream_features 2011-06-10 15:14:51 -07:00
Lance Stout
e219c0f976 Added session_end event and some docs.
For now, session_end is the same as disconnected, but once support is
added later for stream management, the two events will become distinct.

Plugins should add handlers for session_end for cleaning any session
state.
2011-06-08 10:24:25 -07:00
Lance Stout
8f9100c762 Merge branch 'develop' into stream_features 2011-06-01 15:17:13 -07:00
Lance Stout
1469323350 Cache stanza if sending fails.
The stanza will be sent first once the send queue is reactivated
after session start.

Stanzas sent by skipping the queue will not be cached.
2011-06-01 15:10:44 -07:00
Lance Stout
83a73ac9b7 Merge branch 'develop' into stream_features
Conflicts:
	sleekxmpp/clientxmpp.py
2011-05-31 11:05:54 -07:00
Lance Stout
a81162edd2 Apply connection backoff to reconnect attempts.
Backoff was only being done for the initial connection attempt
before. Now any reconnection will start with a minimum 1 sec
delay which will approximately double between attempts.
2011-05-31 10:55:15 -07:00
Lance Stout
8080b4cae2 Cleanup logging and exception handling.
The syntax and attribute errors raised during a disconnect/reconnect
attempt are now caught and produce nicer log messages.
2011-05-31 10:23:05 -07:00
Lance Stout
1735c194cd Don't use the send queue for stream initialization.
Use the parameter now=True to skip the queue when
sending Iq stanzas, or using xmpp.send().
2011-05-27 17:00:57 -07:00
Lance Stout
6997b2fbf8 Fix typo for SSL certificate use. 2011-05-27 16:39:45 -07:00
Lance Stout
b81ab97900 Add exponential backoff to connection attempts.
Delay will approximately double between attempts (random variation).

See issue #67.
2011-05-27 14:42:40 -07:00
Lance Stout
384e1a92b7 Added support for testind disconnect errors. 2011-05-27 11:01:30 -07:00
Lance Stout
9851a2a057 Merge branch 'develop' into stream_features 2011-05-20 21:41:44 -04:00
Lance Stout
6b274a2543 Fix double roster entry issue with Unicode.
JIDs with Unicode values were being encoded by the JID class
instead of leaving them as just Unicode strings.

It may still be a good idea to use

    from __future__ import unicode_literals

pretty much everywhere though.

Fixes issue #88.
2011-05-20 16:48:13 -04:00
Lance Stout
e2de82ac8d Merge branch 'develop' into stream_features
Conflicts:
	sleekxmpp/clientxmpp.py
2011-05-20 13:26:21 -04:00
Lance Stout
1d891858b6 Mark scheduler thread as a daemon. 2011-04-11 14:22:32 -04:00
Lance Stout
f125c11a81 Merge branch 'develop' into stream_features 2011-03-24 13:15:09 -04:00
Lance Stout
6d45971411 Allow a stanza plugin to override a parent's interfaces.
Each interface, say foo, may be overridden in three ways:
    set_foo
    get_foo
    del_foo

To declare an override in a plugin, add the class field
overrides as so:
    overrides = ['set_foo', 'del_foo']

Each override must have a matching set_foo(), etc method
for implementing the new behaviour.

To enable the overrides for a particular parent stanza,
pass the option overrides=True to register_stanza_plugin.

    register_stanza_plugin(Stanza, Plugin, overrides=True)

Example code:

class Test(ElementBase):

    name = 'test'
    namespace = 'testing'
    interfaces = set(('foo', 'bar'))
    sub_interfaces = set(('bar',))

class TestOverride(ElementBase):

    name = 'test-override'
    namespace = 'testing'
    plugin_attrib = 'override'
    interfaces = set(('foo',))
    overrides = ['set_foo']

    def setup(self, xml):
        # Don't include an XML element in the parent stanza
        # since we're adding just an attribute.
        # If adding a regular subelement, no need to do this.
        self.xml = ET.Element('')

    def set_foo(self, value):
        print("overrides!")
        self.parent()._set_attr('foo', 'override-%s' % value)

register_stanza_plugin(Test, TestOverride, overrides=True)

Example usage:
>>> t = TestStanza()
>>> t['foo'] = 'bar'
>>> t['foo']
'override-bar'
2011-03-24 12:25:17 -04:00
Lance Stout
306bdd8021 Merge branch 'develop' into stream_features 2011-03-22 20:48:28 -04:00
Lance Stout
4b1fadde4b Updated XEP-0128 plugin to work with the new XEP-0030 plugin.
Required fixing a few bugs in StanzaBase related to iterable
substanzas.
2011-03-22 20:42:43 -04:00
Lance Stout
566ec8a5f9 Merge branch 'develop' into stream_features
Conflicts:
	sleekxmpp/xmlstream/stanzabase.py
2011-03-18 17:39:43 -04:00
Lance Stout
dbf6780345 Change namespace inclusion in strings.
ElementBase instances will display the top-most namespace by default.

StanzaBase instances will NOT display the top-most namespace by default.

May pass True or False to __str__ to override.
2011-03-18 17:34:07 -04:00
Lance Stout
f2c99798a6 Merge branch 'develop' into stream_features 2011-03-18 15:51:44 -04:00
Lance Stout
6244857746 Fix self.disconnect(reconnect=True) not working. 2011-03-18 15:47:21 -04:00
Lance Stout
4df3aa569b Bring back the signal handlers (and the "killed" event).
Now done more responsibly, saving any existing signal handlers
and calling them when an interrupt occurs in addition to the
one Sleek installs.

NOTE: You may need to explicitly use "kill <process id>" in
order to trigger the proper signal handler execution, and
to raise the "killed" event.
2011-02-23 10:20:04 -05:00
Lance Stout
d5b3a52827 Merge branch 'develop' into stream_features
Conflicts:
	sleekxmpp/xmlstream/stanzabase.py
2011-02-14 16:26:23 -05:00
Lance Stout
d709f8db65 Use the _build_stanza method. 2011-02-14 13:50:59 -05:00
Lance Stout
75584d7ad7 Remap old method names in a better way.
This should prevent some reference cycles that will cause garbage
collection issues.
2011-02-14 13:49:43 -05:00
Lance Stout
e0f9025e7c More attempts at fixing garbage collection.
Don't keep a reference to stanzas in Callback objects.
2011-02-14 11:30:04 -05:00
Lance Stout
9004e8bbf2 Break references that can prevent garbage collection. 2011-02-14 11:13:41 -05:00
Lance Stout
8b5511c7ec Simplification when removing a deletable handler. 2011-02-13 16:40:04 -05:00
Lance Stout
70af52d74c Make one-off Callbacks ready for deletion after the prerun step.
Waiting until the actual run step means that the handler is not
marked for deletion when checked in the __spawn_event() thread,
causing the callback to stay in the handler list.
2011-02-13 16:28:06 -05:00
Lance Stout
0d32638379 XMPPError exceptions can keep a stanza's contents.
This allows exceptions to include the original
content of a stanza in the error response by including
the parameter clear=False when raising the exception.
2011-02-11 15:20:26 -05:00
Lance Stout
bd9bf3f1c7 Update tostring methods.
Will now always show top-level namespace, unless it is the same
as the stream's default namespace. Also added the XMPP stream
namespace to the namespace map as 'stream'.
2011-01-27 18:05:05 -05:00
Lance Stout
35ef8f9090 Make stanza.plugins an OrderedDict.
This allows you to determine the order in which substanzas
were added in the original XML.
2011-01-27 16:01:35 -05:00
Lance Stout
38dc35840e Recognize stanzas that don't use the default namespace. 2011-01-27 15:59:50 -05:00
Lance Stout
0c8a8314b2 Cleanup for stanzabase.
Use stanza.values instead of _get/set_stanza_values where used.

ElementBase stanzas can now use .tag

May use class method tag_name() for stanza classes.

ElementBase now has .clear() method.
2011-01-26 11:27:41 -05:00
Lance Stout
4e757c2b56 Upgraded how subitem works.
May now use register_stanza_plugin(Foo, Bar, iterable=True)
to add to the set of stanza classes used for iterable
substanzas. It is no longer necessary to manually specify
the contents of subitem if the new method is used.
2011-01-26 10:04:36 -05:00
Lance Stout
da332365d4 Make extending stanza objects nicer.
A stanza object may add is_extension = True to its class definition
to provide a single new interface to a parent stanza.

For example:

import sleekxmpp
from sleekxmpp import Iq
from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin, ET

class Foo(ElementBase):
    """
    Test adding just an attribute to a parent stanza.

    Adding subelements works as expected.
    """
    is_extension = True
    interfaces = set(('foo',))
    plugin_attrib = 'foo'

    def setup(self, xml):
        # Don't include an XML element in the parent stanza
        # since we're adding just an attribute.
        # If adding a regular subelement, no need to do this.
        self.xml = ET.Element('')

    def set_foo(self, val):
        self.parent()._set_attr('foo', val)

    def get_foo(self):
        return self.parent()._get_attr('foo')

    def del_foo(self):
        self.parent()._del_attr('foo')

register_stanza_plugin(Iq, Foo)

i1 = Iq()
i2 = Iq(xml=ET.fromstring("<iq xmlns='jabber:client' foo='bar' />"))

>>> i1['foo'] = '3'
>>> i1
'3'
>>> i1
'<iq id="0" foo="3" />'
>>> i2
'<iq id="0" foo="bar" />'
>>> i2['foo']
'bar'
>>> del i2['foo']
>>> i2
'<iq id="0" />'
2011-01-19 19:49:13 -05:00
Lance Stout
cb85d4a529 Raise the event 'socket_error' when a socket error occurs.
Will be most useful for debugging and responding to failed
connection attempts.
2011-01-16 13:07:39 -05:00
Lance Stout
d7dea0c6cc Add a note for debug statement when running scheduled events.
Fixes the intermittent DEBUG ((),) messages that give no
explanation.

Will now show as:
DEBUG Scheduled event: ((), )
2011-01-14 12:07:25 -05:00
Lance Stout
632827f213 Fix bug in JID class. Attribute .jid now works properly. 2011-01-13 10:21:20 -05:00
Lance Stout
2908751020 Allow JID objects to be compared with strings.
Two JIDs match if they have the same full JID value.
2011-01-05 20:16:15 -05:00
Lance Stout
34c374a1e1 Make tests pass for catching exceptions.
May now use sys.excepthook to catch exceptions
from threaded handlers.
2010-12-17 13:11:03 -05:00
Lance Stout
0aee445e69 Use daemon threads instead of signals.
Daemonized threads exit once the main program has quit,
and the only threads left running are all daemon threads.

Should fix hanging clients while not trampling over anyone
else's signal handlers.
2010-12-16 22:21:50 -05:00