comparison sat/plugins/plugin_misc_groupblog.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 0b7ce5daee9b
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
1 #!/usr/bin/env python2 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # SAT plugin for microbloging with roster access 4 # SAT plugin for microbloging with roster access
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
6 6
23 23
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 from twisted.internet import defer 25 from twisted.internet import defer
26 from sat.core import exceptions 26 from sat.core import exceptions
27 from wokkel import disco, data_form, iwokkel 27 from wokkel import disco, data_form, iwokkel
28 from zope.interface import implements 28 from zope.interface import implementer
29 29
30 try: 30 try:
31 from twisted.words.protocols.xmlstream import XMPPHandler 31 from twisted.words.protocols.xmlstream import XMPPHandler
32 except ImportError: 32 except ImportError:
33 from wokkel.subprotocols import XMPPHandler 33 from wokkel.subprotocols import XMPPHandler
76 yield self.host.checkFeatures(client, (NS_PUBSUB_GROUPBLOG,)) 76 yield self.host.checkFeatures(client, (NS_PUBSUB_GROUPBLOG,))
77 except exceptions.FeatureNotFound: 77 except exceptions.FeatureNotFound:
78 client.server_groupblog_available = False 78 client.server_groupblog_available = False
79 log.warning( 79 log.warning(
80 _( 80 _(
81 u"Server is not able to manage item-access pubsub, we can't use group blog" 81 "Server is not able to manage item-access pubsub, we can't use group blog"
82 ) 82 )
83 ) 83 )
84 else: 84 else:
85 client.server_groupblog_available = True 85 client.server_groupblog_available = True
86 log.info(_(u"Server can manage group blogs")) 86 log.info(_("Server can manage group blogs"))
87 87
88 def getFeatures(self, profile): 88 def getFeatures(self, profile):
89 try: 89 try:
90 client = self.host.getClient(profile) 90 client = self.host.getClient(profile)
91 except exceptions.ProfileNotSetError: 91 except exceptions.ProfileNotSetError:
117 """ 117 """
118 groups = mb_data.get('groups', []) 118 groups = mb_data.get('groups', [])
119 if not groups: 119 if not groups:
120 return 120 return
121 if not client.server_groupblog_available: 121 if not client.server_groupblog_available:
122 raise exceptions.CancelError(u"GroupBlog is not available") 122 raise exceptions.CancelError("GroupBlog is not available")
123 log.debug(u"This entry use group blog") 123 log.debug("This entry use group blog")
124 form = data_form.Form("submit", formNamespace=NS_PUBSUB_ITEM_CONFIG) 124 form = data_form.Form("submit", formNamespace=NS_PUBSUB_ITEM_CONFIG)
125 access = data_form.Field( 125 access = data_form.Field(
126 None, self._p.OPT_ACCESS_MODEL, value=self._p.ACCESS_PUBLISHER_ROSTER 126 None, self._p.OPT_ACCESS_MODEL, value=self._p.ACCESS_PUBLISHER_ROSTER
127 ) 127 )
128 allowed = data_form.Field(None, self._p.OPT_ROSTER_GROUPS_ALLOWED, values=groups) 128 allowed = data_form.Field(None, self._p.OPT_ROSTER_GROUPS_ALLOWED, values=groups)
137 """ 137 """
138 if "group" in mb_data: 138 if "group" in mb_data:
139 options[self._p.OPT_ACCESS_MODEL] = self._p.ACCESS_PUBLISHER_ROSTER 139 options[self._p.OPT_ACCESS_MODEL] = self._p.ACCESS_PUBLISHER_ROSTER
140 options[self._p.OPT_ROSTER_GROUPS_ALLOWED] = mb_data['groups'] 140 options[self._p.OPT_ROSTER_GROUPS_ALLOWED] = mb_data['groups']
141 141
142 @implementer(iwokkel.IDisco)
142 class GroupBlog_handler(XMPPHandler): 143 class GroupBlog_handler(XMPPHandler):
143 implements(iwokkel.IDisco)
144 144
145 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): 145 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
146 return [disco.DiscoFeature(NS_GROUPBLOG)] 146 return [disco.DiscoFeature(NS_GROUPBLOG)]
147 147
148 def getDiscoItems(self, requestor, target, nodeIdentifier=""): 148 def getDiscoItems(self, requestor, target, nodeIdentifier=""):