#NEWLINE# def __new__( cls , name , bases , attrs ) : #NEWLINE# #INDENT# if ( not bases ) : #NEWLINE# #INDENT# return super ( BaseModel , cls ) . __new__ ( cls , name , bases , attrs ) #NEWLINE# #UNINDENT# ignore = set ( ) #NEWLINE# primary_key = None #NEWLINE# for ( key , value ) in attrs . items ( ) : #NEWLINE# #INDENT# if ( isinstance ( value , Field ) and value . _primary_key ) : #NEWLINE# #INDENT# primary_key = ( key , value ) #NEWLINE# #UNINDENT# #UNINDENT# for base in bases : #NEWLINE# #INDENT# for ( key , value ) in base . __dict__ . items ( ) : #NEWLINE# #INDENT# if ( key in attrs ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if isinstance ( value , Field ) : #NEWLINE# #INDENT# if ( value . _primary_key and primary_key ) : #NEWLINE# #INDENT# ignore . add ( key ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if value . _primary_key : #NEWLINE# #INDENT# primary_key = ( key , value ) #NEWLINE# #UNINDENT# attrs [ key ] = deepcopy ( value ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( not primary_key ) : #NEWLINE# #INDENT# attrs [ '_id' ] = AutoIncrementField ( ) #NEWLINE# primary_key = ( '_id' , attrs [ '_id' ] ) #NEWLINE# #UNINDENT# model_class = super ( BaseModel , cls ) . __new__ ( cls , name , bases , attrs ) #NEWLINE# model_class . _data = None #NEWLINE# defaults = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# fields = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# indexes = [ ] #NEWLINE# for ( key , value ) in model_class . __dict__ . items ( ) : #NEWLINE# #INDENT# if ( isinstance ( value , Field ) and ( key not in ignore ) ) : #NEWLINE# #INDENT# value . add_to_class ( model_class , key ) #NEWLINE# if value . _index : #NEWLINE# #INDENT# indexes . append ( value ) #NEWLINE# #UNINDENT# fields [ key ] = value #NEWLINE# if ( value . _default is not None ) : #NEWLINE# #INDENT# defaults [ key ] = value . _default #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# model_class . _defaults = defaults #NEWLINE# model_class . _fields = fields #NEWLINE# model_class . _indexes = indexes #NEWLINE# model_class . _primary_key = primary_key [ 0 ] #NEWLINE# model_class . _query = Query ( model_class ) #NEWLINE# return model_class