
    +h.                        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edf   Z ej4                  e      Zd	ee   d
ee   fdZ G d d      Z	 d(dededee   d
ee   fdZe	dedee   d
eeee   ee   f      fd       Z 	 	 	 d)dedededede!dee   d
eee!   eef   fdZ"	 	 d*de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&	 	 	 	 	 	 d,dee   d#eee      d$e!de!d%e!dee   d
e!fd&Z'	 	 	 	 	 d-dee   d#eee      d$e!d%e!dee   d
eeee   f   fd'Z(y).    N)OrderedDict)contextmanager)IODictIterableIteratorMappingOptionalTupleUnion   )Bindingparse_stream)parse_variableszos.PathLike[str]mappingsreturnc              #      K   | D ]<  }|j                   r*t        j                  d|j                  j                         | > y w)Nz;Python-dotenv could not parse statement starting at line %s)errorloggerwarningoriginalline)r   mappings     >/var/www/html/venv/lib/python3.12/site-packages/dotenv/main.pywith_warn_for_invalid_linesr      sA      ==NNM  %% s   AAc                       e Zd Z	 	 	 	 	 ddee   deee      dedee   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y)DotEnvNdotenv_pathstreamverboseencodinginterpolateoverrider   c                 f    || _         || _        d | _        || _        || _        || _        || _        y N)r   r   _dictr    r!   r"   r#   )selfr   r   r    r!   r"   r#   s          r   __init__zDotEnv.__init__#   s7     /:)/9=
$'/!,&    c              #     K   | j                   rXt        j                  j                  | j                         r/t	        | j                   | j
                        5 }| d d d        y | j                  | j                   y | j                  r$t        j                  d| j                   xs d       t        j                  d       y # 1 sw Y   y xY ww)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_stream4   s     t/?/? @d&&? 6 [[$++||I$$. ++b/! s   ACC
A,C
CCc                    | j                   r| j                   S | j                         }| j                  r1t        t	        || j
                              | _         | j                   S t        |      | _         | j                   S )zReturn dotenv as dict)r#   )r&   parser"   r   resolve_variablesr#   )r'   
raw_valuess     r   dictzDotEnv.dictC   sc    ::::ZZ\
$%6zDMM%Z[DJ zz %Z0DJzzr)   c              #      K   | j                         5 }t        t        |            D ])  }|j                  |j                  |j                  f + 	 d d d        y # 1 sw Y   y xY wwr%   )r5   r   r   keyvalue)r'   r   r   s      r   r7   zDotEnv.parseQ   s^      	566|F7KL 5;;*!++w}}445	5 	5 	5s!   A*$AA	A*A'#A*c                     | j                         sy| j                         j                         D ]:  \  }}|t        j                  v r| j                  s%|(|t        j                  |<   < y)zI
        Load the current dotenv as system environment variable.
        FT)r:   itemsr.   environr#   )r'   kvs      r   set_as_environment_variablesz#DotEnv.set_as_environment_variablesW   s]     yy{IIK%%' 	"DAqBJJt}}} !

1		" r)   r<   c                     | j                         }||v r||   S | j                  r!t        j                  d|| j                         y)z	
        zKey %s not found in %s.N)r:   r    r   r   r   )r'   r<   datas      r   getz
DotEnv.getf   sA     yy{$;9<<NN4c4;K;KLr)   )NFNTT)__name__
__module____qualname__r
   StrPathr   strboolr(   r   r   r5   r   r:   r   r7   rC   rF    r)   r   r   r   "   s     %)"& 'g&' C!' 	'
 3-' ' ' 
'" "Xbg. " "d3-. 5xc8C=&8 9: 5d s x} r)   r   r   
key_to_getr!   c                 <    t        | d|      j                  |      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   rN   r!   s      r   get_keyrP   t   s     +th?CCJOOr)   r/   c              #     K   t         j                  j                  |       s(t        | d|      5 }|j	                  d       d d d        t        j                  d|d      5 }	 t        | |      5 }||f d d d        d d d        t        j                  j                  |        y # 1 sw Y   hxY w# 1 sw Y   >xY w# t        $ r! t        j                  |j                          w xY w# 1 sw Y   oxY ww)Nw)moder!   r-   F)rS   r!   deleter+   )r.   r/   r0   r1   writetempfileNamedTemporaryFileBaseExceptionunlinknameshutilmove)r/   r!   sourcedests       r   rewriter_      s     
 77>>$$S84 	LL			$	$#	O SW	dX. %&tn$% KK		4 	 	% % 	IIdii 		 s^   .C:B) C:"C.$C1B58C )C:)B2.C:5B>	:C*C++C..C73C:
