python (3.11.7)

(root)/
lib/
python3.11/
site-packages/
pip/
_internal/
utils/
compat.py
       1  """Stuff that differs in different Python versions and platform
       2  distributions."""
       3  
       4  import logging
       5  import os
       6  import sys
       7  
       8  __all__ = ["get_path_uid", "stdlib_pkgs", "WINDOWS"]
       9  
      10  
      11  logger = logging.getLogger(__name__)
      12  
      13  
      14  def has_tls() -> bool:
      15      try:
      16          import _ssl  # noqa: F401  # ignore unused
      17  
      18          return True
      19      except ImportError:
      20          pass
      21  
      22      from pip._vendor.urllib3.util import IS_PYOPENSSL
      23  
      24      return IS_PYOPENSSL
      25  
      26  
      27  def get_path_uid(path: str) -> int:
      28      """
      29      Return path's uid.
      30  
      31      Does not follow symlinks:
      32          https://github.com/pypa/pip/pull/935#discussion_r5307003
      33  
      34      Placed this function in compat due to differences on AIX and
      35      Jython, that should eventually go away.
      36  
      37      :raises OSError: When path is a symlink or can't be read.
      38      """
      39      if hasattr(os, "O_NOFOLLOW"):
      40          fd = os.open(path, os.O_RDONLY | os.O_NOFOLLOW)
      41          file_uid = os.fstat(fd).st_uid
      42          os.close(fd)
      43      else:  # AIX and Jython
      44          # WARNING: time of check vulnerability, but best we can do w/o NOFOLLOW
      45          if not os.path.islink(path):
      46              # older versions of Jython don't have `os.fstat`
      47              file_uid = os.stat(path).st_uid
      48          else:
      49              # raise OSError for parity with os.O_NOFOLLOW above
      50              raise OSError(f"{path} is a symlink; Will not return uid for symlinks")
      51      return file_uid
      52  
      53  
      54  # packages in the stdlib that may have installation metadata, but should not be
      55  # considered 'installed'.  this theoretically could be determined based on
      56  # dist.location (py27:`sysconfig.get_paths()['stdlib']`,
      57  # py26:sysconfig.get_config_vars('LIBDEST')), but fear platform variation may
      58  # make this ineffective, so hard-coding
      59  stdlib_pkgs = {"python", "wsgiref", "argparse"}
      60  
      61  
      62  # windows detection, covers cpython and ironpython
      63  WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt")