
    \c.                     "   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ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j        e          Zdee         d	ee         fd
Z G d d          Z	 d,deeej        f         dedee         d	ee         fdZe	deeej        f         dee         d	eeee         ee         f                  fd            Z 	 	 	 d-deeej        f         dededede!dee         d	eee!         eef         fdZ"	 	 d.deeej        f         dededee         d	eee!         ef         f
dZ#deeeee         f                  de!d	eeee         f         fdZ$ded	ee         fd Z%	 	 	 d/d"ed#e!d$e!d	efd%Z&	 	 	 	 	 	 d0deeej        df         d'eee                  d(e!de!d)e!dee         d	e!fd*Z'	 	 	 	 	 d1deeej        df         d'eee                  d(e!d)e!dee         d	eeee         f         fd+Z(dS )2    N)OrderedDict)contextmanager)IODictIterableIteratorMappingOptionalTupleUnion   )Bindingparse_stream)parse_variablesmappingsreturnc              #   t   K   | D ]2}|j         r%t                              d|j        j                   |V  3d S )Nz;Python-dotenv could not parse statement starting at line %s)errorloggerwarningoriginalline)r   mappings     +lib/python3.11/site-packages/dotenv/main.pywith_warn_for_invalid_linesr      sX        = 	NNM %        c                   D   e Zd Z	 	 	 	 	 ddeeeej        f                  deee                  de	dedef         de	d	e	d
dfdZ
ed
eee                  fd            Zd
eeee         f         fdZd
eeeee         f                  fdZd
e	fdZded
ee         fdZdS )DotEnvNFTdotenv_pathstreamverboseencodinginterpolateoverrider   c                 h    || _         || _        d | _        || _        || _        || _        || _        d S N)r   r    _dictr!   r"   r#   r$   )selfr   r    r!   r"   r#   r$   s          r   __init__zDotEnv.__init__   s;     '
 & r   c              #   v  K   | j         r^t          j                            | j                   r:t	          | j         | j                  5 }|V  d d d            d S # 1 swxY w Y   d S | j        | j        V  d S | j        r"t          	                    d| j         pd           t          j        d          V  d S )Nr"   z3Python-dotenv could not find configuration file %s..env )r   ospathisfileopenr"   r    r!   r   infoioStringIO)r(   r    s     r   _get_streamzDotEnv._get_stream.   s      	"t/? @ @ 	"d&??? 6                 [ 	"+| I$.   +b//!!!!!s   	AA"Ac                     | j         r| j         S |                                 }| j        r)t          t	          || j                            | _         nt          |          | _         | j         S )zReturn dotenv as dict)r$   )r'   parser#   r   resolve_variablesr$   )r(   
