#NEWLINE# def get_magic_type( self ) : #NEWLINE# #INDENT# 'Checks the volume for its magic bytes and returns the magic.' #NEWLINE# with io . open ( self . disk . get_fs_path ( ) , 'rb' ) as file : #NEWLINE# #INDENT# file . seek ( self . offset ) #NEWLINE# fheader = file . read ( ( min ( self . size , 4096 ) if self . size else 4096 ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# import magic #NEWLINE# if hasattr ( magic , 'from_buffer' ) : #NEWLINE# #INDENT# logger . debug ( 'Using python-magic Python package for file type magic' ) #NEWLINE# result = magic . from_buffer ( fheader ) . decode ( ) #NEWLINE# return result #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( magic , 'open' ) : #NEWLINE# #INDENT# logger . debug ( 'Using python-magic system package for file type magic' ) #NEWLINE# ms = magic . open ( magic . NONE ) #NEWLINE# ms . load ( ) #NEWLINE# result = ms . buffer ( ms ) #NEWLINE# ms . close ( ) #NEWLINE# return result #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logger . warning ( 'The python-magic module is not available, but another module named magic was found.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except ImportError : #NEWLINE# #INDENT# logger . warning ( 'The python-magic module is not available.' ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# logger . warning ( 'The python-magic module is not available, but another module named magic was found.' ) #NEWLINE# #UNINDENT# return None