<s> """<STR_LIT>""" <EOL> import getpass <EOL> import re <EOL> import sys <EOL> from optparse import make_option <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth . management import get_default_username <EOL> from django . core import exceptions <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from django . db import DEFAULT_DB_ALIAS <EOL> from django . utils . translation import ugettext as _ <EOL> RE_VALID_USERNAME = re . compile ( '<STR_LIT>' ) <EOL> EMAIL_RE = re . compile ( <EOL> r"<STR_LIT>" <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' , re . IGNORECASE ) <EOL> def is_valid_email ( value ) : <EOL> if not EMAIL_RE . search ( value ) : <EOL> raise exceptions . ValidationError ( _ ( '<STR_LIT>' ) ) <EOL> class Command ( BaseCommand ) : <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , dest = '<STR_LIT:username>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , dest = '<STR_LIT:email>' , default = None , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT>' , dest = '<STR_LIT>' , default = True , <EOL> help = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) , <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> def handle ( self , * args , ** options ) : <EOL> username = options . get ( '<STR_LIT:username>' , None ) <EOL> email = options . get ( '<STR_LIT:email>' , None ) <EOL> interactive = options . get ( '<STR_LIT>' ) <EOL> verbosity = int ( options . get ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> database = options . get ( '<STR_LIT>' ) <EOL> if not interactive : <EOL> if not username or not email : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> if not RE_VALID_USERNAME . match ( username ) : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> try : <EOL> is_valid_email ( email ) <EOL> except exceptions . ValidationError : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> password = None <EOL> if interactive : <EOL> default_username = get_default_username ( ) <EOL> try : <EOL> while <NUM_LIT:1> : <EOL> if not username : <EOL> input_msg = '<STR_LIT>' <EOL> if default_username : <EOL> input_msg += '<STR_LIT>' % default_username <EOL> username = raw_input ( input_msg + '<STR_LIT>' ) <EOL> if default_username and username == '<STR_LIT>' : <EOL> username = default_username <EOL> if not RE_VALID_USERNAME . match ( username ) : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> username = None <EOL> continue <EOL> try : <EOL> User . objects . using ( database ) . get ( username = username ) <EOL> except User . DoesNotExist : <EOL> break <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> username = None <EOL> while <NUM_LIT:1> : <EOL> if not email : <EOL> email = raw_input ( '<STR_LIT>' ) <EOL> try : <EOL> is_valid_email ( email ) <EOL> except exceptions . ValidationError : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> email = None <EOL> else : <EOL> break <EOL> while <NUM_LIT:1> : <EOL> if not password : <EOL> password = getpass . getpass ( ) <EOL> password2 = getpass . getpass ( '<STR_LIT>' ) <EOL> if password != password2 : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> password = None <EOL> continue <EOL> if password . strip ( ) == '<STR_LIT>' : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> password = None <EOL> continue <EOL> break <EOL> except KeyboardInterrupt : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> User . objects . db_manager ( database ) . create_superuser ( username , email , password ) <EOL> if verbosity >= <NUM_LIT:1> : <EOL> self . stdout . write ( "<STR_LIT>" ) </s>
