#NEWLINE# def convert( self , model , mapper , prop , field_args , db_session = None ) : #NEWLINE# #INDENT# if ( ( not hasattr ( prop , 'columns' ) ) and ( not hasattr ( prop , 'direction' ) ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not hasattr ( prop , 'direction' ) ) and ( len ( prop . columns ) != 1 ) ) : #NEWLINE# #INDENT# raise TypeError ( ( 'Do not know how to convert multiple-column ' + 'properties currently' ) ) #NEWLINE# #UNINDENT# #UNINDENT# kwargs = { #NEWLINE# #INDENT# 'validators' : [ ] , #NEWLINE# 'filters' : [ ] , #NEWLINE# 'default' : None , #NEWLINE# #UNINDENT# } #NEWLINE# converter = None #NEWLINE# column = None #NEWLINE# types = None #NEWLINE# if ( not hasattr ( prop , 'direction' ) ) : #NEWLINE# #INDENT# column = prop . columns [ 0 ] #NEWLINE# default = getattr ( column , 'default' , None ) #NEWLINE# if ( default is not None ) : #NEWLINE# #INDENT# callable_default = getattr ( default , 'arg' , None ) #NEWLINE# if ( callable_default is not None ) : #NEWLINE# #INDENT# default = ( callable_default ( None ) if callable ( callable_default ) else callable_default ) #NEWLINE# #UNINDENT# #UNINDENT# kwargs [ 'default' ] = converter #NEWLINE# if column . nullable : #NEWLINE# #INDENT# kwargs [ 'validators' ] . append ( validators . Optional ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# kwargs [ 'validators' ] . append ( validators . Required ( ) ) #NEWLINE# #UNINDENT# if ( db_session and column . unique ) : #NEWLINE# #INDENT# kwargs [ 'validators' ] . append ( Unique ( ( lambda : db_session ) , model , column ) ) #NEWLINE# #UNINDENT# if self . use_mro : #NEWLINE# #INDENT# types = inspect . getmro ( type ( column . type ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# types = [ type ( column . type ) ] #NEWLINE# #UNINDENT# for col_type in types : #NEWLINE# #INDENT# type_string = ( '%s.%s' % ( col_type . __module__ , col_type . __name__ ) ) #NEWLINE# if type_string . startswith ( 'sqlalchemy' ) : #NEWLINE# #INDENT# type_string = type_string [ 11 : ] #NEWLINE# #UNINDENT# if ( type_string in self . converters ) : #NEWLINE# #INDENT# converter = self . converters [ type_string ] #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for col_type in types : #NEWLINE# #INDENT# if ( col_type . __name__ in self . converters ) : #NEWLINE# #INDENT# converter = self . converters [ col_type . __name__ ] #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise ModelConversionError ( ( 'Could not find field converter for %s (%r).' % ( prop . key , types [ 0 ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not db_session ) : #NEWLINE# #INDENT# raise ModelConversionError ( ( 'Cannot convert field %s, need DB session.' % prop . key ) ) #NEWLINE# #UNINDENT# foreign_model = prop . mapper . class_ #NEWLINE# nullable = True #NEWLINE# for pair in prop . local_remote_pairs : #NEWLINE# #INDENT# if ( not pair [ 0 ] . nullable ) : #NEWLINE# #INDENT# nullable = False #NEWLINE# #UNINDENT# #UNINDENT# kwargs . update ( { #NEWLINE# #INDENT# 'allow_blank' : nullable , #NEWLINE# 'query_factory' : ( lambda : db_session . query ( foreign_model ) . all ( ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# converter = self . converters [ prop . direction . name ] #NEWLINE# #UNINDENT# if field_args : #NEWLINE# #INDENT# kwargs . update ( field_args ) #NEWLINE# #UNINDENT# return converter ( model = model , mapper = mapper , prop = prop , column = column , field_args = kwargs )