class_docstr: OLE container object
  
  This class encapsulates the interface to an OLE 2 structured
  storage file.  Use the listdir and openstream methods to
  access the contents of this file.
  
  Object names are given as a list of strings, one for each subentry
  level.  The root entry should be omitted.  For example, the following
  code extracts all image streams from a Microsoft Image Composer file::
  
      ole = OleFileIO("fan.mic")
  
      for entry in ole.listdir():
          if entry[1:2] == "Image":
              fin = ole.openstream(entry)
              fout = open(entry[0:1], "wb")
              while True:
                  s = fin.read(8192)
                  if not s:
                      break
                  fout.write(s)
  
  You can use the viewer application provided with the Python Imaging
  Library to view the resulting files (which happens to be standard
  TIFF files).
class_docstr_tok: ["OLE","container","object","This","class","encapsulates","the","interface","to","an","OLE","2","structured","storage","file",".","Use","the","listdir","and","openstream","methods","to","access","the","contents","of","this","file",".","Object","names","are","given","as","a","list","of","strings",",","one","for","each","subentry","level",".","The","root","entry","should","be","omitted",".","For","example",",","the","following","code","extracts","all","image","streams","from","a","Microsoft","Image","Composer","file",":",":","ole","=","OleFileIO","(","``","fan.mic","''",")","for","entry","in","ole.listdir","(",")",":","if","entry","[","1:2","]","==","``","Image","''",":","fin","=","ole.openstream","(","entry",")","fout","=","open","(","entry","[","0:1","]",",","``","wb","''",")","while","True",":","s","=","fin.read","(","8192",")","if","not","s",":","break","fout.write","(","s",")","You","can","use","the","viewer","application","provided","with","the","Python","Imaging","Library","to","view","the","resulting","files","(","which","happens","to","be","standard","TIFF","files",")","."]
docstr: Constructor for the OleFileIO class.
  
  :param filename: file to open.
  
      - if filename is a string smaller than 1536 bytes, it is the path
        of the file to open. (bytes or unicode string)
      - if filename is a string longer than 1535 bytes, it is parsed
        as the content of an OLE file in memory. (bytes type only)
      - if filename is a file-like object (with read, seek and tell methods),
        it is parsed as-is.
  
  :param raise_defects: minimal level for defects to be raised as exceptions.
      (use DEFECT_FATAL for a typical application, DEFECT_INCORRECT for a
      security-oriented application, see source code for details)
  
  :param write_mode: bool, if True the file is opened in read/write mode instead
      of read-only by default.
  
  :param debug: bool, set debug mode (deprecated, not used anymore)
  
  :param path_encoding: None or str, name of the codec to use for path
      names (streams and storages), or None for Unicode.
      Unicode by default on Python 3+, UTF-8 on Python 2.x.
      (new in olefile 0.42, was hardcoded to Latin-1 until olefile v0.41)
docstr_tok: ["Constructor","for","the","OleFileIO","class",".",":","param","filename",":","file","to","open",".","-","if","filename","is","a","string","smaller","than","1536","bytes",",","it","is","the","path","of","the","file","to","open",".","(","bytes","or","unicode","string",")","-","if","filename","is","a","string","longer","than","1535","bytes",",","it","is","parsed","as","the","content","of","an","OLE","file","in","memory",".","(","bytes","type","only",")","-","if","filename","is","a","file-like","object","(","with","read",",","seek","and","tell","methods",")",",","it","is","parsed","as-is",".",":","param","raise_defects",":","minimal","level","for","defects","to","be","raised","as","exceptions",".","(","use","DEFECT_FATAL","for","a","typical","application",",","DEFECT_INCORRECT","for","a","security-oriented","application",",","see","source","code","for","details",")",":","param","write_mode",":","bool",",","if","True","the","file","is","opened","in","read\/write","mode","instead","of","read-only","by","default",".",":","param","debug",":","bool",",","set","debug","mode","(","deprecated",",","not","used","anymore",")",":","param","path_encoding",":","None","or","str",",","name","of","the","codec","to","use","for","path","names","(","streams","and","storages",")",",","or","None","for","Unicode",".","Unicode","by","default","on","Python","3+",",","UTF-8","on","Python","2.x",".","(","new","in","olefile","0.42",",","was","hardcoded","to","Latin-1","until","olefile","v0.41",")"]
code: def __init__(
      self,
      filename=None,
      raise_defects=DEFECT_FATAL,
      write_mode=False,
      debug=False,
      path_encoding=DEFAULT_PATH_ENCODING,
  ):
      """
      Constructor for the OleFileIO class.
  
      :param filename: file to open.
  
          - if filename is a string smaller than 1536 bytes, it is the path
            of the file to open. (bytes or unicode string)
          - if filename is a string longer than 1535 bytes, it is parsed
            as the content of an OLE file in memory. (bytes type only)
          - if filename is a file-like object (with read, seek and tell methods),
            it is parsed as-is.
  
      :param raise_defects: minimal level for defects to be raised as exceptions.
          (use DEFECT_FATAL for a typical application, DEFECT_INCORRECT for a
          security-oriented application, see source code for details)
  
      :param write_mode: bool, if True the file is opened in read/write mode instead
          of read-only by default.
  
      :param debug: bool, set debug mode (deprecated, not used anymore)
  
      :param path_encoding: None or str, name of the codec to use for path
          names (streams and storages), or None for Unicode.
          Unicode by default on Python 3+, UTF-8 on Python 2.x.
          (new in olefile 0.42, was hardcoded to Latin-1 until olefile v0.41)
      """
      # minimal level for defects to be raised as exceptions:
      self._raise_defects_level = raise_defects
      #: list of defects/issues not raised as exceptions:
      #: tuples of (exception type, message)
      self.parsing_issues = []
      self.write_mode = write_mode
      self.path_encoding = path_encoding
      # initialize all attributes to default values:
      self._filesize = None
      self.ministream = None
      self._used_streams_fat = []
      self._used_streams_minifat = []
      self.byte_order = None
      self.directory_fp = None
      self.direntries = None
      self.dll_version = None
      self.fat = None
      self.first_difat_sector = None
      self.first_dir_sector = None
      self.first_mini_fat_sector = None
      self.fp = None
      self.header_clsid = None
      self.header_signature = None
      self.metadata = None
      self.mini_sector_shift = None
      self.mini_sector_size = None
      self.mini_stream_cutoff_size = None
      self.minifat = None
      self.minifatsect = None
      # TODO: duplicates?
      self.minisectorcutoff = None
      self.minisectorsize = None
      self.ministream = None
      self.minor_version = None
      self.nb_sect = None
      self.num_difat_sectors = None
      self.num_dir_sectors = None
      self.num_fat_sectors = None
      self.num_mini_fat_sectors = None
      self.reserved1 = None
      self.reserved2 = None
      self.root = None
      self.sector_shift = None
      self.sector_size = None
      self.transaction_signature_number = None
      if filename:
          self.open(filename, write_mode=write_mode)
  
imports: from __future__ import print_function
  import io
  import sys
  import struct, array, os.path, datetime, logging
label_desc: Use image node_id 1 to create a new OleFileIO object  with example: obj = OleFileIO(filename, raise_defects, write_mode, debug, path_encoding)