Commit graph

182 commits

Author SHA1 Message Date
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
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
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
Lance Stout
4b57b8131f Added support for using SSL CA certificates.
Originally provided by Brian Beggs (macdiesel)
and Thom Nichols (tomstrummer).
2010-12-16 17:30:08 -05:00
Lance Stout
f474d378ef Add support for using xml:lang values.
Support is only for adding literal XML content
to stanzas. Full support for things like multiple
message bodies with different xml:lang values is
still in the works.
2010-12-07 23:07:40 -05:00
Lance Stout
60d3afe6b6 Added __repr__ for JIDs. 2010-11-18 00:03:39 -05:00
Lance Stout
6ee8a2980c Fix RESPONSE_TIMEOUT dependency loops. 2010-11-17 15:13:09 -05:00
Lance Stout
b8114b25ed Make live stream tests work better.
SleekTest can now use matchers when checking stanzas, using
the method parameter for self.check(), self.recv(), and self.send():
    method='exact'      - Same behavior as before
           'xpath'      - Use xpath matcher
           'id'         - Use ID matcher
           'mask'       - Use XML mask matcher
           'stanzapath' - Use StanzaPath matcher

recv_feature and send_feature only accept 'exact' and 'mask' for now.
2010-11-17 13:43:15 -05:00
Nathan Fritz
45991e47ee scheduler no longer waits for the next event before exiting 2010-11-16 17:58:20 -08:00
Lance Stout
4fb77ac878 Logging no longer uses root logger.
Each module should now log into its own logger.
2010-11-06 01:28:59 -04:00
Lance Stout
d0c506f930 Simplified SleekTest.
* check_stanza does not require stanza_class parameter. Introspection!
* check_message, check_iq, and check_presence removed -- use check
  instead.
* stream_send_stanza, stream_send_message, stream_send_iq, and
  stream_send_presence removed -- use send instead.
* Use recv instead of recv_message, recv_presence, etc.
* check_jid instead of check_JID
* stream_start may accept multi=True to return a new SleekTest instance
  for testing multiple streams at once.
2010-11-05 21:18:48 -04:00
Lance Stout
7351fe1a02 Fix bug introduced while fixing another bug.
Threaded event handlers now handle exceptions again.
2010-11-04 14:35:35 -04:00
Nathan Fritz
38c2f51f83 fixed indent errors 2010-11-04 11:39:41 -07:00
Lance Stout
5769935720 Merge branch 'develop' of github.com:fritzy/SleekXMPP into develop 2010-11-03 12:39:44 -04:00
Lance Stout
0214db7545 Catch exceptions for direct events.
Events triggered with direct=True will have exceptions caught.

Note that all event handlers in a direct event will currently run
in the same thread.
2010-11-03 12:38:13 -04:00
Lance Stout
9e248bb852 Fix bug in XEP-0030 plugin.
xep_0030 still referenced event_handlers. Added the method event_handled
which will return the number of registered handlers for an event to
resolve the issue.
2010-10-31 18:27:52 -04:00
Lance Stout
973890e2c9 Added try/except for setting signal handlers.
Setting signal handlers from inside a thread is not supported in Python,
but some applications need to run Sleek from a child thread.

SleekXMPP applications that run inside a child thread will NOT be able
to detect SIGHUP or SIGTERM events. Those must be caught and managed by
the main program.
2010-10-28 10:42:23 -04:00
Lance Stout
9c08e56ed0 SSL and signal fixes.
Made setting the SIG* handlers conditional on if the signal defined for
the OS.

Added the attribute ssl_version to XMLStream to set the version of SSL
used during connection. It defaults to ssl.PROTOCOL_TLSv1, but OpenFire
tends to require ssl.PROTOCOL_SSLv23.
2010-10-27 19:27:47 -04:00
Lance Stout
5bdcd9ef9d Made exceptions work.
Raising an XMPPError exception from an event handler now works, even if
from a threaded handler.

Added stream tests to verify.

We should start using XMPPError, it really makes things simple!
2010-10-25 15:09:56 -04:00
Lance Stout
185d7cf28e More JID unit tests.
sleekxmpp.xmlstream.jid now has 100% coverage!
2010-10-24 19:06:54 -04:00
Lance Stout
9e3d506651 Fixed resource bug in JIDs.
JIDs without resources will return '' instead of the bare JID.

Cleaned up JID tests, and added check_JID to SleekTest.
2010-10-24 18:22:41 -04:00
Lance Stout
8f55704928 Fixed mixed text and elements bug in tostring.
XML of the form <a>foo <b>bar</b> baz</a> was outputted as
<a>foo <b>bar</b> baz baz</a>.

Includes unit test.
2010-10-21 16:21:28 -04:00
Nathan Fritz
d88999691c misc small tweaks 2010-10-20 20:14:26 -07:00
Nathan Fritz
77eab6544f reconnect if session isn't established within 15 seconds 2010-10-20 19:18:27 -07:00
Nathan Fritz
11264fe0a8 capture SIGHUP and SIGTERM (windows) and disconnect; also testall no longer loads string26 with python3 2010-10-20 17:30:12 -07:00
Nathan Fritz
6e34b2cfdd fixed disconnect 2010-10-20 16:32:50 -07:00
Lance Stout
e18354ae0e Continue converting to underscored names. 2010-10-18 09:06:54 -04:00
Lance Stout
4375ac7d8b Underscore names by default.
Stanza objects now accept the use of underscored names.

The CamelCase versions are still available for backwards compatibility,
but are discouraged.

The property stanza.values now maps to the old getStanzaValues and
setStanzaValues, in addition to _set_stanza_values and
_get_stanza_values.
2010-10-17 22:04:42 -04:00
Lance Stout
505a63da3a Cleanup, restore PEP8. 2010-10-16 21:15:31 -04:00
Florent Le Coz
2755d732a4 Remove deprecation warnings
Remove all the deprecation warnings by using only boundjid.
And also fix a indentation error.
2010-10-17 08:55:30 +08:00
Florent Le Coz
2d18d905a5 Anonymous authentication
Implemented ANONYMOUS authentication on the ClientXMPP class.
To use it, you just need to provide a domain (e.g 'anon.example.com')
with an optional resource (e.g 'anon.example.com/resource') as the JID,
with no password. The JID class has been improved to accept
domains as fulljid.

You can test this with echo_client.py
python echo_client.py -j anon.louiz.org/  # anonymous with a resource
                                          # defined by the server
python echo_client.py -j anon.louiz.org/resource  # anonymous with given
                                                  # resource

The "normal" authentication method still works exactly like before.
2010-10-17 08:55:30 +08:00
Nathan Fritz
8b5c1010de fixed JID to accept server/domain/host as the same 2010-10-14 16:34:16 -07:00
Nathan Fritz
aeb7999e6a don't import statemachine 2010-10-14 16:08:50 -07:00
Nathan Fritz
dc001bb201 deprecated jid, fulljid, server, user, resource properties and added boundjid JID 2010-10-14 15:50:54 -07:00