# HG changeset patch # User Goffi # Date 1301158279 -3600 # Node ID e04ccf122bb64cc3f003d27bbcc727d9ec25fc70 # Parent 2b52a5da09788821afee9fecd0465010f08df3e7 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 diff -r 2b52a5da0978 -r e04ccf122bb6 frontends/src/bridge/DBus.py --- a/frontends/src/bridge/DBus.py Thu Mar 24 21:15:26 2011 +0100 +++ b/frontends/src/bridge/DBus.py Sat Mar 26 17:51:19 2011 +0100 @@ -217,3 +217,6 @@ 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) diff -r 2b52a5da0978 -r e04ccf122bb6 src/bridge/bridge_constructor/dbus_frontend_template.py --- a/src/bridge/bridge_constructor/dbus_frontend_template.py Thu Mar 24 21:15:26 2011 +0100 +++ b/src/bridge/bridge_constructor/dbus_frontend_template.py Sat Mar 26 17:51:19 2011 +0100 @@ -99,3 +99,6 @@ 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) + diff -r 2b52a5da0978 -r e04ccf122bb6 src/plugins/plugin_xep_0277.py --- a/src/plugins/plugin_xep_0277.py Thu Mar 24 21:15:26 2011 +0100 +++ b/src/plugins/plugin_xep_0277.py Sat Mar 26 17:51:19 2011 +0100 @@ -117,15 +117,16 @@ 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 @@ 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 @@ #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) diff -r 2b52a5da0978 -r e04ccf122bb6 src/tools/xml_tools.py --- a/src/tools/xml_tools.py Thu Mar 24 21:15:26 2011 +0100 +++ b/src/tools/xml_tools.py Sat Mar 26 17:51:19 2011 +0100 @@ -324,5 +324,5 @@ 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()