in java/com/google/cloud/deploymentmanager/autogen/templates/dm/sharedsupport/common/password.py [0:0]
def GeneratePassword(length=8, include_symbols=False):
"""Generates a random password."""
if length < MIN_LENGTH:
raise InputError('Password length must be at least %d' % MIN_LENGTH)
if include_symbols:
candidates = CANDIDATES_WITH_SYMBOLS
categories = CATEGORIES_WITH_SYMBOLS
else:
candidates = CANDIDATES_WITHOUT_SYMBOLS
categories = CATEGORIES_WITHOUT_SYMBOLS
# Generates up to the specified length minus the number of categories.
# Then inserts one character for each category, ensuring that the character
# satisfy the category if the generated string hasn't already.
generated = ([random.choice(ALPHABET)] +
[random.choice(candidates)
for _ in range(length - 1 - len(categories))])
for category in categories:
_InsertAndEnsureSatisfaction(generated, category, candidates)
return ''.join(generated)