code: def _identify_format(filename):
      """_identify_format(filename)
  
      Tries to identify the format of the graph stored in the file with the
      given filename. It identifies most file formats based on the extension
      of the file (and not on syntactic evaluation). The only exception is
      the adjacency matrix format and the edge list format: the first few
      lines of the file are evaluated to decide between the two.
  
      @note: Internal function, should not be called directly.
  
      @param filename: the name of the file or a file object whose C{name}
        attribute is set.
      @return: the format of the file as a string.
      """
      import os.path
  
      if hasattr(filename, "name") and hasattr(filename, "read"):
          # It is most likely a file
          try:
              filename = filename.name
          except Exception:
              return None
  
      root, ext = os.path.splitext(filename)
      ext = ext.lower()
  
      if ext == ".gz":
          _, ext2 = os.path.splitext(root)
          ext2 = ext2.lower()
          if ext2 == ".pickle":
              return "picklez"
          elif ext2 == ".graphml":
              return "graphmlz"
  
      if ext in [
          ".dimacs",
          ".dl",
          ".dot",
          ".edge",
          ".edges",
          ".edgelist",
          ".gml",
          ".graphml",
          ".graphmlz",
          ".gw",
          ".lgl",
          ".lgr",
          ".ncol",
          ".net",
          ".pajek",
          ".pickle",
          ".picklez",
          ".svg",
      ]:
          return ext[1:]
  
      if ext == ".txt" or ext == ".dat":
          # Most probably an adjacency matrix or an edge list
          f = open(filename, "r")
          line = f.readline()
          if line is None:
              return "edges"
          parts = line.strip().split()
          if len(parts) == 2:
              line = f.readline()
              if line is None:
                  return "edges"
              parts = line.strip().split()
              if len(parts) == 2:
                  line = f.readline()
                  if line is None:
                      # This is a 2x2 matrix, it can be a matrix or an edge
                      # list as well and we cannot decide
                      return None
                  else:
                      parts = line.strip().split()
                      if len(parts) == 0:
                          return None
                  return "edges"
              else:
                  # Not a matrix
                  return None
          else:
              return "adjacency"
  
file_path: python-igraph/src/igraph/io/files.py
imports: import gzip
  import os
  from shutil import copyfileobj
  from warnings import warn
  from igraph._igraph import GraphBase
  from igraph.utils import named_temporary_file
label_desc: Use image node_id 1 for calling a global function with example usage: _identify_format(filename) and returns: ext, str, str, str, None, str, str, str, None, None, None