o
    Th*                     @   sn   d Z ddlZddlmZmZmZmZmZmZm	Z	 ddl
mZmZ ddlmZ er.ddlmZ G dd	 d	ZdS )
a.  
Environment variable configuration loading class.

Using a class here doesn't really model anything but makes state passing (in a
situation requiring it) more convenient.

This module is currently considered private/an implementation detail and should
not be included in the Sphinx API documentation.
    N)TYPE_CHECKINGAnyDictIterableListMappingSequence   )UncastableEnvVarAmbiguousEnvVar)debug)Configc                   @   s   e Zd ZdddeddfddZdeeef fdd	Zd
ee de	ee
e f deeef fddZd
ee defddZd
ee ddfddZd
e
e deddfddZdededefddZdS )Environmentconfigr   prefixreturnNc                 C   s   || _ || _i | _d S N)_config_prefixdata)selfr   r    r   =/var/www/html/venv/lib/python3.10/site-packages/invoke/env.py__init__   s   
zEnvironment.__init__c                 C   sv   | j g i d}d}t|| j| | D ]\}}| jpd| }|tjv r/| |tj|  qtd| j | jS )z
        Return a nested dict containing values from `os.environ`.

        Specifically, values whose keys map to already-known configuration
        settings, allowing us to perform basic typecasting.

        See :ref:`env-vars` for details.
        )key_pathenv_varsz>Scanning for env vars according to prefix: {!r}, mapping: {!r} zObtained env var config: {!r})	_crawlr   formatr   itemsosenviron	_path_setr   )r   r   menv_varr   real_varr   r   r   load   s   

zEnvironment.loadr   r   c           
      C   s   i }|  |}t|drIt|jrIt|drI| D ],}t|fi |}||g }| ||}|D ]}||v r@d}	t|	|q1|| q|S ||| 	|< |S )a  
        Examine config at location ``key_path`` & return potential env vars.

        Uses ``env_vars`` dict to determine if a conflict exists, and raises an
        exception if so. This dict is of the following form::

            {
                'EXPECTED_ENV_VAR_HERE': ['actual', 'nested', 'key_path'],
                ...
            }

        Returns another dictionary of new keypairs as per above.
        keys__getitem__zFound >1 source for {})
	_path_gethasattrcallabler'   dictr   r   r   update_to_env_var)
r   r   r   new_varsobjkeymerged_varsmerged_pathcrawlederrr   r   r   r   0   s*   

zEnvironment._crawlc                 C   s   d | S )N_)joinupper)r   r   r   r   r   r.   X   s   zEnvironment._to_env_varc                 C   s   | j }|D ]}|| }q|S r   )r   )r   r   r0   r1   r   r   r   r)   [   s   
zEnvironment._path_getvaluec                 C   sV   | j }|d d D ]}||vri ||< || }q	| |}| ||}|||d < d S )N)r   r)   _cast)r   r   r9   r0   r1   oldnewr   r   r   r"   c   s   

zEnvironment._path_setr<   r=   c                 C   s^   t |tr	|dvS t |tr|S |d u r|S t |ttfr*d}|t|}t|||S )N)0r   z,Can't adapt an environment string into a {}!)	
isinstanceboolstrlisttupler   typer
   	__class__)r   r<   r=   r5   r   r   r   r;   o   s   


zEnvironment._cast)__name__
__module____qualname__rA   r   r   r   r&   r   r   r   r   r   r.   r)   r"   r;   r   r   r   r   r      s    

(r   )__doc__r    typingr   r   r   r   r   r   r   
exceptionsr
   r   utilr   r   r   r   r   r   r   r   <module>   s    
$