#NEWLINE# @ classmethod #NEWLINE# def forTypes( klass , key , classes , description , extraValidator = None ) : #NEWLINE# #INDENT# '\n        Create a L{Field} that must be an instance of a given set of types.\n\n        @param key: The name of the field, the key which refers to it,\n            e.g. C{"path"}.\n\n        @ivar classes: A C{list} of allowed Python classes for this field\'s\n            values. Supported classes are C{unicode}, C{int}, C{float},\n            C{bool}, C{long}, C{list} and C{dict} and C{None} (the latter\n            isn\'t strictly a class, but will be converted appropriately).\n\n        @param description: A description of what this field contains.\n        @type description: C{unicode}\n\n        @param extraValidator: See description in L{Field.__init__}.\n\n        @return: A L{Field}.\n        ' #NEWLINE# fixedClasses = [ ] #NEWLINE# for k in classes : #NEWLINE# #INDENT# if ( k is None ) : #NEWLINE# #INDENT# k = type ( None ) #NEWLINE# #UNINDENT# if ( k not in _JSON_TYPES ) : #NEWLINE# #INDENT# raise TypeError ( ( '%s is not JSON-encodeable' % ( k , ) ) ) #NEWLINE# #UNINDENT# fixedClasses . append ( k ) #NEWLINE# #UNINDENT# fixedClasses = tuple ( fixedClasses ) #NEWLINE# def validate( value ) : #NEWLINE# #INDENT# if ( not isinstance ( value , fixedClasses ) ) : #NEWLINE# #INDENT# raise ValidationError ( value , ( 'Field %r requires type to be one of %s' % ( key , classes ) ) ) #NEWLINE# #UNINDENT# if ( extraValidator is not None ) : #NEWLINE# #INDENT# extraValidator ( value ) #NEWLINE# #UNINDENT# #UNINDENT# return klass ( key , ( lambda v : v ) , description , extraValidator = validate )