#NEWLINE# def __new__( mcs , name , bases , attrs ) : #NEWLINE# #INDENT# '\n        This metaclass adds four attributes to host classes: mcs._fields,\n        mcs._serializables, mcs._validator_functions, and mcs._options.\n\n        This function creates those attributes like this:\n\n        ``mcs._fields`` is list of fields that are Schematics types\n        ``mcs._serializables`` is a list of ``Serializable`` objects\n        ``mcs._validator_functions`` are class-level validation functions\n        ``mcs._options`` is the end result of parsing the ``Options`` class\n        ' #NEWLINE# fields = OrderedDict ( ) #NEWLINE# serializables = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# validator_functions = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for base in reversed ( bases ) : #NEWLINE# #INDENT# if hasattr ( base , '_fields' ) : #NEWLINE# #INDENT# fields . update ( deepcopy ( base . _fields ) ) #NEWLINE# #UNINDENT# if hasattr ( base , '_serializables' ) : #NEWLINE# #INDENT# serializables . update ( deepcopy ( base . _serializables ) ) #NEWLINE# #UNINDENT# if hasattr ( base , '_validator_functions' ) : #NEWLINE# #INDENT# validator_functions . update ( base . _validator_functions ) #NEWLINE# #UNINDENT# #UNINDENT# for ( key , value ) in iteritems ( attrs ) : #NEWLINE# #INDENT# if ( key . startswith ( 'validate_' ) and callable ( value ) ) : #NEWLINE# #INDENT# validator_functions [ key [ 9 : ] ] = prepare_validator ( value , 4 ) #NEWLINE# #UNINDENT# if isinstance ( value , BaseType ) : #NEWLINE# #INDENT# fields [ key ] = value #NEWLINE# #UNINDENT# if isinstance ( value , Serializable ) : #NEWLINE# #INDENT# serializables [ key ] = value #NEWLINE# #UNINDENT# #UNINDENT# options = mcs . _read_options ( name , bases , attrs ) #NEWLINE# fields . sort ( key = ( lambda i : i [ 1 ] . _position_hint ) ) #NEWLINE# for ( key , field ) in iteritems ( fields ) : #NEWLINE# #INDENT# attrs [ key ] = FieldDescriptor ( key ) #NEWLINE# #UNINDENT# for ( key , serializable ) in iteritems ( serializables ) : #NEWLINE# #INDENT# attrs [ key ] = serializable #NEWLINE# #UNINDENT# attrs [ '_fields' ] = fields #NEWLINE# attrs [ '_field_list' ] = list ( fields . items ( ) ) #NEWLINE# attrs [ '_serializables' ] = serializables #NEWLINE# attrs [ '_validator_functions' ] = validator_functions #NEWLINE# attrs [ '_options' ] = options #NEWLINE# klass = type . __new__ ( mcs , name , bases , attrs ) #NEWLINE# klass = str_compat ( klass ) #NEWLINE# klass . _subclasses = [ ] #NEWLINE# for base in klass . __mro__ [ 1 : ] : #NEWLINE# #INDENT# if isinstance ( base , ModelMeta ) : #NEWLINE# #INDENT# base . _subclasses . append ( klass ) #NEWLINE# #UNINDENT# #UNINDENT# for ( field_name , field ) in fields . items ( ) : #NEWLINE# #INDENT# field . _setup ( field_name , klass ) #NEWLINE# #UNINDENT# for ( field_name , field ) in serializables . items ( ) : #NEWLINE# #INDENT# field . _setup ( field_name , klass ) #NEWLINE# #UNINDENT# klass . _valid_input_keys = ( set ( itertools . chain ( * ( field . get_input_keys ( ) for field in fields . values ( ) ) ) ) | set ( serializables ) ) #NEWLINE# return klass