code: def detect_opened_file_encoding(f):
      # PEPs 263 and 3120
      # Most of the time the first two lines fall in the first couple of hundred chars,
      # and this bulk read/split is much faster.
      lines = ()
      start = b""
      while len(lines) < 3:
          data = f.read(500)
          start += data
          lines = start.split(b"\n")
          if not data:
              break
      m = _match_file_encoding(lines[0])
      if m and m.group(1) != b"c_string_encoding":
          return m.group(2).decode("iso8859-1")
      elif len(lines) > 1:
          m = _match_file_encoding(lines[1])
          if m:
              return m.group(2).decode("iso8859-1")
      return "UTF-8"
  
imports: from __future__ import absolute_import
  import os
  import sys
  import re
  import io
  import codecs
  import shutil
  import tempfile
  from contextlib import contextmanager
label_desc: Use image node_id 15 for calling a global function with example usage: detect_opened_file_encoding(f) and returns: str, m, m