From 7f373b50dba236b71183c221b0a01635660d96ad Mon Sep 17 00:00:00 2001
From: Maxime Bombar <bombar@crans.org>
Date: Sat, 6 Jun 2020 21:07:40 +0200
Subject: [PATCH] [server] str has no attribute 'decode'

---
 cpasswords/server.py | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/cpasswords/server.py b/cpasswords/server.py
index d8999f2..28b8d72 100755
--- a/cpasswords/server.py
+++ b/cpasswords/server.py
@@ -1,5 +1,4 @@
 #!python
-# -*- encoding: utf-8 -*-
 
 """
 Group password manager server
@@ -61,7 +60,6 @@ def validate(roles, mode='r'):
 
 def getpath(filename, backup=False):
     """Récupère le chemin du fichier ``filename``"""
-    filename = filename.encode('utf-8')
     return os.path.join(serverconfig.STORE, '%s.%s' % (filename, 'bak' if backup else 'json'))
 
 
@@ -69,7 +67,7 @@ def writefile(filename, contents):
     """Écrit le fichier avec les bons droits UNIX"""
     os.umask(0o077)
     f = open(filename, 'w')
-    f.write(contents.encode("utf-8"))
+    f.write(contents)
     f.close()
 
 
@@ -167,7 +165,7 @@ def listfiles():
     files = {}
     for filename in filenames:
         file_dict = json.loads(open(filename).read())
-        fname = filename[:-5].decode('utf-8')
+        fname = filename[:-5]
         files[fname] = file_dict["roles"]
     return files
 
@@ -182,7 +180,7 @@ def restorefiles():
     for filename in filenames:
         file_dict = json.loads(open(filename).read())
         if not ('-----BEGIN PGP MESSAGE-----' in file_dict["contents"]):
-            fname = filename[:-5].decode('utf-8')
+            fname = filename[:-5]
             with open(fname+'.bak') as f:
                 line = f.readline()
                 backup = ''
@@ -304,8 +302,7 @@ def backup(corps, fname, old):
     back = open(getpath(fname, backup=True), 'a')
     back.write(json.dumps(old))
     back.write('\n')
-    back.write((u'* %s: %s\n' %
-                (str(datetime.datetime.now()), corps)).encode("utf-8"))
+    back.write(f"* {datetime.datetime.now()}: {corps}\n")
     back.close()
 
 
@@ -360,8 +357,6 @@ def main():
         raise IOError("Ce serveur est read-only.")
 
     args = argv[2:]
-    # On veut des unicode partout
-    args = [s.decode('utf-8') for s in args]
     if command.stdin_input:
         args.append(json.loads(sys.stdin.read()))
     answer = command.decorated(*args)
-- 
GitLab