Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://svn.defuze.org/oss/headstock@979 5b3156b2-dc0e-0410-86c6-8c750cf32934
- Loading branch information
sylvain
committed
Nov 7, 2009
1 parent
8d6e9a1
commit f527882
Showing
103 changed files
with
1,175 additions
and
11,046 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
import headstock | ||
from headstock.lib.stanza import Stanza | ||
from bridge import Element as E | ||
from bridge import Attribute as A | ||
from bridge.common import XMPP_CLIENT_NS, XMPP_ROSTER_NS | ||
|
||
class Basic(object): | ||
def ready(self, client): | ||
self.client = client | ||
|
||
def cleanup(self): | ||
self.client = None | ||
|
||
@headstock.xmpphandler('item', XMPP_ROSTER_NS) | ||
def roster(self, e): | ||
self.client.log("Contact '%s' %s with subscription: %s" % (e.get_attribute_value('name', ''), | ||
e.get_attribute_value('jid', ''), | ||
e.get_attribute_value('subscription', ''))) | ||
|
||
@headstock.xmpphandler('presence', XMPP_CLIENT_NS) | ||
def presence(self, e): | ||
self.client.log("Received '%s' presence from: %s" % (e.get_attribute_value('type', 'available'), | ||
e.get_attribute_value('from'))) | ||
|
||
@headstock.xmpphandler('message', XMPP_CLIENT_NS) | ||
def message(self, e): | ||
who = e.get_attribute_value('from') | ||
body = e.get_child('body', ns=e.xml_ns) | ||
print "%s says: %s" % (who, body.xml_text) | ||
|
||
# Echo the received message | ||
m = E(u"message", attributes={u'from': unicode(self.client.jid), u'to': who, u'type': u'chat', | ||
u'id': e.get_attribute_value('id')}, | ||
namespace=XMPP_CLIENT_NS) | ||
E(u'body', content=body.xml_text, namespace=XMPP_CLIENT_NS, parent=m) | ||
|
||
self.client.send_stanza(m) | ||
|
||
if __name__ == '__main__': | ||
from headstock.lib.utils import parse_commandline | ||
|
||
options = parse_commandline() | ||
if not options.password: | ||
from getpass import getpass | ||
options.password = getpass() | ||
host, port = options.address.split(':') | ||
|
||
registercls = None | ||
if options.register: | ||
from headstock.register import Register | ||
registercls = Register | ||
|
||
from headstock.client import AsyncClient | ||
c = AsyncClient(unicode(options.jid), unicode(options.password), | ||
hostname=host, port=int(port), tls=options.usetls, | ||
register=registercls) | ||
c.set_log(stdout=True) | ||
|
||
c.register(Basic()) | ||
|
||
c.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# -*- coding: utf-8 -*- | ||
import headstock | ||
from headstock.client import AsyncClient | ||
from headstock.lib.stanza import Stanza | ||
from bridge import Element as E | ||
from bridge import Attribute as A | ||
from bridge.common import XMPP_CLIENT_NS, XMPP_ROSTER_NS,\ | ||
XMPP_PUBSUB_NS | ||
|
||
from basic import Basic | ||
|
||
class PubSub(object): | ||
def ready(self, client): | ||
self.client = client | ||
self.fetch() | ||
self.unsubscribe(u"http://www.reddit.com/r/WeAreTheMusicMakers/.rss") | ||
self.subscribe(u"http://www.reddit.com/r/WeAreTheMusicMakers/.rss") | ||
|
||
def fetch(self): | ||
iq = Stanza.get_iq(self.client.jid, u"firehoser.superfeedr.com") | ||
|
||
pubsub = E(u"pubsub", namespace=XMPP_PUBSUB_NS, parent=iq) | ||
A(u"superfeedr", prefix=u"xmlns", parent=pubsub, | ||
namespace=u"http://superfeedr.com/xmpp-pubsub-ext") | ||
sub = E(u"subscriptions", attributes={u"jid": unicode(self.client.jid)}, | ||
parent=pubsub, namespace=XMPP_PUBSUB_NS) | ||
A(u"page", value=u"1", prefix=u"superfeedr", parent=sub) | ||
|
||
self.client.send_stanza(iq) | ||
|
||
def subscribe(self, url): | ||
iq = Stanza.set_iq(self.client.jid, u"firehoser.superfeedr.com") | ||
|
||
pubsub = E(u"pubsub", namespace=XMPP_PUBSUB_NS, parent=iq) | ||
A(u"superfeedr", prefix=u"xmlns", parent=pubsub, | ||
namespace=u"http://superfeedr.com/xmpp-pubsub-ext") | ||
E(u"subscribe", attributes={u"jid": u"", u"node": url}, | ||
parent=pubsub, namespace=XMPP_PUBSUB_NS) | ||
|
||
self.client.send_stanza(iq) | ||
|
||
def unsubscribe(self, url): | ||
iq = Stanza.set_iq(self.client.jid, u"firehoser.superfeedr.com") | ||
|
||
pubsub = E(u"pubsub", namespace=XMPP_PUBSUB_NS, parent=iq) | ||
A(u"superfeedr", prefix=u"xmlns", parent=pubsub, | ||
namespace=u"http://superfeedr.com/xmpp-pubsub-ext") | ||
E(u"unsubscribe", attributes={u"jid": u"", u"node": url}, | ||
parent=pubsub, namespace=XMPP_PUBSUB_NS) | ||
|
||
self.client.send_stanza(iq) | ||
|
||
@headstock.xmpphandler('subscription', XMPP_PUBSUB_NS) | ||
def subscription(self, e): | ||
print e.xml() | ||
|
||
@headstock.xmpphandler('message', XMPP_PUBSUB_NS) | ||
def message(self, e): | ||
print e.xml() | ||
|
||
|
||
if __name__ == '__main__': | ||
from headstock.lib.utils import parse_commandline | ||
|
||
options = parse_commandline() | ||
if not options.password: | ||
from getpass import getpass | ||
options.password = getpass() | ||
host, port = options.address.split(':') | ||
|
||
c = AsyncClient(unicode(options.jid), unicode(options.password), | ||
hostname=host, port=int(port), tls=options.usetls) | ||
c.set_log(stdout=True) | ||
|
||
c.register(Basic()) | ||
c.register(PubSub()) | ||
|
||
c.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.