
    Vh                        d Z ddlmZ ddlZddlZddlZddlmZm	Z	 ddl
mZmZmZ ddlmZmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZmZmZ  e       ZddZddZ ddZ!ddZ"ddZ#ddZ$ddZ%y)zContent configuration.    )annotationsN   )CONTROLLER_PYTHON_VERSIONSSUPPORTED_PYTHON_VERSIONS)PACKAGING_IMPORT_ERRORSpecifierSetVersion)YAML_IMPORT_ERROR	yaml_load)open_binary_fileread_text_file)ApplicationErrordisplay)data_context)EnvironmentConfigContentConfigModulesConfigc                    t        | t              st        dt        |       z        | j	                  dt
              }|t
        k(  rt        d      t        |t        |      |dk(        S )z:Parse the given dictionary as module config and return it.#config must be type `dict` not `%s`python_requireszpython_requires is required
controller)r   python_versionscontroller_only)	
isinstancedict	ExceptiontypegetMISSINGKeyErrorr   parse_python_requires)datar   s     U/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/content_config.pyparse_modules_configr$   /   sf    dD!=T
JKKhh0':O'!455'-o>'<7     c                    t        | t              st        dt        |       z        t	        | j                  di             t        fdt        D              }t        |      S )z;Parse the given dictionary as content config and return it.r   modulesc              3  N   K   | ]  }|t         v s|j                  v r|  y wN)r   r   ).0versionr'   s     r#   	<genexpr>z'parse_content_config.<locals>.<genexpr>J   s1      l&*DDSZSjSjHj $ ls   "%)r'   r   )	r   r   r   r   r$   r   tupler   r   )r"   r   r'   s     @r#   parse_content_configr.   @   sj    dD!=T
JKK #488Ir#:;G  l3L l lO ' r%   c                   t         rt        dt         z        t        rt        dt        z        t        |       }	 t	        |      }	 t        |      }t        j                  d| z  d	       |S # t
        $ r%}t        j                  d| d|       Y d}~yd}~ww xY w# t
        $ r%}t        j                  d| d|       Y d}~yd}~ww xY w)
zaLoad and parse the specified config file and return the result or None if loading/parsing failed.z3The "PyYAML" module is required to parse config: %sz6The "packaging" module is required to parse config: %szIgnoring config "z" due to a YAML parsing error: Nz" due a config parsing error: zLoaded configuration: %sr   )	verbosity)
r
   r   r   r   r   r   r   warningr.   info)pathvalue
yaml_valueexconfigs        r#   load_configr8   S   s    TWhhiiWZppqq4 Eu%

%j1
 LL+d2a@M  RVXZ[\  QUWYZ[s/   A0 	B! 0	B9BB!	C*C

Cc                B   | j                   r8t        t        j                  j	                  | j                   d            | _        | j
                  r| j
                  S d}d}t               j                  j                  r*t        j                  j                  |      rt        |      }|st        t        t        d                  }|j                  j                  s8t        ddj	                  t               d	|j                  j"                        || _        |S )
z
    Parse and return the content configuration (if any) for the current collection.
    For ansible-core, a default configuration is used.
    Results are cached.
    z
config.datztests/config.ymlNdefault)r   )r'   zThis collection does not declare support for modules/module_utils on any known Python version.
Ansible supports modules/module_utils on Python versions: z, z2
This collection provides the Python requirement: )	host_pathdeserialize_content_configosr3   joincontent_configr   content
collectionexistsr8   r.   r   r'   r   r   r   r   )argscollection_config_pathr7   s      r#   get_content_configrE   n   s     ~~8dnnVb9cd"""/F~((RWW^^<R-S34%d )'
  >>)) $(99-F#GIgIg i j 	j
 !DMr%   c                    t        | t              st        dt        |       z        | dk(  rt        }|S | dk(  rt
        }|S t        |       t        fdt        D              }|S )z\Parse the given 'python_requires' version specifier and return the matching Python versions.z8python_requires must must be of type `str` not type `%s`r:   r   c              3  X   K   | ]!  }j                  t        |            s| # y wr)   )containsr	   )r*   r+   specifier_sets     r#   r,   z(parse_python_requires.<locals>.<genexpr>   s%     vW]McMcdklsdtMuvs   **)r   str
ValueErrorr   r   r   r   r-   )r4   versionsrI   s     @r#   r!   r!      ss    eS!SVZ[`Vaabb 	, O 
,	-
 O %U+v0IvvOr%   c                    t        |d      5 }t        j                  | j                  |       ddd       y# 1 sw Y   yxY w)zvSerialize the content config to the given path. If the config has not been loaded, an empty config will be serialized.wbN)r   pickledumpr?   )rC   r3   config_files      r#   serialize_content_configrR      s7    	$	% 6D''56 6 6s	   !7A c                n    t        |       5 }t        j                  |      cddd       S # 1 sw Y   yxY w)z)Deserialize content config from the path.N)r   rO   load)r3   rQ   s     r#   r<   r<      s-    	$	 (;{{;'( ( (s   +4)r"   t.Anyreturnr   )r"   rU   rV   r   )r3   rJ   rV   zt.Optional[ContentConfig])rC   r   rV   r   )r4   rU   rV   ztuple[str, ...])rC   r   r3   rJ   rV   None)r3   rJ   rV   r   )&__doc__
__future__r   r=   rO   typingt	constantsr   r   compat.packagingr   r   r	   compat.yamlr
   r   ior   r   utilr   r   r"   r   r7   r   r   r   objectr   r$   r.   r8   rE   r!   rR   r<    r%   r#   <module>rc      sn     " 	  
 


  ("&6"J$6(r%   