diff sat/plugins/plugin_xep_0054.py @ 3185:554b3b632378

memory (cache): purge + pathlib: - cache is now purged on backend startup (every file which has passed EOL will be deleted) - use of pathlib, getPath now returns a Path
author Goffi <goffi@goffi.org>
date Wed, 26 Feb 2020 15:54:43 +0100
parents 559a625a236b
children 5afd7416ca2d
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0054.py	Wed Feb 26 15:54:34 2020 +0100
+++ b/sat/plugins/plugin_xep_0054.py	Wed Feb 26 15:54:43 2020 +0100
@@ -18,25 +18,23 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from sat.core.i18n import _
-from sat.core.constants import Const as C
-from sat.core.log import getLogger
-
-log = getLogger(__name__)
+import mimetypes
+from base64 import b64decode, b64encode
+from hashlib import sha1
+from pathlib import Path
+from zope.interface import implementer
 from twisted.internet import threads, defer
 from twisted.words.protocols.jabber import jid, error
 from twisted.words.xish import domish
 from twisted.python.failure import Failure
-
-from zope.interface import implementer
-
 from wokkel import disco, iwokkel
+from sat.core import exceptions
+from sat.core.i18n import _
+from sat.core.constants import Const as C
+from sat.core.log import getLogger
+from sat.memory import persistent
 
-from base64 import b64decode, b64encode
-from hashlib import sha1
-from sat.core import exceptions
-from sat.memory import persistent
-import mimetypes
+log = getLogger(__name__)
 
 try:
     from PIL import Image
@@ -406,8 +404,9 @@
     def _getAvatar(self, entity, cache_only, hash_only, profile):
         client = self.host.getClient(profile)
         d = self.getAvatar(client, jid.JID(entity), cache_only, hash_only)
+        # we need to convert the Path to string
+        d.addCallback(str)
         d.addErrback(lambda __: "")
-
         return d
 
     def getAvatar(self, client, entity, cache_only=True, hash_only=False):
@@ -436,7 +435,7 @@
                     raise KeyError
             else:
                 # avatar has already been checked but it is not set
-                full_path = ""
+                full_path = Path("")
         except KeyError:
             # avatar is not in cache
             if cache_only: