<s> import getpass <EOL> from optparse import make_option <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from django . contrib . auth . models import User <EOL> from django . db import DEFAULT_DB_ALIAS <EOL> class Command ( BaseCommand ) : <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT>' , <EOL> default = DEFAULT_DB_ALIAS , help = '<STR_LIT>' ) , <EOL> ) <EOL> help = "<STR_LIT>" <EOL> requires_model_validation = False <EOL> def _get_pass ( self , prompt = "<STR_LIT>" ) : <EOL> p = getpass . getpass ( prompt = prompt ) <EOL> if not p : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> return p <EOL> def handle ( self , * args , ** options ) : <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> if args : <EOL> username , = args <EOL> else : <EOL> username = getpass . getuser ( ) <EOL> try : <EOL> u = User . objects . using ( options . get ( '<STR_LIT>' ) ) . get ( username = username ) <EOL> except User . DoesNotExist : <EOL> raise CommandError ( "<STR_LIT>" % username ) <EOL> self . stdout . write ( "<STR_LIT>" % u . username ) <EOL> MAX_TRIES = <NUM_LIT:3> <EOL> count = <NUM_LIT:0> <EOL> p1 , p2 = <NUM_LIT:1> , <NUM_LIT:2> <EOL> while p1 != p2 and count < MAX_TRIES : <EOL> p1 = self . _get_pass ( ) <EOL> p2 = self . _get_pass ( "<STR_LIT>" ) <EOL> if p1 != p2 : <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> count = count + <NUM_LIT:1> <EOL> if count == MAX_TRIES : <EOL> raise CommandError ( "<STR_LIT>" % ( username , count ) ) <EOL> u . set_password ( p1 ) <EOL> u . save ( ) <EOL> return "<STR_LIT>" % u . username </s>
