diff cutils/genpwd.py @ 250:48f89d312309

genpwd: use binary output on Python3 to prevent double encoding
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 08 Feb 2025 13:31:19 +0100
parents f161448d673e
children 14bb7423445d
line wrap: on
line diff
--- a/cutils/genpwd.py	Sat Feb 08 13:26:39 2025 +0100
+++ b/cutils/genpwd.py	Sat Feb 08 13:31:19 2025 +0100
@@ -166,9 +166,13 @@
     else:
         if len(pwd) != opts.req_length:
             raise AssertionError("internal length mismatch")
-    if not PY2:
-        pwd = pwd.decode("iso-8859-15")
-    print(pwd)
+    if PY2:
+        print(pwd)
+        sys.stdout.flush()
+    else:
+        sys.stdout.buffer.write(pwd)
+        sys.stdout.buffer.write(b'\n')
+        sys.stdout.buffer.flush()
 
 
 def gen_from_repertoire(length, repertoire):