new_contents: '''
  Forked from https://github.com/trentm/which
  Copyright (c) 2002-2005 ActiveState Corp.
  
  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:
  
  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  '''
  
  
  import os
  import sys
  import stat
  import getopt
  
  def _cull(potential, matches, verbose=0):
      """Cull inappropriate matches. Possible reasons:
          - a duplicate of a previous match
          - not a disk file
          - not executable (non-Windows)
      If 'potential' is approved it is returned and added to 'matches'.
      Otherwise, None is returned.
      """
      for match in matches:  # don't yield duplicates
          if _samefile(potential[0], match[0]):
              if verbose:
                  sys.stderr.write("duplicate: %s (%s)\n" % potential)
              return None
      else:
          if not stat.S_ISREG(os.stat(potential[0]).st_mode):
              if verbose:
                  sys.stderr.write("not a regular file: %s (%s)\n" % potential)
          elif sys.platform != "win32" \
               and not os.access(potential[0], os.X_OK):
              if verbose:
                  sys.stderr.write("no executable access: %s (%s)\n"\
                                   % potential)
          else:
              matches.append(potential)
              return potential
  
  def whichgen(command, path=None, verbose=0):
      """Return a generator of full paths to the given command.
      "command" is a the name of the executable to search for.
      "path" is an optional alternate path list to search. The default it
          to use the PATH environment variable.
      "verbose", if true, will cause a 2-tuple to be returned for each
          match. The second element is a textual description of where the
          match was found.
      This method returns a generator which yields either full paths to
      the given command or, if verbose, tuples of the form (<path to
      command>, <where path found>).
      """
      matches = []
      if path is None:
          usingGivenPath = 0
          path = os.environ.get("PATH", "").split(os.pathsep)
      else:
          usingGivenPath = 1
  
      # File name cannot have path separators because PATH lookup does not
      # work that way.
      if os.sep in command or os.altsep and os.altsep in command:
          if os.path.exists(command):
              match = _cull((command, "explicit path given"), matches, verbose)
              if verbose:
                  yield match
              else:
                  yield match[0]
      else:
          for i in range(len(path)):
              dirName = path[i]
              # On windows the dirName *could* be quoted, drop the quotes
              for ext in ['']:
                  absName = os.path.abspath(
                      os.path.normpath(os.path.join(dirName, command+ext)))
                  if os.path.isfile(absName):
                      if usingGivenPath:
                          fromWhere = "from given path element %d" % i
                      elif not sys.platform.startswith("win"):
                          fromWhere = "from PATH element %d" % i
                      elif i == 0:
                          fromWhere = "from current directory"
                      else:
                          fromWhere = "from PATH element %d" % (i-1)
                      match = _cull((absName, fromWhere), matches, verbose)
                      if match:
                          if verbose:
                              yield match
                          else:
                              yield match[0]
  
subject: add python `which` clone