code: def _mapped_std_streams(lookup_paths, streams=('stdin', 'stdout', 'stderr')):
      
      # FIXME add device number too
      standard_inos = {}
      for stream in streams:
          try:
              stream_stat = os.fstat(getattr(sys, stream).fileno())
              key = stream_stat.st_dev, stream_stat.st_ino
              standard_inos[key] = stream
          except Exception:  # FIXME UnsupportedOperation
              pass
          # FIXME if not getattr(sys, stream).istty()
  
      def stream_inos(paths):
          """Yield tuples with stats and path."""
          for path in paths:
              try:
                  stat = os.stat(path)
                  key = (stat.st_dev, stat.st_ino)
                  if key in standard_inos:
                      yield standard_inos[key], path
              except FileNotFoundError:  # pragma: no cover
                  pass
  
      return dict(stream_inos(lookup_paths)) if standard_inos else {}
docs: Get a mapping of standard streams to given paths.