From 9ce9174d981803ddca90f4bdb57b981598721a98 Mon Sep 17 00:00:00 2001 From: piernov Date: Sat, 28 Feb 2015 22:29:30 +0100 Subject: Add some explicit string utf-8 encoding/decoding --- jm2l/models.py | 12 ++++++------ jm2l/upload.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jm2l/models.py b/jm2l/models.py index 0bc212c..54acdf3 100644 --- a/jm2l/models.py +++ b/jm2l/models.py @@ -161,14 +161,14 @@ class User(Base): @property def my_hash(self): m = hashlib.sha1() - m.update("Nobody inspects ") + m.update("Nobody inspects ".encode('utf-8')) if self.nom: - m.update(unicode.encode(self.nom,'utf8')) + m.update(self.nom.encode('utf-8')) if self.pseudo: - m.update(unicode.encode(self.pseudo,'utf8')) - if self.prenom: - m.update(unicode.encode(self.prenom,'utf8')) - m.update(" the spammish repetition") + m.update(self.pseudo.encode('utf-8')) + if self.prenom: + m.update(self.prenom.encode('utf-8')) + m.update(" the spammish repetition".encode('utf-8')) return m.hexdigest() @property diff --git a/jm2l/upload.py b/jm2l/upload.py index 22281b8..551eb27 100644 --- a/jm2l/upload.py +++ b/jm2l/upload.py @@ -134,7 +134,7 @@ class MediaUpload(MediaPath): def validate(self, result, filecontent): # let's say we don't trust the uploader - RealMime = magic.from_buffer( filecontent.read(1024), mime=True) + RealMime = magic.from_buffer( filecontent.read(1024), mime=True).decode('utf-8') filecontent.seek(0) if RealMime!=result['type']: result['error'] = 'l\'extension du fichier ne correspond pas à son contenu - ' -- cgit v1.2.3-70-g09d2