#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 location ) : #NEWLINE# #INDENT# raise ValueError ( 'Missing path specification.' ) #NEWLINE# #UNINDENT# if path_spec . HasParent ( ) : #NEWLINE# #INDENT# raise errors . PathSpecError ( 'Unsupported path specification with parent.' ) #NEWLINE# #UNINDENT# location = getattr ( path_spec , 'location' , None ) #NEWLINE# if ( location is None ) : #NEWLINE# #INDENT# raise errors . PathSpecError ( 'Path specification missing location.' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# is_device = pysmdev . check_device ( location ) #NEWLINE# #UNINDENT# except IOError as exception : #NEWLINE# #INDENT# exception_string = str ( exception ) #NEWLINE# if ( not isinstance ( exception_string , py2to3 . UNICODE_TYPE ) ) : #NEWLINE# #INDENT# exception_string = py2to3 . UNICODE_TYPE ( exception_string , errors = 'replace' ) #NEWLINE# #UNINDENT# if ( ' access denied ' in exception_string ) : #NEWLINE# #INDENT# raise errors . AccessError ( 'Access denied to file: {0:s} with error: {1:s}' . format ( location , exception_string ) ) #NEWLINE# #UNINDENT# is_device = False #NEWLINE# #UNINDENT# if ( not is_device ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# stat_info = os . stat ( location ) #NEWLINE# #UNINDENT# except OSError as exception : #NEWLINE# #INDENT# raise IOError ( 'Unable to open file with error: {0:s}.' . format ( exception ) ) #NEWLINE# #UNINDENT# if ( stat . S_ISCHR ( stat_info . st_mode ) or stat . S_ISBLK ( stat_info . st_mode ) ) : #NEWLINE# #INDENT# is_device = True #NEWLINE# #UNINDENT# #UNINDENT# if is_device : #NEWLINE# #INDENT# self . _file_object = pysmdev . handle ( ) #NEWLINE# self . _file_object . open ( location , mode = mode ) #NEWLINE# self . _size = self . _file_object . media_size #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _file_object = open ( location , mode = mode ) #NEWLINE# self . _size = stat_info . st_size