
    .                        S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  S SKJ	r	  S SK
JrJrJrJrJrJrJrJr  SSKJrJr  SSKJr  \R0                  " \5      rS\\   S	\\   4S
 jr " S S5      r S'S\\\R<                  4   S\S\\   S	\\   4S jjr\	S\\\R<                  4   S\\   S	\\\\   \\   4      4S j5       r    S(S\\\R<                  4   S\S\S\S\!S\\   S	\\\!   \\4   4S jjr"  S)S\\\R<                  4   S\S\S\\   S	\\\!   \4   4
S jjr#S\\\\\   4      S\!S	\\\\   4   4S jr$S\S	\\   4S jr%   S*S\S\!S \!S	\4S! jjr&      S+S\\\R<                  S4   S"\\\      S#\!S\!S$\!S\\   S	\!4S% jjr'     S,S\\\R<                  S4   S"\\\      S#\!S$\!S\\   S	\\\\   4   4S& jjr(g)-    N)OrderedDict)contextmanager)IODictIterableIteratorMappingOptionalTupleUnion   )Bindingparse_stream)parse_variablesmappingsreturnc              #      #    U  HB  nUR                   (       a*  [        R                  SUR                  R                  5        Uv   MD     g 7f)Nz;Python-dotenv could not parse statement starting at line %s)errorloggerwarningoriginalline)r   mappings     lib/third_party/dotenv/main.pywith_warn_for_invalid_linesr      s;     ==NNM  %%  s   A
Ac                      \ rS rSr     SS\\\\R                  4      S\\	\      S\
S\S\4   S\
S\
S	S4S
 jjr\S	\\	\      4S j5       rS	\\\\   4   4S jrS	\\\\\   4      4S jrS	\
4S jrS\S	\\   4S jrSrg)DotEnv   Ndotenv_pathstreamverboseencodinginterpolateoverrider   c                 Z    Xl         X l        S U l        X0l        X@l        XPl        X`l        g N)r   r    _dictr!   r"   r#   r$   )selfr   r    r!   r"   r#   r$   s          r   __init__DotEnv.__init__   s+     '
 &     c              #     #    U R                   (       aZ  [        R                  R                  U R                   5      (       a,  [	        U R                   U R
                  S9 nUv   S S S 5        g U R                  b  U R                  v   g U R                  (       a)  [        R                  SU R                   =(       d    S5        [        R                  " S5      v   g ! , (       d  f       g = f7f)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_streamDotEnv._get_stream.   s     t/?/? @ @d&&?6 @?[[$++||I$$. ++b/! @?s   AC. C%A8C.
C+'C.c                    U R                   (       a  U R                   $ U R                  5       nU R                  (       a-  [        [	        XR
                  S95      U l         U R                   $ [        U5      U l         U R                   $ )zReturn dotenv as dict)r$   )r'   parser#   r   resolve_variablesr$   )r(   
raw_valuess     r   dictDotEnv.dict=   sa    ::::ZZ\
$%6zMM%Z[DJ zz %Z0DJzzr+   c              #      #    U R                  5        n[        [        U5      5       H,  nUR                  c  M  UR                  UR                  4v   M.     S S S 5        g ! , (       d  f       g = f7fr&   )r7   r   r   keyvalue)r(   r    r   s      r   r:   DotEnv.parseK   sP     66|F7KL;;*!++w}}44 M  s!   A2#A!A!	A2!
A/+A2c                     U R                  5       (       d  gU R                  5       R                  5        HD  u  pU[        R                  ;   a  U R                  (       d  M,  Uc  M1  U[        R                  U'   MF     g)z9
Load the current dotenv as system environment variable.
FT)r=   itemsr0   environr$   )r(   kvs      r   set_as_environment_variables#DotEnv.set_as_environment_variablesQ   sX     yy{{IIK%%'DABJJt}}} !

1	 ( r+   r@   c                     U R                  5       nX;   a  X!   $ U R                  (       a   [        R                  SXR                  5        g)z	
        zKey %s not found in %s.N)r=   r!   r   r   r   )r(   r@   datas      r   get
DotEnv.get`   s;     yy{;9<<NN4c;K;KLr+   )r'   r   r"   r#   r$   r    r!   )NFNTT)__name__
__module____qualname____firstlineno__r
   r   strr0   PathLiker   boolr)   r   r   r7   r   r=   r   r:   rH   rL   __static_attributes__ r+   r   r   r      s    %)%) !eC$456! C!! 	!
 c	"! ! ! 
