Strict typing
This commit is contained in:
parent
206e364451
commit
9833101e37
37
bin/genpw
37
bin/genpw
|
@ -1,37 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
"""Module to generate a random string
|
||||
"""
|
||||
Module to generate a random string
|
||||
|
||||
Attributes:
|
||||
LENGTH (int): Defaults to a length of 16
|
||||
"""
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
import os
|
||||
import argparse
|
||||
import base64
|
||||
import os
|
||||
import sys
|
||||
|
||||
LENGTH = 16
|
||||
|
||||
|
||||
def generate(length):
|
||||
def generate(length: int) -> str:
|
||||
"""Simple function to call OpenSSL
|
||||
|
||||
Args:
|
||||
length (int): length of string to return
|
||||
"""
|
||||
return base64.encodestring(os.urandom(256))[:length]
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function to call
|
||||
"""
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('-n', dest='length', default=LENGTH, type=int)
|
||||
opts, _ = parser.parse_args()
|
||||
|
||||
sys.stdout.write(generate(opts.length))
|
||||
return base64.encodebytes(os.urandom(256)).decode()[:length]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
sys.exit(0)
|
||||
|
||||
def main() -> int:
|
||||
"""Main function to call"""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-n', dest='length', default=LENGTH, type=int)
|
||||
args = parser.parse_args()
|
||||
|
||||
sys.stdout.write(generate(args.length))
|
||||
|
||||
return 0
|
||||
|
||||
sys.exit(main())
|
||||
|
|
Loading…
Reference in a new issue