key_to_setvalue_to_set
quote_modeexportc                    |dvrt        d|       |dk(  xs |dk(  xr |j                          }|r"dj                  |j                  dd            }n|}|r
d| d	| d
}n| d	| d
}t	        | |      5 \  }	}
d}d}t        t        |	            D ]p  }|j                  |k(  r|
j                  |       d}&|
j                  |j                  j                         |j                  j                  j                  d
       }r |s$|r|
j                  d
       |
j                  |       ddd       d||fS # 1 sw Y   xY w)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
    )alwaysautoneverzUnknown quote_mode: re   rf   z'{}''z\'zexport =
r+   FTN)
ValueErrorisalnumformatreplacer_   r   r   r<   rU   r   stringendswith)r   r`   ra   rb   rc   r!   quote	value_outline_outr]   r^   replacedmissing_newliner   s                 r   set_keyrv      si    44/
|<== 	h 	A& ?)=)=)?%? 

 MM,"6"6sE"BC	 	ZL)B7 \9+R0	x	0 !NVT2<3GH 	MG{{j(

8$

7++223&-&6&6&=&=&F&Ft&L"L	M 

4 JJx ! \))! !s   9B5D;;Ekey_to_unsetc                    t         j                  j                  |       st        j	                  d|        d|fS d}t        | |      5 \  }}t        t        |            D ]9  }|j                  |k(  rd}|j                  |j                  j                         ; 	 ddd       |st        j	                  d||        d|fS ||fS # 1 sw Y   *xY w)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   ro   )r   rw   rb   r!   removedr]   r^   r   s           r   	unset_keyr{      s     77>>+&A;O\!!G	x	0 4NVT2<3GH 	4G{{l*

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

2::&

:&

:&

2::&WWA5AAF!
4"  r)   c              #     K   t         j                  j                  |       st        d      t         j                  j	                  |       rt         j                  j                  |       } d}t         j                  j                  |       }||k7  rd| t         j                  j                  t         j                  j                  |t         j                  j                              }||}}||k7  rcyyw)zL
    Yield directories starting from the given directory up to the root
    zStarting path not foundN)	r.   r/   ry   IOErrorr0   dirnameabspathr   pardir)r/   last_dircurrent_dir
parent_dirs       r   _walk_to_rootr      s      77>>$/00	ww~~dwwt$H''//$'K
k
!WW__RWW\\+rww~~%NO
 +Z+ k
!s   C1C64C6filenameraise_error_if_not_foundusecwdc                    d }|s |       st        t        dd      rt        j                         }nt        j                         }t
        }|j                  j                  |k(  r4|j                  J |j                  }|j                  j                  |k(  r4|j                  j                  }t        j                  j                  t        j                  j                  |            }t        |      D ]E  }t        j                  j                  ||       }	t        j                  j                  |	      sC|	c S  |rt        d      y)z
    Search in increasingly higher folders for the given file

    Returns path to the file if found, or an empty string otherwise
    c                  <    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4,,,r)   frozenFz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     s    -
 "gc8U&Cyy{ ll&&,6<<+++LLE ll&&,6 11wwrww~>? & WW\\'84
77>>*%
  &''r)   r   r    r"   c                 `    | |
t               } t        | |||||      }|j                         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 at least one environment variable is set else False

    If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
    .env file.
    r   r   r    r"   r#   r!   )r   r   rC   )r   r   r    r#   r"   r!   dotenvs          r   load_dotenvr   7  sB    0 v~!mF ..00r)   c                 \    | |
t               } t        | |||d|      j                         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.
    Tr   )r   r   r:   )r   r   r    r"   r!   s        r   dotenv_valuesr   ]  s=    . v~!m dfr)   )utf-8)re   Fr   )re   r   )r,   FF)NNFFTr   )NNFTr   ))r3   loggingr.   r[   r   rV   collectionsr   
contextlibr   typingr   r   r   r   r	   r
   r   r   parserr   r   	variablesr   rK   rJ   	getLoggerrG   r   r   r   rP   r_   rL   rv   r{   r8   r   r   r   r   rM   r)   r   <module>r      s"   	  	  
  # %   * & ''
(			8	$(7*; @Q O Oj &
P
P
P sm
P c]	
P !
!sm! eBsGRW$%&! !* %.*.*.* .* 	.*
 .* sm.* 8D>3#$.*h %	!!! ! sm	!
 8D>3!>U3-./ S(3- 28 8 8& %*&&"& & 		&T &* $%#1'"#1RW#1 #1 	#1
 #1 sm#1 
#1N &* $%!'"!RW! ! 	!
 sm! 
#x}
!r)   