username

gratipay.utils.username.gen_random_usernames()[source]

Yield random 12-hex-digit unicodes.

gratipay.utils.username.safely_reserve_a_username(cursor, gen_usernames=<function gen_random_usernames>, reserve=<function insert_into_participants>)[source]

Safely reserve a username.

Parameters:
  • cursor – a psycopg2.cursor managed as a postgres transaction
  • gen_usernames – a generator of usernames to try
  • reserve – a function that takes the cursor and does the SQL stuff
Database:

one INSERT on average

Returns:

a 12-hex-digit unicode

Raises:

FailedToReserveUsername if no acceptable username is found within 100 attempts, or RanOutOfUsernameAttempts if the username generator runs out first

The returned value is guaranteed to have been reserved in the database.