#NEWLINE# def set_lexer_from_filename( self , filename ) : #NEWLINE# #INDENT# '\n        Change the lexer based on the filename (actually only the extension is\n        needed)\n\n        :param filename: Filename or extension\n        ' #NEWLINE# self . _lexer = None #NEWLINE# if filename . endswith ( '~' ) : #NEWLINE# #INDENT# filename = filename [ 0 : ( len ( filename ) - 1 ) ] #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . _lexer = get_lexer_for_filename ( filename ) #NEWLINE# #UNINDENT# except ( ClassNotFound , ImportError ) : #NEWLINE# #INDENT# print ( 'class not found for url' , filename ) #NEWLINE# try : #NEWLINE# #INDENT# m = mimetypes . guess_type ( filename ) #NEWLINE# print ( m ) #NEWLINE# self . _lexer = get_lexer_for_mimetype ( m [ 0 ] ) #NEWLINE# #UNINDENT# except ( ClassNotFound , IndexError , ImportError ) : #NEWLINE# #INDENT# self . _lexer = get_lexer_for_mimetype ( 'text/plain' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( self . _lexer is None ) : #NEWLINE# #INDENT# _logger ( ) . warning ( 'failed to get lexer from filename: %s, using plain text instead...' , m ) #NEWLINE# self . _lexer = TextLexer ( )