Skip to content

Instantly share code, notes, and snippets.

@legastero
legastero / xep_0059_reversed.md
Last active February 15, 2020 03:43
XEP-0059 Reversed Pages

Reverse Item Ordering

In some cases, it is useful for the order of items in a page to be reversed when paging backwards through a result set. These cases are typically when the result page is returned as a series of response stanzas by the wrapper protocol instead of as a single result stanza.

Requesting reverse order for a result set page is done by including a <reversed /> element in the page request.

@legastero
legastero / parser.py
Created September 13, 2012 18:53
Experimental restricted XML parser for SleekXMPP
# -*- encoding: utf-8 -*-
"""
sleekxmpp.xml.parser
~~~~~~~~~~~~~~~~~~~~
This module provides a customized XML parser that restricts
the use of certain XML features as mandated by RFC 6120.
Part of SleekXMPP: The Sleek XMPP Library
@legastero
legastero / gist:1110035
Created July 27, 2011 18:27
XMPPFlask MUC Bot using SleekXMPP
# -*- coding: utf-8 -*-
"""
xmpp_wsgi_runner for xmppflask (or just XMPPWSGI)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This application is intended to be something like a web server bug for
XMPPWSGI and serve XMPPWSGI applications. It is kept simple, but
potentially can be rewritten to handle more load. Future plans are also
support of gevent-like coroutines, but we will need to try to import
gevent's monkey.patch_sockets() to PyPy somehow.
@legastero
legastero / gist:1109928
Created July 27, 2011 17:30
Using SleekXMPP with XMPPFlask
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
xmpp_wsgi_runner for xmppflask (or just XMPPWSGI)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This application is intended to be something like a web server bug for
XMPPWSGI and serve XMPPWSGI applications. It is kept simple, but
potentially can be rewritten to handle more load. Future plans are also
support of gevent-like coroutines, but we will need to try to import
@legastero
legastero / del_roster.py
Created July 19, 2010 07:50
Delete Roster Item
# Where self is a ClientXMPP object
self.delRosterItem('[email protected]')
# -or-
self.updateRoster('[email protected]', subscription='remove')
@legastero
legastero / update_roster.py
Created July 19, 2010 07:36
Update Roster
# Where self is a ClientXMPP object
self.rosterUpdate('[email protected]', name='Romeo', groups=['Montagues'])
@legastero
legastero / subscription_handling.py
Created June 17, 2010 19:02
Subscription Handling
# Where self is a SleekXMPP object, and self.backend is some arbitrary
# object that you create depending on the needs of your application.
# self.add_event_handler('presence_subscribe', self.subscribe)
# self.add_event_handler('presence_subscribed', self.subscribed)
# The unsubscribe and unsubscribed handlers will be similar.
# If a component is being used, be sure to set the pfrom parameter
# when sending presences if you are using multiple JIDs for the component,
# such as [email protected] and [email protected].
@legastero
legastero / send_presence_subscription.py
Created June 17, 2010 18:37
Send Presence Subscription
# Where xmpp is a SleekXMPP object
xmpp.sendPresence(pto='[email protected]', ptype='subscribe')
# -or-
xmpp.sendPresenceSubscription(pto='[email protected]', ptype='subscribe', pnick='Sleek')
@legastero
legastero / send_presence_probe.py
Created June 17, 2010 14:31
Send Presence Probe
# Where xmpp is a SleekXMPP object
xmpp.sendPresence(pto='[email protected]', ptype='probe')
@legastero
legastero / presence_probe.py
Created June 17, 2010 14:25
Handle Presence Probe
# Where self is a SleekXMPP object:
# self.add_event_handler('presence_probe', handle_probe)
def handle_probe(self, presence):
sender = presence['from']
# Populate the presence reply with the agent's current status.
self.sendPresence(pto=sender, pstatus="Busy studying XMPP", pshow="dnd")