raw_valuess     r   dictzDotEnv.dict=   sd    : 	:ZZ\\
 	1$%6zDM%Z%Z%Z[[DJJ$Z00DJzr   c              #      K   |                                  5 }t          t          |                    D ]}|j        |j        |j        fV  	 d d d            d S # 1 swxY w Y   d S r&   )r5   r   r   keyvalue)r(   r    r   s      r   r7   zDotEnv.parseK   s       	566|F7K7KLL 5 5; 5!+w}44445	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   7AA #A c                     |                                  sdS |                                                                  D ],\  }}|t          j        v r| j        s||t          j        |<   -dS )zI
        Load the current dotenv as system environment variable.
        FNT)r:   itemsr.   environr$   )r(   kvs      r   set_as_environment_variablesz#DotEnv.set_as_environment_variablesQ   ss     yy{{ 	5IIKK%%'' 	" 	"DAqBJ t}  " !
1tr   r<   c                     |                                  }||v r||         S | j        r!t                              d|| j                   dS )z	
        zKey %s not found in %s.N)r:   r!   r   r   r   )r(   r<   datas      r   getz
DotEnv.get`   sQ     yy{{$; 	9< 	MNN4c4;KLLLtr   )NFNTT)__name__
__module____qualname__r
   r   strr.   PathLiker   boolr)   r   r   r5   r   r:   r   r7   rC   rF    r   r   r   r      sm        %)%) ! !eC$456! C!! 	!
 c	"! ! ! 
! ! ! !" "Xbg. " " " ^"d3-.    5xc8C=&8 9: 5 5 5 5d    s x}      r   r   utf-8r   
key_to_getr"   c                 L    t          | d|                              |          S )z
    Get the value of a given key from the given .env.

    Returns `None` if the key isn't found or doesn't have a value.
    T)r!   r"   )r   rF   )r   rO   r"   s      r   get_keyrQ   n   s'     +th???CCJOOOr   r/   c              #   P  K   	 t           j                            |           s?t          | d|          5 }|                    d           d d d            n# 1 swxY w Y   t          j        dd|          5 }t          | |          5 }||fV  d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        |j	        |            d S # t          $ r? t           j                            |j	                  rt          j        |j	                    w xY w)Nzw+r+   r-   F)modedeleter"   )r.   r/   r0   r1   writetempfileNamedTemporaryFileshutilmovenameBaseExceptionunlink)r/   r"   sourcedests       r   rewriter_   {   s     
%w~~d## 	!dD8444 !R   ! ! ! ! ! ! ! ! ! ! ! ! ! ! !(d58TTT 	%X\dX... %&tn$$$% % % % % % % % % % % % % % %	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	DIt$$$$$    7>>$)$$ 	!Idi   sw   1C AC AC AC 9B5BB5B"	"B5%B"	&B5)C 5B99C <B9=C A	D%alwaysF
key_to_setvalue_to_set
quote_modeexportc                    |dvr"t          d                    |                    |dk    p|dk    o|                                 }|r*d                    |                    dd                    }n|}|rd                    ||          }nd	                    ||          }t	          | |
          5 \  }	}
d}d}t          t          |	                    D ]d}|j        |k    r|
                    |           d}%|
                    |j	        j
                   |j	        j
                            d           }e|s,|r|
                    d           |
                    |           ddd           n# 1 swxY w Y   d||fS )z
    Adds or Updates a key/value to the given .env

    If the .env path given doesn't exist, fails instead of risking creating
    an orphan .env somewhere in the filesystem
    )r`   autoneverzUnknown quote_mode: {}r`   rf   z'{}''z\'zexport {}={}
z{}={}
r+   FT
N)
ValueErrorformatisalnumreplacer_   r   r   r<   rU   r   stringendswith)r   ra   rb   rc   rd   r"   quote	value_outline_outr]   r^   replacedmissing_newliner   s                 r   set_keyru      s    44 F188DDEEE 	h 	A& ?)=)=)?)?%? 

  !MM,"6"6sE"B"BCC		 	 ;#**:yAA##J	::	x	0	0	0 !NVT2<3G3GHH 	M 	MG{j( M

8$$$

7+2333&-&6&=&F&Ft&L&L"L 	! !

4   JJx   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! \))s   6B7E99E= E=key_to_unsetc                    t           j                            |           st                              d|            d|fS d}t          | |          5 \  }}t          t          |                    D ]/}|j        |k    rd}|	                    |j
        j                   0	 ddd           n# 1 swxY w Y   |s t                              d||            d|fS ||fS )z
    Removes a given key from the given `.env` file.

    If the .env path given doesn't exist, fails.
    If the given key doesn't exist in the .env, fails.
    z(Can't delete from %s - it doesn't exist.NFr+   Tz/Key %s not removed from %s - key doesn't exist.)r.   r/   existsr   r   r_   r   r   r<   rU   r   rn   )r   rv   rc   r"   removedr]   r^   r   s           r   	unset_keyrz      s5    7>>+&& "A;OOO\!!G	x	0	0	0 4NVT2<3G3GHH 	4 	4G{l* 4

7+23333		44 4 4 4 4 4 4 4 4 4 4 4 4 4 4  "H,Xcddd\!!L  s   AB//B36B3valuesr$   c                 j   i }| D ]\  }}|d }nt          |          }i |r5                    t          j                                       |           n4                    |                               t          j                   d                    fd|D                       }|||<   |S )Nr-   c              3   B   K   | ]}|                               V  d S r&   )resolve).0atomenvs     r   	<genexpr>z$resolve_variables.<locals>.<genexpr>   s/      AA4T\\#..AAAAAAr   )r   updater.   r@   join)r{   r$   
new_valuesrZ   r=   resultatomsr   s          @r   r8   r8      s     J " "u 	BFF#E**EC '

2:&&&

:&&&&

:&&&

2:&&&WWAAAA5AAAAAF!
4r   c              #     K   t           j                            |           st          d          t           j                            |           rt           j                            |           } d}t           j                            |           }||k    r\|V  t           j                            t           j                            |t           j        j                            }||}}||k    ZdS dS )zL
    Yield directories starting from the given directory up to the root
    zStarting path not foundN)	r.   r/   rx   IOErrorr0   dirnameabspathr   pardir)r/   last_dircurrent_dir
parent_dirs       r   _walk_to_rootr      s       7>>$ 1/000	w~~d %wt$$H'//$''K
k
! 8W__RW\\+rw~%N%NOO
 +Z+ k
! 8 8 8 8 8r   r,   filenameraise_error_if_not_foundusecwdc                 h   d }|s  |            st          t          dd          rt          j                    }nt          j                    }t
          }|j        j        |k    r |j        J |j        }|j        j        |k     |j        j        }t          j	        
                    t          j	                            |                    }t          |          D ]E}t          j	                            ||           }	t          j	                            |	          r|	c S F|rt          d          dS )z
    Search in increasingly higher folders for the given file

    Returns path to the file if found, or an empty string otherwise
    c                  L    t          ddddg          } t          | d           S )z> Decide whether this is running in a REPL or IPython notebook __main__N__file__)fromlist)
__import__hasattr)mains    r   _is_interactivez$find_dotenv.<locals>._is_interactive  s-    *dDJ<HHH4,,,,r   frozenFNzFile not foundr-   )getattrsysr.   getcwd	_getframer   f_codeco_filenamef_backr/   r   r   r   r   r0   r   )
r   r   r   r   r/   framecurrent_fileframe_filenamer   
check_paths
             r   find_dotenvr   
  s8   - - -
  @"" @gc8U&C&C @y{{ l&,6 	!<+++LE l&,6 	! 1wrw~>>?? &&  W\\'844
7>>*%% 		   (&'''2r   Tr    r!   r#   c                 x    | |t                      } t          | |||||          }|                                S )a  Parse a .env file and then load all the variables found as environment variables.

    Parameters:
        dotenv_path: Absolute or relative path to .env file.
        stream: Text stream (such as `io.StringIO`) with .env content, used if
            `dotenv_path` is `None`.
        verbose: Whether to output a warning the .env file is missing.
        override: Whether to override the system environment variables with the variables
            from the `.env` file.
        encoding: Encoding to be used to read the file.
    Returns:
        Bool: True if atleast one environment variable is set elese False

    If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
    .env file.
    Nr   r    r!   r#   r$   r"   )r   r   rC   )r   r    r!   r$   r#   r"   dotenvs          r   load_dotenvr   3  sV    0  $v $!mm  F ..000r   c                 t    | |t                      } t          | |||d|                                          S )a  
    Parse a .env file and return its content as a dict.

    The returned dict will have `None` values for keys without values in the .env file.
    For example, `foo=bar` results in `{"foo": "bar"}` whereas `foo` alone results in
    `{"foo": None}`

    Parameters:
        dotenv_path: Absolute or relative path to the .env file.
        stream: `StringIO` object with .env content, used if `dotenv_path` is `None`.
        verbose: Whether to output a warning if the .env file is missing.
        encoding: Encoding to be used to read the file.

    If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
    .env file.
    NTr   )r   r   r:   )r   r    r!   r#   r"   s        r   dotenv_valuesr   Y  sP    .  $v $!mm   dffr   )rN   )r`   FrN   )r`   rN   )r,   FF)NNFFTrN   )NNFTrN   ))r3   loggingr.   rX   r   rV   collectionsr   
contextlibr   typingr   r   r   r   r	   r
   r   r   parserr   r   	variablesr   	getLoggerrG   r   r   r   rJ   rK   rQ   r_   rL   ru   rz   r8   r   r   r   r   rM   r   r   <module>r      s   				  				  



  # # # # # # % % % % % %                    * ) ) ) ) ) ) ) & & & & & &		8	$	$(7*; @Q    O O O O O O O Oj &
P 
PsBK'(
P
P sm
P c]	
P 
P 
P 
P %
R[ 
!%sm% eBsGRW$%&% % % %. %.* .*sBK'(.*.* .* 	.*
 .* sm.* 8D>3#$.* .* .* .*h %	! !sBK'(!! ! sm	!
 8D>3! ! ! !>U3-./ S(3-    28 8 8 8 8 8& %*& &&"& & 		& & & &T 26 $%#1 #1sBK-.#1RW#1 #1 	#1
 #1 sm#1 
#1 #1 #1 #1N 26 $%! !sBK-.!RW! ! 	!
 sm! 
#x}
! ! ! ! ! !r   