diff sat_pubsub/privilege.py @ 414:ccb2a22ea0fc

Python 3 port: /!\ Python 3.6+ is now needed to use SàT Pubsub /!\ instability may occur and features may not be working anymore, this will improve with time The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs for details). Python minimal version has been updated in setup.py
author Goffi <goffi@goffi.org>
date Fri, 16 Aug 2019 12:53:33 +0200
parents c56a728412f1
children 96342e7e9f5d
line wrap: on
line diff
--- a/sat_pubsub/privilege.py	Fri Aug 16 12:48:34 2019 +0200
+++ b/sat_pubsub/privilege.py	Fri Aug 16 12:53:33 2019 +0200
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 #-*- coding: utf-8 -*-
 #
 # Copyright (c) 2015 Jérôme Poisson
@@ -92,18 +92,18 @@
 
         self._permissions will be updated according to advertised privileged
         """
-        privilege_elt = message.elements(PRIV_ENT_NS, 'privilege').next()
+        privilege_elt = next(message.elements(PRIV_ENT_NS, 'privilege'))
         for perm_elt in privilege_elt.elements(PRIV_ENT_NS):
             try:
                 if perm_elt.name != 'perm':
-                    raise InvalidStanza(u'unexpected element {}'.format(perm_elt.name))
+                    raise InvalidStanza('unexpected element {}'.format(perm_elt.name))
                 perm_access = perm_elt['access']
                 perm_type = perm_elt['type']
                 try:
                     if perm_type not in TO_CHECK[perm_access]:
-                        raise InvalidStanza(u'bad type [{}] for permission {}'.format(perm_type, perm_access))
+                        raise InvalidStanza('bad type [{}] for permission {}'.format(perm_type, perm_access))
                 except KeyError:
-                    raise InvalidStanza(u'bad permission [{}]'.format(perm_access))
+                    raise InvalidStanza('bad permission [{}]'.format(perm_access))
             except InvalidStanza as e:
                 log.msg("Invalid stanza received ({}), setting permission to none".format(e))
                 for perm in self._permissions:
@@ -238,7 +238,7 @@
             self.roster_cache[from_jid_bare] = {'timestamp': timestamp,
                                                 'roster': roster,
                                                 }
-            for roster_jid, roster_item in roster.iteritems():
+            for roster_jid, roster_item in roster.items():
                 if roster_item.subscriptionFrom:
                     self.presence_map.setdefault(roster_jid, set()).add(from_jid_bare)
 
@@ -296,7 +296,7 @@
         """
         auto_subscribers = []
         roster = yield self.getRoster(recipient)
-        for roster_jid, roster_item in roster.iteritems():
+        for roster_jid, roster_item in roster.items():
             if roster_jid in explicit_subscribers:
                 continue
             if roster_item.subscriptionFrom:
@@ -304,7 +304,7 @@
                     online_resources = self.caps_map[roster_jid]
                 except KeyError:
                     continue
-                for res, disco_tuple in online_resources.iteritems():
+                for res, disco_tuple in online_resources.items():
                      notify = self.hash_map[disco_tuple]['notify']
                      if nodeIdentifier in notify:
                          full_jid = jid.JID(tuple=(roster_jid.user, roster_jid.host, res))