#NEWLINE# def check_image_file_format( self , f ) : #NEWLINE# #INDENT# extension = os . path . splitext ( f . name ) [ 1 ] . lower ( ) [ 1 : ] #NEWLINE# if ( extension not in ALLOWED_EXTENSIONS ) : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid_image' ] , code = 'invalid_image' ) #NEWLINE# #UNINDENT# if hasattr ( f , 'image' ) : #NEWLINE# #INDENT# image = f . image #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not image . closed ) : #NEWLINE# #INDENT# file_position = f . tell ( ) #NEWLINE# f . seek ( 0 ) #NEWLINE# try : #NEWLINE# #INDENT# image = Image . open ( f ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# raise ValidationError ( self . error_messages [ 'invalid_image_known_format' ] , code = 'invalid_image_known_format' ) #NEWLINE# #UNINDENT# f . seek ( file_position ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# image_format = extension . upper ( ) #NEWLINE# if ( image_format == 'JPG' ) : #NEWLINE# #INDENT# image_format = 'JPEG' #NEWLINE# #UNINDENT# internal_image_format = image . format . upper ( ) #NEWLINE# if ( internal_image_format == 'MPO' ) : #NEWLINE# #INDENT# internal_image_format = 'JPEG' #NEWLINE# #UNINDENT# if ( internal_image_format != image_format ) : #NEWLINE# #INDENT# raise ValidationError ( ( self . error_messages [ 'invalid_image_known_format' ] % ( image_format , ) ) , code = 'invalid_image_known_format' )