microblog sending

- Bridge: added sendPersonalEvent to DBus frontend
- plugin XEP_0277: * fixed unicode issue
				   * node options are now changed instead of node being deleted/recreated for setMicroblogAccess
- xml_tools: fixed unicode issue
This commit is contained in:
Goffi 2011-03-26 17:51:19 +01:00
commit 9361e8fdcc
4 changed files with 21 additions and 10 deletions

View file

@ -217,3 +217,6 @@ class DBusBridgeFrontend(BridgeFrontend):
def getLastMicroblogs(self, jid, max_items, profile_key='@DEFAULT@', callback=None, errback=None):
return self.db_comm_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'):
return self.db_comm_iface.sendPersonalEvent(event_type, data, profile_key)

View file

@ -99,3 +99,6 @@ class DBusBridgeFrontend(BridgeFrontend):
def getLastMicroblogs(self, jid, max_items, profile_key='@DEFAULT@', callback=None, errback=None):
return self.db_comm_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'):
return self.db_comm_iface.sendPersonalEvent(event_type, data, profile_key)

View file

@ -117,15 +117,16 @@ class XEP_0277():
content = data['content']
if not content:
error(_("Microblog data's content value must not be empty"))
return 3
_uuid = unicode(uuid.uuid1())
_entry = Entry()
#FIXME: need to escape html
_entry.title = content.encode('utf-8')
_entry.title = unicode(content).encode('utf-8')
_entry.author = Author()
_entry.author.name = data.get('author',self.host.getJidNStream(profile)[0].userhost()).encode('utf-8')
_entry.updated = float(data.get('timestamp',time()))
_entry.id = _uuid
_entry_elt = ElementParser()(str(_entry))
_entry.id = str(_uuid)
_entry_elt = ElementParser()(str(_entry).decode('utf-8'))
item = pubsub.Item(payload=_entry_elt)
item['id'] = _uuid
self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key = profile)
@ -145,14 +146,15 @@ class XEP_0277():
def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@'):
"""Create a microblog node on PEP with given access
If the node already exists, it is deleted and recreated
If the node already exists, it change options
@param access: Node access model, according to xep-0060 #4.5
@param profile_key: profile key"""
jid, xmlstream = self.host.getJidNStream(profile_key)
_options = {NS_ACCESS_MODEL:access, NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1}
def cb(result):
#Node is created with right permission
debug(_("Microblog node created"))
debug(_("Microblog node has now access %s") % access)
def fatal_err(s_error):
#Something went wrong
@ -162,14 +164,17 @@ class XEP_0277():
#If the node already exists, the condition is "conflict",
#else we have an unmanaged error
if s_error.value.condition=='conflict':
d = self.host.plugins["XEP-0060"].deleteNode(jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key)
d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err))
d.addErrback(fatal_err)
#d = self.host.plugins["XEP-0060"].deleteNode(jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key)
#d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err))
change_node_options().addCallback(cb).addErrback(fatal_err)
else:
fatal_err(s_error)
def create_node():
return self.host.plugins["XEP-0060"].createNode(jid.userhostJID(), NS_MICROBLOG, {NS_ACCESS_MODEL:access, NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1}, profile_key=profile_key)
return self.host.plugins["XEP-0060"].createNode(jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key)
def change_node_options():
return self.host.plugins["XEP-0060"].setOptions(jid.userhostJID(), NS_MICROBLOG, jid.userhostJID(), _options, profile_key=profile_key)
create_node().addCallback(cb).addErrback(err_cb)

View file

@ -324,5 +324,5 @@ class ElementParser(object):
parser.DocumentEndEvent = onEnd
tmp = domish.Element(("", "s"))
tmp.addRawXml(s.replace('\n','').replace('\t',''))
parser.parse(tmp.toXml())
parser.parse(tmp.toXml().encode('utf-8'))
return self.result.firstChildElement()