
    hhg@                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZ G d de	      Z
 G d d	e
      Z G d
 de      Z G d de      Z G d de      Z G d de      Zy)z@Utilities for determining the current platform and architecture.    )absolute_import)division)unicode_literalsNc                       e Zd ZdZy)Errorz2Base class for exceptions in the platforms module.N)__name__
__module____qualname____doc__     T/var/www/html/dev/engine/venv/lib/python3.12/site-packages/fire/console/platforms.pyr   r      s    :r   r   c                   "     e Zd ZdZ fdZ xZS )InvalidEnumValuezFException for when a string could not be parsed to a valid enum value.c           	      l    t         t        |   dj                  ||dj	                  |                   y)zConstructs a new exception.

    Args:
      given: str, The given string that could not be parsed.
      enum_type: str, The human readable name of the enum you were trying to
        parse.
      options: list(str), The valid values for this enum.
    z?Could not parse [{0}] into a valid {1}.  Valid values are [{2}]z, N)superr   __init__formatjoin)selfgiven	enum_typeoptions	__class__s       r   r   zInvalidEnumValue.__init__$   s/     

D*I	y$))G"4	57r   )r   r	   r
   r   r   __classcell__)r   s   @r   r   r   !   s    N7 7r   r   c                       e Zd ZdZ G d de      Z eddd      Z eddd	      Z ed
dd      Z eddd      Z	 eddd      Z
eeee	e
gZed        Zedd       Zed        Zed        Zy)OperatingSystemz=An enum representing the operating system you are running on.c                   V    e Zd ZdZd Zd Zd Zd Zd Ze	d        Z
d Zd	 Zd
 Zd Zy)OperatingSystem._OSzA single operating system.c                 .    || _         || _        || _        y Nidname	file_namer   r#   r$   r%   s       r   r   zOperatingSystem._OS.__init__9       dgdi dnr   c                     | j                   S r!   r#   r   s    r   __str__zOperatingSystem._OS.__str__>       WWnr   c                     t        |t        |             xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S r!   
isinstancetyper#   r$   r%   r   others     r   __eq__zOperatingSystem._OS.__eq__A   V    T
+ 0gg!0ii5::%0 nn/1r   c                     t        | j                        t        | j                        z   t        | j                        z   S r!   hashr#   r$   r%   r*   s    r   __hash__zOperatingSystem._OS.__hash__G   +    $'']T$))_,tDNN/CCCr   c                     | |k(   S r!   r   r1   s     r   __ne__zOperatingSystem._OS.__ne__J       r   c                     ||kD  ||k  z
  S z;Just a helper equivalent to the cmp() function in Python 2.r   clsxys      r   
_CmpHelperzOperatingSystem._OS._CmpHelperM        !eAr   c                     | j                  | j                  | j                  | j                  f|j                  |j                  |j                  f      dk  S Nr   rC   r#   r$   r%   r1   s     r   __lt__zOperatingSystem._OS.__lt__R   G    __77DIIt~~
.88UZZ
13567 7r   c                     | j                  | j                  | j                  | j                  f|j                  |j                  |j                  f      dkD  S rF   rG   r1   s     r   __gt__zOperatingSystem._OS.__gt__W   rI   r   c                 &    | j                  |       S r!   rK   r1   s     r   __le__zOperatingSystem._OS.__le__\       U###r   c                 &    | j                  |       S r!   rH   r1   s     r   __ge__zOperatingSystem._OS.__ge___   rO   r   Nr   r	   r
   r   r   r+   r3   r8   r;   classmethodrC   rH   rK   rN   rR   r   r   r   _OSr   5   sG    $!