!" "Xbg. " "d3-. 5xc8C=&8 9: 5d s x} r+   r   r   
key_to_getr"   c                 6    [        U SUS9R                  U5      $ )zs
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   rL   )r   rW   r"   s      r   get_keyrY   n   s     +th?CCJOOr+   r1   c              #   n  #     [         R                  R                  U 5      (       d%  [        U SUS9 nUR	                  S5        S S S 5        [
        R                  " SSUS9 n[        XS9 nX#4v   S S S 5        S S S 5        [        R                  " WR                  U 5        g ! , (       d  f       Nf= f! , (       d  f       NI= f! , (       d  f       NR= f! [         aP    [         R                  R                  WR                  5      (       a   [         R                  " UR                  5        e f = f7f)Nzw+r-   r/   F)modedeleter"   )r0   r1   r2   r3   writetempfileNamedTemporaryFileshutilmovenameBaseExceptionunlink)r1   r"   sourcedests       r   rewriterg   {   s     
%ww~~d##dD84R  5((d58TX\d.&n$ / U 	DIIt$ 54 /. UT  77>>$))$$IIdii sd   D5/C B%C #
C-B63C;C "D5%
B3/C 6
C	 C
CC AD22D5
key_to_setvalue_to_set
quote_modeexportc                    US;  a  [        SR                  U5      5      eUS:H  =(       d!    US:H  =(       a    UR                  5       (       + nU(       a"  SR                  UR                  SS5      5      nOUnU(       a  SR                  X5      nOS	R                  X5      n[	        XS
9 u  pSnSn[        [        U	5      5       Hw  nUR                  U:X  a  U
R                  U5        SnM(  U
R                  UR                  R                  5        UR                  R                  R                  S5      (       + nMy     U(       d)  U(       a  U
R                  S5        U
R                  U5        SSS5        SX4$ ! , (       d  f       N= f)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: {}rm   rn   z'{}''z\'zexport {}={}
z{}={}
r-   FT
N)
ValueErrorformatisalnumreplacerg   r   r   r@   r]   r   stringendswith)r   rh   ri   rj   rk   r"   quote	value_outline_outre   rf   replacedmissing_newliner   s                 r   set_keyr}      sT    44188DEE 	h 	A& ?)=)=)?%? 

 MM,"6"6sE"BC	 	#**:A##J:		0NV2<3GHG{{j(

8$

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

4 JJx  
1 )) 
1	0s   ,CE>>
Fkey_to_unsetc                    [         R                  R                  U 5      (       d  [        R	                  SU 5        SU4$ Sn[        XS9 u  pV[        [        U5      5       H<  nUR                  U:X  a  SnM  UR                  UR                  R                  5        M>     SSS5        U(       d  [        R	                  SX5        SU4$ XA4$ ! , (       d  f       N2= f)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.)r0   r1   existsr   r   rg   r   r   r@   r]   r   rv   )r   r~   rj   r"   removedre   rf   r   s           r   	unset_keyr      s     77>>+&&A;O\!!G		0NV2<3GHG{{l*

7++223	 I 
1 H,d\!!   
1	0s   
AC
Cvaluesr$   c                 V  ^ 0 nU  H  u  p4Uc  S nO[        U5      n0 mU(       a1  TR                  [        R                  5        TR                  U5        O0TR                  U5        TR                  [        R                  5        SR	                  U4S jU 5       5      nXRU'   M     U$ )Nr/   c              3   D   >#    U  H  oR                  T5      v   M     g 7fr&   )resolve).0atomenvs     r   	<genexpr>$resolve_variables.<locals>.<genexpr>   s     A54\\#..5s    )r   updater0   rE   join)r   r$   
new_valuesrb   rA   resultatomsr   s          @r   r;   r;      s     J=F#E*EC

2::&

:&

:&

2::&WWA5AAF!4    r+   c              #     #    [         R                  R                  U 5      (       d  [        S5      e[         R                  R	                  U 5      (       a  [         R                  R                  U 5      n Sn[         R                  R                  U 5      nX:w  ac  Uv   [         R                  R                  [         R                  R                  U[         R                  R                  5      5      nX#p!X:w  a  Mb  gg7f)zD
Yield directories starting from the given directory up to the root
zStarting path not foundN)	r0   r1   r   IOErrorr2   dirnameabspathr   pardir)r1   last_dircurrent_dir
parent_dirs       r   _walk_to_rootr      s      77>>$/00	ww~~dwwt$H''//$'K

!WW__RWW\\+rww~~%NO
 ++ 
!s   C9C?=C?filenameraise_error_if_not_foundusecwdc                    S nU(       d"  U" 5       (       d  [        [        SS5      (       a  [        R                  " 5       nO[        R                  " 5       n[
        nUR                  R                  U:X  a7  UR                  c   eUR                  nUR                  R                  U:X  a  M7  UR                  R                  n[        R                  R                  [        R                  R                  U5      5      n[        U5       HJ  n[        R                  R                  X5      n	[        R                  R                  U	5      (       d  MH  U	s  $    U(       a  [        S5      eg)z{
Search in increasingly higher folders for the given file

Returns path to the file if found, or an empty string otherwise
c                  >    [        SSSS/S9n [        U S5      (       + $ )z=Decide whether this is running in a REPL or IPython notebook __main__N__file__)fromlist)
__import__hasattr)mains    r   _is_interactive$find_dotenv.<locals>._is_interactive  s$    *dDJ<H4,,,r+   frozenFzFile not foundr/   )getattrsysr0   getcwd	_getframer   f_codeco_filenamef_backr1   r   r   r   r   r2   r   )
r   r   r   r   r1   framecurrent_fileframe_filenamer   
check_paths
             r   find_dotenvr   
  s    -
 ""gc8U&C&Cyy{ ll&&,6<<+++LLE ll&&,6 11wwrww~>? &WW\\'4
77>>*%% '
  &''r+   r    r!   r#   c           	      ^    U c  Uc
  [        5       n [        U UUUUUS9nUR                  5       $ )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.
r   r    r!   r#   r$   r"   )r   r   rH   )r   r    r!   r$   r#   r"   dotenvs          r   load_dotenvr   3  sB    0 v~!mF ..00r+   c           	      Z    U c  Uc
  [        5       n [        U UUUSUS9R                  5       $ )aa  
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   Y  s=    . v~!m dfr+   )utf-8)rm   Fr   )rm   r   )r.   FF)NNFFTr   )NNFTr   ))r5   loggingr0   r`   r   r^   collectionsr   
contextlibr   typingr   r   r   r   r	   r
   r   r   parserr   r   	variablesr   	getLoggerrN   r   r   r   rR   rS   rY   rg   rT   r}   r   r;   r   r   r   r   rV   r+   r   <module>r      s\   	  	  
  # %   * &			8	$(7*; @Q O Oj &
PsBKK'(
P
P sm
P c]	
P %
R[[ 
!%sm% eBsGRW$%&% %. %.*sBKK'(.*.* .* 	.*
 .* sm.* 8D>3#$.*h %	!sBKK'(!! ! sm	!
 8D>3!>U3-./ S(3- 28 8 8& %*&&"& & 		&T 26 $%#1sBKK-.#1RW#1 #1 	#1
 #1 sm#1 
#1N 26 $%!sBKK-.!RW! ! 	!
 sm! 
#x}
!r+   