#NEWLINE# def _Open( self , path_spec = None , mode = 'rb' ) : #NEWLINE# #INDENT# "Opens the file-like object defined by path specification.\n\n    Args:\n      path_spec: optional path specification (instance of PathSpec).\n      mode: optional file access mode. The default is 'rb' read-only binary.\n\n    Raises:\n      AccessError: if the access to open the file was denied.\n      IOError: if the file-like object could not be opened.\n      PathSpecError: if the path specification is incorrect.\n      ValueError: if the path specification is invalid.\n    " #NEWLINE# if ( not path_spec ) : #NEWLINE# #INDENT# raise ValueError ( 'Missing path specification.' ) #NEWLINE# #UNINDENT# data_stream = getattr ( path_spec , 'data_stream' , None ) #NEWLINE# file_system = resolver . Resolver . OpenFileSystem ( path_spec , resolver_context = self . _resolver_context ) #NEWLINE# file_entry = file_system . GetFileEntryByPathSpec ( path_spec ) #NEWLINE# if ( not file_entry ) : #NEWLINE# #INDENT# file_system . Close ( ) #NEWLINE# raise IOError ( 'Unable to retrieve file entry.' ) #NEWLINE# #UNINDENT# tsk_file = file_entry . GetTSKFile ( ) #NEWLINE# tsk_attribute = None #NEWLINE# if ( getattr ( tsk_file , 'info' , None ) is None ) : #NEWLINE# #INDENT# file_system . Close ( ) #NEWLINE# raise IOError ( 'Missing attribute info in file (pytsk3.File).' ) #NEWLINE# #UNINDENT# if ( getattr ( tsk_file . info , 'meta' , None ) is None ) : #NEWLINE# #INDENT# file_system . Close ( ) #NEWLINE# raise IOError ( 'Missing attribute meta in file.info pytsk3.TSK_FS_FILE).' ) #NEWLINE# #UNINDENT# if ( not hasattr ( tsk_file . info . meta , 'size' ) ) : #NEWLINE# #INDENT# file_system . Close ( ) #NEWLINE# raise IOError ( 'Missing attribute size in file.info.meta (pytsk3.TSK_FS_META).' ) #NEWLINE# #UNINDENT# if ( not hasattr ( tsk_file . info . meta , 'type' ) ) : #NEWLINE# #INDENT# file_system . Close ( ) #NEWLINE# raise IOError ( 'Missing attribute type in file.info.meta (pytsk3.TSK_FS_META).' ) #NEWLINE# #UNINDENT# if data_stream : #NEWLINE# #INDENT# for attribute in tsk_file : #NEWLINE# #INDENT# if ( getattr ( attribute , 'info' , None ) is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# attribute_name = getattr ( attribute . info , 'name' , None ) #NEWLINE# if ( attribute_name is None ) : #NEWLINE# #INDENT# attribute_name = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# attribute_name = attribute_name . decode ( 'utf8' ) #NEWLINE# #UNINDENT# except UnicodeError : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# attribute_type = getattr ( attribute . info , 'type' , None ) #NEWLINE# if ( ( attribute_name == data_stream ) and ( attribute_type in ( pytsk3 . TSK_FS_ATTR_TYPE_HFS_DEFAULT , pytsk3 . TSK_FS_ATTR_TYPE_HFS_DATA , pytsk3 . TSK_FS_ATTR_TYPE_NTFS_DATA ) ) ) : #NEWLINE# #INDENT# tsk_attribute = attribute #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( tsk_attribute is None ) : #NEWLINE# #INDENT# file_system . Close ( ) #NEWLINE# raise IOError ( 'Unable to open data stream: {0:s}.' . format ( data_stream ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not tsk_attribute ) and ( tsk_file . info . meta . type != pytsk3 . TSK_FS_META_TYPE_REG ) ) : #NEWLINE# #INDENT# file_system . Close ( ) #NEWLINE# raise IOError ( 'Not a regular file.' ) #NEWLINE# #UNINDENT# self . _current_offset = 0 #NEWLINE# self . _file_system = file_system #NEWLINE# self . _tsk_attribute = tsk_attribute #NEWLINE# self . _tsk_file = tsk_file #NEWLINE# if self . _tsk_attribute : #NEWLINE# #INDENT# self . _size = self . _tsk_attribute . info . size #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _size = self . _tsk_file . info . meta . size