
    VhE                     Z    d dl mZmZmZ eZd dlZd dlZd dlm	Z	 d Z
 G d de      Zd Zy)    )absolute_importdivisionprint_functionN)string_typesc                     d | j                  d      D        }t        d d |D              }ddj                  |      z   dz   }t        j                  |      S )Nc              3   ^   K   | ]%  }|j                         s|j                          ' y wN)strip.0lines     s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/module_utils/homebrew.py	<genexpr>z1_create_regex_group_complement.<locals>.<genexpr>   s     Ddtzz|TZZ\Ds   --
c              3   `   K   | ]&  }|j                  d       d   j                          ( yw)#r   N)splitr
   r   s     r   r   z1_create_regex_group_complement.<locals>.<genexpr>   s&     G$**S/!,224Gs   ,.z[^ ])r   filterjoinrecompile)slinescharsgroups       r   _create_regex_group_complementr      sL    DaggdmDE4GGHECHHUO#d*E::e    c                      e Zd Zdj                  ej
                  j                        Zdj                  ej
                  j                        ZdZ	 e
e      Z e
e      Z e
e	      Zed        Zed        Zed        Zy)	HomebrewValidatea  
        \w                  # alphanumeric characters (i.e., [a-zA-Z0-9_])
        \s                  # spaces
        :                   # colons
        {sep}               # the OS-specific path separator
        .                   # dots
        \-                  # dashes
    )sepz
        \w                  # alphanumeric characters (i.e., [a-zA-Z0-9_])
        \s                  # spaces
        {sep}               # the OS-specific path separator
        .                   # dots
        \-                  # dashes
    aC  
        \w                  # alphanumeric characters (i.e., [a-zA-Z0-9_])
        .                   # dots
        /                   # slash (for taps)
        \+                  # plusses
        \-                  # dashes
        :                   # colons (for URLs)
        @                   # at-sign
    c                      t        |t              r j                  j                  |       S 	 t	        |       |}t         fd|D              S # t        $ r Y yw xY w)z
        `path` must be one of:
         - list of paths
         - a string containing only:
             - alphanumeric characters
             - dashes
             - dots
             - spaces
             - colons
             - os.path.sep
        c              3   @   K   | ]  }j                  |        y wr	   )valid_brew_path)r   path_clss     r   r   z.HomebrewValidate.valid_path.<locals>.<genexpr>T   s     Ees**51Es   F)
isinstancer   INVALID_PATH_REGEXsearchiterall	TypeError)r'   pathpathss   `  r   
valid_pathzHomebrewValidate.valid_path=   sb     dL)--44T:::	FJ EEuEEE	  		s   A 	AAc                 d    |yt        |t              xr | j                  j                  |       S )z
        `brew_path` must be one of:
         - None
         - a string containing only:
             - alphanumeric characters
             - dashes
             - dots
             - spaces
             - os.path.sep
        T)r(   r   INVALID_BREW_PATH_REGEXr*   )r'   	brew_paths     r   r%   z HomebrewValidate.valid_brew_pathV   s=     |
 @--44Y??	@r   c                 d    |yt        |t              xr | j                  j                  |       S )z/A valid package is either None or alphanumeric.T)r(   r   INVALID_PACKAGE_REGEXr*   )r'   packages     r   valid_packagezHomebrewValidate.valid_packagej   s:     ?\
 <++227;;	<r   N)__name__
__module____qualname__formatosr.   r"   VALID_PATH_CHARSVALID_BREW_PATH_CHARSVALID_PACKAGE_CHARSr   r)   r2   r5   classmethodr0   r%   r7    r   r   r!   r!      s     	GGKK 	 	  	GGKK 	 	  88HI<=RS:;NO F F0 @ @& < <r   r!   c                    | j                   d   }t        j                  |      s!| j                  dj	                  |             t        |t              r|j                  d      }n4t        |t              r|}n!| j                  dj	                  |             | j                  dd      }t        j                  |      s!| j                  dj	                  |             |S )	zAttempt to find the Homebrew executable path.

    Requires:
        - module has a `path` parameter
        - path is a valid path string for the target OS. Otherwise, module.fail_json()
          is called with msg="Invalid_path: <path>".
    r.   zInvalid path: {0})msg:brewT)requiredopt_dirszInvalid brew path: {0})paramsr!   r0   	fail_jsonr;   r(   r   r   listget_bin_pathr%   )moduler.   r/   r3   s       r   parse_brew_pathrM   v   s     == D&&t,077=>$%

3	D$	077=>##FTE#JI++I65<<YGHr   )
__future__r   r   r   type__metaclass__r<   r   ansible.module_utils.sixr   r   objectr!   rM   rA   r   r   <module>rS      s5    A @ 	 	 1]<v ]<@r   