code: def find_tor_binary(globs=('/usr/sbin/', '/usr/bin/',
                             '/Applications/TorBrowser_*.app/Contents/MacOS/'),
                      system_tor=True):
      
  
      # Try to find the tor executable using the shell
      if system_tor:
          try:
              proc = subprocess.Popen(
                  ('which tor'),
                  stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                  shell=True
              )
          except OSError:
              pass
          else:
              stdout, _ = proc.communicate()
              if proc.poll() == 0 and stdout != '':
                  return stdout.strip()
  
      # the shell may not provide type and tor is usually not on PATH when using
      # the browser-bundle. Look in specific places
      for pattern in globs:
          for path in glob.glob(pattern):
              torbin = os.path.join(path, 'tor')
              if is_executable(torbin):
                  return torbin
      return None
docs: Tries to find the tor executable using the shell first or in in the
      paths whose glob-patterns is in the given 'globs'-tuple.
  
      :param globs:
          A tuple of shell-style globs of directories to use to find tor
          (TODO consider making that globs to actual tor binary?)
  
      :param system_tor:
          This controls whether bash is used to seach for 'tor' or
          not. If False, we skip that check and use only the 'globs'
          tuple.