comparison 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
comparison
equal deleted inserted replaced
249:f161448d673e 250:48f89d312309
164 if len(pwd) < opts.req_length: 164 if len(pwd) < opts.req_length:
165 raise AssertionError("internal length mismatch") 165 raise AssertionError("internal length mismatch")
166 else: 166 else:
167 if len(pwd) != opts.req_length: 167 if len(pwd) != opts.req_length:
168 raise AssertionError("internal length mismatch") 168 raise AssertionError("internal length mismatch")
169 if not PY2: 169 if PY2:
170 pwd = pwd.decode("iso-8859-15") 170 print(pwd)
171 print(pwd) 171 sys.stdout.flush()
172 else:
173 sys.stdout.buffer.write(pwd)
174 sys.stdout.buffer.write(b'\n')
175 sys.stdout.buffer.flush()
172 176
173 177
174 def gen_from_repertoire(length, repertoire): 178 def gen_from_repertoire(length, repertoire):
175 """Select `length` characters randomly from given character repertoire 179 """Select `length` characters randomly from given character repertoire
176 `repertoire`. 180 `repertoire`.