#NEWLINE# def validate_answer( answer , question ) : #NEWLINE# #INDENT# '\n    Return True if answer is a valid response to question, False if not.\n    (question is expected to be the XFormsResponse object for the question)\n    ' #NEWLINE# if ( question . event . datatype == 'select' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# assert ( answer is not None ) #NEWLINE# answer = int ( answer ) #NEWLINE# assert ( ( question >= 1 ) and ( answer <= len ( question . event . choices ) ) ) #NEWLINE# return True #NEWLINE# #UNINDENT# except ( ValueError , AssertionError ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# assert ( answer is not None ) #NEWLINE# if isinstance ( answer , basestring ) : #NEWLINE# #INDENT# assert ( len ( answer . strip ( ) ) > 0 ) #NEWLINE# #UNINDENT# return True #NEWLINE# #UNINDENT# except AssertionError : #NEWLINE# #INDENT# return False