#NEWLINE# def secure_password( length = 20 , use_random = True ) : #NEWLINE# #INDENT# '\n    Generate a secure password.\n    ' #NEWLINE# length = int ( length ) #NEWLINE# pw = '' #NEWLINE# while ( len ( pw ) < length ) : #NEWLINE# #INDENT# if ( HAS_RANDOM and use_random ) : #NEWLINE# #INDENT# pw += re . sub ( '\\W' , '' , Crypto . Random . get_random_bytes ( 1 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pw += random . SystemRandom ( ) . choice ( ( string . ascii_letters + string . digits ) ) #NEWLINE# #UNINDENT# #UNINDENT# return pw