Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 1902:085f29c20f7e
plugin XEP-0277: removed mbGetAtom which has not reason to be in the backend, as it is highly dependant of (web) frontend elements. The code will be moved to Libervia:
/!\ this break Libervia static blog temporarily, the time to commit the changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 09 Mar 2016 14:33:54 +0100 |
parents | fc6eeacf31bc |
children | ee1125fffba8 |
comparison
equal
deleted
inserted
replaced
1901:faa8427dd032 | 1902:085f29c20f7e |
---|---|
15 # GNU Affero General Public License for more details. | 15 # GNU Affero General Public License for more details. |
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _, D_ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | 23 log = getLogger(__name__) |
24 from twisted.words.protocols.jabber import jid, error | 24 from twisted.words.protocols.jabber import jid, error |
25 from twisted.words.xish import domish | 25 from twisted.words.xish import domish |
37 except ImportError: | 37 except ImportError: |
38 raise exceptions.MissingModule(u"Missing module pyfeed, please download/install it from http://home.avvanta.com/~steveha/pyfeed.html") | 38 raise exceptions.MissingModule(u"Missing module pyfeed, please download/install it from http://home.avvanta.com/~steveha/pyfeed.html") |
39 import uuid | 39 import uuid |
40 import time | 40 import time |
41 import urlparse | 41 import urlparse |
42 import urllib | |
43 | 42 |
44 NS_MICROBLOG = 'urn:xmpp:microblog:0' | 43 NS_MICROBLOG = 'urn:xmpp:microblog:0' |
45 NS_ATOM = 'http://www.w3.org/2005/Atom' | 44 NS_ATOM = 'http://www.w3.org/2005/Atom' |
46 NS_PUBSUB_EVENT = "{}{}".format(pubsub.NS_PUBSUB, "#event") | 45 NS_PUBSUB_EVENT = "{}{}".format(pubsub.NS_PUBSUB, "#event") |
47 NS_COMMENT_PREFIX = '{}:comments/'.format(NS_MICROBLOG) | 46 NS_COMMENT_PREFIX = '{}:comments/'.format(NS_MICROBLOG) |
100 method=self._mbGetFromMany) | 99 method=self._mbGetFromMany) |
101 host.bridge.addMethod("mbGetFromManyWithCommentsRTResult", ".plugin", in_sign='ss', out_sign='(ua(sssa(a{ss}a(sssaa{ss}a{ss}))a{ss}))', | 100 host.bridge.addMethod("mbGetFromManyWithCommentsRTResult", ".plugin", in_sign='ss', out_sign='(ua(sssa(a{ss}a(sssaa{ss}a{ss}))a{ss}))', |
102 method=self._mbGetFromManyWithCommentsRTResult, async=True) | 101 method=self._mbGetFromManyWithCommentsRTResult, async=True) |
103 host.bridge.addMethod("mbGetFromManyWithComments", ".plugin", in_sign='sasiia{ss}a{ss}s', out_sign='s', | 102 host.bridge.addMethod("mbGetFromManyWithComments", ".plugin", in_sign='sasiia{ss}a{ss}s', out_sign='s', |
104 method=self._mbGetFromManyWithComments) | 103 method=self._mbGetFromManyWithComments) |
105 host.bridge.addMethod("mbGetAtom", ".plugin", in_sign='ssiasa{ss}s', out_sign='s', | |
106 method=self._mbGetAtom, async=True) | |
107 | 104 |
108 def _checkFeaturesCb(self, available): | 105 def _checkFeaturesCb(self, available): |
109 return {'available': C.BOOL_TRUE} | 106 return {'available': C.BOOL_TRUE} |
110 | 107 |
111 def _checkFeaturesEb(self, fail): | 108 def _checkFeaturesEb(self, fail): |
911 d.addCallback(getComments) | 908 d.addCallback(getComments) |
912 d.addCallback(lambda items_comments_data: ('', items_comments_data)) | 909 d.addCallback(lambda items_comments_data: ('', items_comments_data)) |
913 d.addErrback(lambda failure: (unicode(failure.value), ([],{}))) | 910 d.addErrback(lambda failure: (unicode(failure.value), ([],{}))) |
914 | 911 |
915 return self.rt_sessions.newSession(deferreds, client.profile) | 912 return self.rt_sessions.newSession(deferreds, client.profile) |
916 | |
917 # atom feed | |
918 | |
919 def _mbGetAtom(self, service_jid_s, node="", max_items=10, item_ids=None, extra_dict=None, profile_key=C.PROF_KEY_NONE): | |
920 """Get the atom feed of the last published microblogs | |
921 | |
922 @param service_jid(jid.JID): jid of the publisher | |
923 @param node(unicode, None): node to get (or microblog node if None) | |
924 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit | |
925 @param item_ids (list[unicode]): list of item IDs | |
926 @param rsm_request (rsm.RSMRequest): RSM request data | |
927 @param extra (dict): extra data | |
928 @param profile_key: %(doc_profile_key)s | |
929 @return: a deferred unicode (atom XML feed) | |
930 """ | |
931 max_items = None if max_items == C.NO_LIMIT else max_items | |
932 extra = self._p.parseExtra(extra_dict) | |
933 return self.mbGetAtom(jid.JID(service_jid_s), node or None, max_items or None, item_ids, extra.rsm_request, extra.extra, profile_key) | |
934 | |
935 @defer.inlineCallbacks | |
936 def mbGetAtom(self, service_jid, node=None, max_items=None, item_ids=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): | |
937 """Get the atom feed of the last published microblogs | |
938 | |
939 @param service_jid(jid.JID): jid of the publisher | |
940 @param node(unicode, None): node to get (or microblog node if None) | |
941 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit | |
942 @param item_ids (list[unicode]): list of item IDs | |
943 @param rsm_request (rsm.RSMRequest): RSM request data | |
944 @param extra (dict): extra data | |
945 @param profile_key: %(doc_profile_key)s | |
946 | |
947 @return: a deferred couple with the list of items and metadatas. | |
948 """ | |
949 if node is None: | |
950 node = NS_MICROBLOG | |
951 | |
952 feed_elt = domish.Element((NS_ATOM, 'feed')) | |
953 title = D_(u"{user}'s blogposts").format(user=service_jid.user) | |
954 feed_elt.addElement('title', content=title) | |
955 link_feed_elt = feed_elt.addElement('link') | |
956 link_feed_elt['href'] = 'http://{host}/blog/{user}/atom.xml'.format( | |
957 host=urllib.quote(service_jid.host.encode('utf-8'),''), | |
958 user=urllib.quote(service_jid.user.encode('utf-8'),'')) | |
959 link_feed_elt['rel'] = 'self' | |
960 link_blog_elt = feed_elt.addElement('link') | |
961 link_blog_elt['href'] = 'http://{host}/blog/{user}'.format( | |
962 host=urllib.quote(service_jid.host.encode('utf-8'),''), | |
963 user=urllib.quote(service_jid.user.encode('utf-8'),'')) | |
964 feed_elt.addElement('id', content=node) | |
965 feed_elt.addElement('updated', rfc3339.timestamp_from_tf(rfc3339.tf_utc())) | |
966 | |
967 # FIXME: no cleaning is done here | |
968 # FIXME: no check is done neither, we have to be sure that we get microblogs | |
969 items, metadata = yield self._p.getItems(service_jid, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=profile_key) | |
970 | |
971 for item in items: | |
972 entry_elt = item.elements(NS_ATOM, 'entry').next() | |
973 feed_elt.addChild(entry_elt) | |
974 | |
975 defer.returnValue(u'<?xml version="1.0" encoding="utf-8"?>'+feed_elt.toXml()) |