code: def open_file(filename, password, show=False, pdf=True):
      """Open and authenticate a document."""
      doc = fitz.open(filename)
      if not doc.is_pdf and pdf is True:
          sys.exit("this command supports PDF files only")
      rc = -1
      if not doc.needs_pass:
          return doc
      if password:
          rc = doc.authenticate(password)
          if not rc:
              sys.exit("authentication unsuccessful")
          if show is True:
              print(
                  "authenticated as %s" % "owner" if rc > 2 else "user"
              )
      else:
          sys.exit("'%s' requires a password" % doc.name)
      return doc
  
imports: import argparse
  import bisect
  import os
  import sys
  import statistics
  from typing import Dict, List, Set, Tuple
  import fitz
  from fitz.fitz import TEXT_INHIBIT_SPACES, TEXT_PRESERVE_LIGATURES, TEXT_PRESERVE_WHITESPACE
label_desc: Use image node_id 2 for calling a global function with example usage: open_file(filename, password, show, pdf) and returns: doc, doc