#NEWLINE# @ classmethod #NEWLINE# def get_backend( self , uri , client ) : #NEWLINE# #INDENT# "Given the filename of an image, returns (fname, backend)\n        where fname is the filename to be used (could be the same as\n        filename, or something different if the image had to be converted\n        or is missing), and backend is an Image class that can handle\n        fname.\n\n\n        If uri ensd with '.*' then the returned filename will be the best\n        quality supported at the moment.\n\n        That means:  PDF > SVG > anything else\n\n        " #NEWLINE# backend = defaultimage #NEWLINE# ( filename , extension , options ) = self . split_uri ( uri ) #NEWLINE# if ( '*' in filename ) : #NEWLINE# #INDENT# preferred = [ 'gif' , 'jpg' , 'png' ] #NEWLINE# if SVGImage . available ( ) : #NEWLINE# #INDENT# preferred . append ( 'svg' ) #NEWLINE# #UNINDENT# preferred . append ( 'pdf' ) #NEWLINE# available = glob . glob ( filename ) #NEWLINE# cfn = available [ 0 ] #NEWLINE# cv = ( - 10 ) #NEWLINE# for fn in available : #NEWLINE# #INDENT# ext = fn . split ( '.' ) [ ( - 1 ) ] #NEWLINE# if ( ext in preferred ) : #NEWLINE# #INDENT# v = preferred . index ( ext ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# v = ( - 1 ) #NEWLINE# #UNINDENT# if ( v > cv ) : #NEWLINE# #INDENT# cv = v #NEWLINE# cfn = fn #NEWLINE# #UNINDENT# #UNINDENT# filename = cfn #NEWLINE# extension = cfn . split ( '.' ) [ ( - 1 ) ] #NEWLINE# uri = filename #NEWLINE# #UNINDENT# if ( not os . path . exists ( filename ) ) : #NEWLINE# #INDENT# log . error ( 'Missing image file: %s' , filename ) #NEWLINE# filename = missing #NEWLINE# #UNINDENT# if ( extension in [ 'svg' , 'svgz' ] ) : #NEWLINE# #INDENT# if SVGImage . available ( ) : #NEWLINE# #INDENT# log . info ( ( 'Backend for %s is SVGIMage' % filename ) ) #NEWLINE# backend = SVGImage #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# filename = missing #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( extension in [ 'pdf' ] ) : #NEWLINE# #INDENT# if ( ( VectorPdf is not None ) and ( filename is not missing ) ) : #NEWLINE# #INDENT# backend = VectorPdf #NEWLINE# filename = uri #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( LazyImports . PMImage or LazyImports . gfx ) : #NEWLINE# #INDENT# filename = self . raster ( filename , client ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# log . warning ( 'Minimal PDF image support requires PythonMagick or the vectorpdf extension [%s]' , filename ) #NEWLINE# filename = missing #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( extension != 'jpg' ) and ( not LazyImports . PILImage ) ) : #NEWLINE# #INDENT# if LazyImports . PMImage : #NEWLINE# #INDENT# filename = self . raster ( filename , client ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# log . error ( 'To use a %s image you need PIL installed [%s]' , extension , filename ) #NEWLINE# filename = missing #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( filename , backend )