Strict typing

This commit is contained in:
Scott Wallace 2021-12-11 18:22:49 +00:00
parent 206e364451
commit 9833101e37
Signed by: scott
GPG key ID: AA742FDC5AFE2A72

View file

@ -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())