<s> def get ( prop , choices = None ) : <EOL> prompt = prop . verbose_name <EOL> if not prompt : <EOL> prompt = prop . name <EOL> if choices : <EOL> if callable ( choices ) : <EOL> choices = choices ( ) <EOL> else : <EOL> choices = prop . get_choices ( ) <EOL> valid = False <EOL> while not valid : <EOL> if choices : <EOL> min = <NUM_LIT:1> <EOL> max = len ( choices ) <EOL> for i in range ( min , max + <NUM_LIT:1> ) : <EOL> value = choices [ i - <NUM_LIT:1> ] <EOL> if isinstance ( value , tuple ) : <EOL> value = value [ <NUM_LIT:0> ] <EOL> print '<STR_LIT>' % ( i , value ) <EOL> value = raw_input ( '<STR_LIT>' % ( prompt , min , max ) ) <EOL> try : <EOL> int_value = int ( value ) <EOL> value = choices [ int_value - <NUM_LIT:1> ] <EOL> if isinstance ( value , tuple ) : <EOL> value = value [ <NUM_LIT:1> ] <EOL> valid = True <EOL> except ValueError : <EOL> print '<STR_LIT>' % value <EOL> except IndexError : <EOL> print '<STR_LIT>' % ( min , max ) <EOL> else : <EOL> value = raw_input ( '<STR_LIT>' % prompt ) <EOL> try : <EOL> value = prop . validate ( value ) <EOL> if prop . empty ( value ) and prop . required : <EOL> print '<STR_LIT>' <EOL> else : <EOL> valid = True <EOL> except : <EOL> print '<STR_LIT>' % value <EOL> return value </s>