1D  7
7
$$r   rU   WINDOWSWindowswindowsMACOSXzMac OS XdarwinLINUXLinuxlinuxCYGWINCygwincygwinMSYSMsysmsysc                  4    t        t        j                        S zRGets all possible enum values.

    Returns:
      list, All the enum values.
    )listr   _ALLr   r   r   	AllValueszOperatingSystem.AllValuesi   s     $$%%r   c                     | syt         j                  D ]  }|j                  | k(  s|c S  |r3t        | dt         j                  D cg c]  }|j                   c}      yc c}w )a  Gets the enum corresponding to the given operating system id.

    Args:
      os_id: str, The operating system id to parse
      error_on_unknown: bool, True to raise an exception if the id is unknown,
        False to just return None.

    Raises:
      InvalidEnumValue: If the given value cannot be parsed.

    Returns:
      OperatingSystemTuple, One of the OperatingSystem constants or None if the
      input is None.
    NzOperating System)r   rg   r#   r   )os_iderror_on_unknownoperating_systemvalues       r   FromIdzOperatingSystem.FromIdr   sn      +00  				%  U$64C4H4HI5ehhIK K J   A"c                  Z   t         j                  dk(  rt        j                  S dt        j
                  v rt        j                  S dt        j
                  v rt        j                  S dt        j
                  v rt        j                  S dt        j
                  v rt        j                  S y)zDetermines the current operating system.

    Returns:
      OperatingSystemTuple, One of the OperatingSystem constants or None if it
      cannot be determined.
    ntr]   rZ   r`   rc   N)
osr$   r   rV   sysplatformr[   rY   r^   ra   r   r   r   CurrentzOperatingSystem.Current   s~     
ww$$$$	CLL	 """	S\\	!###	S\\	!###	3<<	!!!r   c                  J    t         j                         t         j                  u S )z8Returns True if the current operating system is Windows.)r   ru   rV   r   r   r   	IsWindowszOperatingSystem.IsWindows   s     ""$(?(???r   NT)r   r	   r
   r   objectrU   rV   rY   r[   r^   ra   rg   staticmethodrh   rn   ru   rw   r   r   r   r   r   2   s    E+$F +$Z 	9i0'xX.&
gw
(%x8,&	VVV	$$
65&$	/$& &  2  & @ @r   r   c                       e Zd ZdZ G d de      Z eddd      Z eddd      Z eddd      Z eddd      Z	eeee	gZ
eeeeeeeeeee	e	e	e	e	d	Zed
        Zedd       Zed        Zy)Architecturez@An enum representing the system architecture you are running on.c                   V    e Zd ZdZd Zd Zd Zd Zd Ze	d        Z
d Zd	 Zd
 Zd Zy)Architecture._ARCHzA single architecture.c                 .    || _         || _        || _        y r!   r"   r&   s       r   r   zArchitecture._ARCH.__init__   r'   r   c                     | j                   S r!   r)   r*   s    r   r+   zArchitecture._ARCH.__str__   r,   r   c                     t        |t        |             xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S r!   r.   r1   s     r   r3   zArchitecture._ARCH.__eq__   r4   r   c                     t        | j                        t        | j                        z   t        | j                        z   S r!   r6   r*   s    r   r8   zArchitecture._ARCH.__hash__   r9   r   c                     | |k(   S r!   r   r1   s     r   r;   zArchitecture._ARCH.__ne__   r<   r   c                     ||kD  ||k  z
  S r>   r   r?   s      r   rC   zArchitecture._ARCH._CmpHelper   rD   r   c                     | j                  | j                  | j                  | j                  f|j                  |j                  |j                  f      dk  S rF   rG   r1   s     r   rH   zArchitecture._ARCH.__lt__   rI   r   c                     | j                  | j                  | j                  | j                  f|j                  |j                  |j                  f      dkD  S rF   rG   r1   s     r   rK   zArchitecture._ARCH.__gt__   rI   r   c                 &    | j                  |       S r!   rM   r1   s     r   rN   zArchitecture._ARCH.__le__   rO   r   c                 &    | j                  |       S r!   rQ   r1   s     r   rR   zArchitecture._ARCH.__ge__   rO   r   NrS   r   r   r   _ARCHr~      sG     !
1D  7
7
$$r   r   x86x86_64PPCppcarm)amd64r   zi686-64i386i686r   ia64powerpczpower macintoshppc64armv6armv6larm64armv7armv7lc                  4    t        t        j                        S re   )rf   r|   rg   r   r   r   rh   zArchitecture.AllValues   s     !!""r   c                     | syt         j                  D ]  }|j                  | k(  s|c S  |r3t        | dt         j                  D cg c]  }|j                   c}      yc c}w )a  Gets the enum corresponding to the given architecture id.

    Args:
      architecture_id: str, The architecture id to parse
      error_on_unknown: bool, True to raise an exception if the id is unknown,
        False to just return None.

    Raises:
      InvalidEnumValue: If the given value cannot be parsed.

    Returns:
      ArchitectureTuple, One of the Architecture constants or None if the input
      is None.
    Nr|   )r|   rg   r#   r   )architecture_idrk   archrm   s       r   rn   zArchitecture.FromId   si      !! 	O	# _n4@4E4EF5ehhFH H Gro   c                      t         j                  j                  t        j                         j                               S )zDetermines the current system architecture.

    Returns:
      ArchitectureTuple, One of the Architecture constants or None if it cannot
      be determined.
    )r|   _MACHINE_TO_ARCHITECTUREgetrt   machinelowerr   r   r   ru   zArchitecture.Current  s-     0044X5E5E5G5M5M5OPPr   Nrx   )r   r	   r
   r   ry   r   r   r   r   r   rg   r   rz   rh   rn   ru   r   r   r   r|   r|      s    H+$f +$Z 	eUE"#8X.&eUE"#eUE"#
vsC	 $
 F3sscC#N # #  2 Q Qr   r|   c                   :    e Zd ZdZd Zd Zedd       Zd Zd Z	y)	Platformz+Holds an operating system and architecture.c                      || _         || _        y)zConstructs a new platform.

    Args:
      operating_system: OperatingSystem, The OS
      architecture: Architecture, The machine architecture.
    N)rl   architecture)r   rl   r   s      r   r   zPlatform.__init__  s     -D$Dr   c                 N    dj                  | j                  | j                        S )Nz{}-{})r   rl   r   r*   s    r   r+   zPlatform.__str__   s    >>$//1B1BCCr   Nc                 z    t        | r| nt        j                         |r|      S t        j                               S )ah  Determines the current platform you are running on.

    Args:
      os_override: OperatingSystem, A value to use instead of the current.
      arch_override: Architecture, A value to use instead of the current.

    Returns:
      Platform, The platform tuple of operating system and architecture.  Either
      can be None if it could not be determined.
    )r   r   ru   r|   )os_overridearch_overrides     r   ru   zPlatform.Current#  s@     "(?(?(A&D D,8,@,@,BD Dr   c                 N   | j                   t        j                  k(  r9dj                  | j                   j                  t        j                               S | j                   t        j                  k(  r9dj                  | j                   j                  t        j                               S | j                   t        j                  k(  r\d}| j                  t        j                  k(  r| j                  j                  nd}|j                  |t        j                               S y)a  Generates the fragment of the User-Agent that represents the OS.

    Examples:
      (Linux 3.2.5-gg1236)
      (Windows NT 6.1.7601)
      (Macintosh; PPC Mac OS X 12.4.0)
      (Macintosh; Intel Mac OS X 12.4.0)

    Returns:
      str, The fragment of the User-Agent string.
    z({name} {version}))r$   versionz({name} NT {version})z&(Macintosh; {name} Mac OS X {version})Intelz())rl   r   r[   r   r$   rt   releaserV   r   rY   r   r|   r   )r   format_stringarch_strings      r   UserAgentFragmentzPlatform.UserAgentFragment3  s     5 55 "(($$))83C3C3E ) G G			/"9"9	9 %++$$))83C3C3E , G G			/"8"8	8 ?m))\-=-== &&++CJ !!H$4$4$6 " 8 8 r   c                    i }| j                   t        j                  k(  rd|d<   d}d}||z  |d<   |S t        j                  |d<   d|d<   t
        j                  |d<   t
        j                  |d<   t
        j                  |d	<   |S )
a{  Returns the args for spawning an async process using Popen on this OS.

    Make sure the main process does not wait for the new process. On windows
    this means setting the 0x8 creation flag to detach the process.

    Killing a group leader kills the whole group. Setting creation flag 0x200 on
    Windows or running setsid on *nix makes sure the new process is in a new
    session with the new process the group leader. This means it can't be killed
    if the parent is killed.

    Finally, all file descriptors (FD) need to be closed so that waiting for the
    output of the main process does not inadvertently wait for the output of the
    new process, which means waiting for the termination of the new process.
    If the new process wants to write to a file, it can open new FDs.

    Returns:
      {str:}, The args for spawning an async process using Popen on this OS.
    T	close_fds   i   creationflags
preexec_fnstdinstdoutstderr)rl   r   rV   rr   setsid
subprocessPIPE)r   argsdetached_processcreate_new_process_groups       r   AsyncPopenArgszPlatform.AsyncPopenArgsW  s    & D 7 77d;#!+.1IId? K 99d<d; ood7m!d8n!d8nKr   )NN)
r   r	   r
   r   r   r+   rz   ru   r   r   r   r   r   r   r     s1    3%D D D"H"r   r   c                   6    e Zd ZdZdZdZdZdZd
dZd Z	dd	Z
y)PythonVersiona
  Class to validate the Python version we are using.

  The Cloud SDK officially supports Python 2.7.

  However, many commands do work with Python 2.6, so we don't error out when
  users are using this (we consider it sometimes "compatible" but not
  "supported").
  )      )r      )      z
If you have a compatible Python interpreter installed, you can use it by setting
the CLOUDSDK_PYTHON environment variable to point to it.

Nc                 x    |r|| _         y t        t        d      rt        j                  d d | _         y d | _         y )Nversion_infor   )r   hasattrrs   r   )r   r   s     r   r   zPythonVersion.__init__  s1    dl	n	%%%bq)dldlr   c                    |rXdj                  t        j                  d   t        j                  d   t        j                  d   t        j                  d         S dj                  t        j                  d   t        j                  d         S )Nz6Please use Python version {0}.{1}.x or {2}.{3} and up.r      z$Please use Python version {0}.{1}.x.)r   r   MIN_SUPPORTED_PY2_VERSIONMIN_SUPPORTED_PY3_VERSION)r   	allow_py3s     r   SupportedVersionMessagez%PythonVersion.SupportedVersionMessage  s    ELL

1
1!
4

1
1!
4

1
1!
4

1
1!
4	6 6 4::

1
1!
4

1
1!
46 6r   c                    d}| j                   s!dj                  | j                  |            }n| j                   d   dk  rZ| j                   t        j                  k  rdj                  | j                   d   | j                   d   | j                  |            }n||s!dj                  | j                  |            }nY| j                   t        j
                  k  r<dj                  | j                   d   | j                   d   | j                  |            }|rZ|rt        |      t        j                  j                  |       t        j                  j                  t        j                         y| j                   | j                  k\  re| j                   | j                  k  rLt        j                  j                  d	j                  | j                  |      t        j                               y
)a  Ensure that the Python version we are using is compatible.

    This will print an error message if not compatible.

    Compatible versions are 2.6 and 2.7 and > 3.4 if allow_py3 is True.
    We don't guarantee support for 2.6 so we want to warn about it.

    Args:
      allow_py3: bool, True if we should allow a Python 3 interpreter to run
        gcloud. If False, this returns an error for Python 3.
      raise_exception: bool, True to raise an exception rather than printing
        the error and exiting.

    Raises:
      Error: If not compatible and raise_exception is True.

    Returns:
      bool, True if the version is valid, False otherwise.
    NzWERROR: Your current version of Python is not compatible with the Google Cloud SDK. {0}
r   r   zGERROR: Python {0}.{1} is not compatible with the Google Cloud SDK. {2}
r   zKERROR: Python 3 and later is not compatible with the Google Cloud SDK. {0}
FzyWARNING:  Python 2.6.x is no longer officially supported by the Google Cloud SDK
and may not function correctly.  {0}
{1}T)r   r   r   r   MIN_REQUIRED_PY2_VERSIONr   r   rs   r   writeENV_VAR_MESSAGEr   )r   r   raise_exceptionerrors       r   IsCompatiblezPythonVersion.IsCompatible  s   ( E<<-t33I>?  
a1	<<-@@@&F4<<?DLLO77	BD  -F477	BC  \\MCCC&F4<<?DLLO77	BD 
 	El	jju	jj}445 	555t555	jj  vd**95++-. r   r!   )FF)r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   |  s1     $$$/
6>r   r   )r   
__future__r   r   r   rr   rt   r   rs   	Exceptionr   r   ry   r   r|   r   r   r   r   r   <module>r      sw     G &  ' 	   
I 
7u 7"q@f q@hjQ6 jQZfv fRgF gr   