
    iP4                        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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j8                  e      Zd	efd
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+ded	efd)Z,y)0    N)OrderedDict)contextmanager)IODictIterableIteratorMappingOptionalTupleUnion   )Bindingparse_stream)parse_variableszos.PathLike[str]returnc                  r    dt         j                  vryt         j                  d   j                         } | dv S )z8
    Determine if dotenv loading has been disabled.
    PYTHON_DOTENV_DISABLEDF>   1tyyestrue)osenvironcasefold)values    Q/var/www/html/talentspherev1.5.2/venv/lib/python3.12/site-packages/dotenv/main.py_load_dotenv_disabledr      s7      rzz1JJ/099;E222    mappingsc              #      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     r   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/   r0   )selfr+   r,   r-   r.   r/   r0   s          r   __init__zDotEnv.__init__.   s7     /:)/9=
$'/!,&r   c              #     K   | j                   rDt        | 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+   _is_file_or_fifoopenr.   r,   r-   r#   infoioStringIO)r4   r,   s     r   _get_streamzDotEnv._get_stream?   s      01A1A Bd&&? 6 [[$++||I$$. ++b/! s   ACB6
A,C6B?;Cc                    | j                   r| j                   S | j                         }| j                  r1t        t	        || j
                              | _         | j                   S t        |      | _         | j                   S )zReturn dotenv as dict)r0   )r3   parser/   r   resolve_variablesr0   )r4   
raw_valuess     r   dictzDotEnv.dictN   se    ::::ZZ\
$!*t}}E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r2   )r?   r(   r   keyr   )r4   r,   r'   s      r   rA   zDotEnv.parse^   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)rD   itemsr   r   r0   )r4   kvs      r   set_as_environment_variablesz#DotEnv.set_as_environment_variablesd   s]     yy{IIK%%' 	"DAqBJJt}}} !

1		" r   rF   c                     | j                         }||v r||   S | j                  r!t        j                  d|| j                         y) zKey %s not found in %s.N)rD   r-   r#   r$   r+   )r4   rF   datas      r   getz
DotEnv.gets   s?    yy{$;9<<NN4c4;K;KLr   )NFNTT)__name__
__module____qualname__r
   StrPathr   strboolr5   r   r   r?   r   rD   r   rA   rK   rO    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*   rO   )r+   rW   r.   s      r   get_keyrY      s     +th?CCJOOr   pathc              #     K   t        j                  |       j                          t        j                  d|d      5 }d }	 t        | |      5 }||f d d d        d d d        !t        j                  j                  |        y t        j                  j                         |d # 1 sw Y   VxY w# t        $ r}|}Y d }~id }~ww xY w# 1 sw Y   rxY ww)NwF)moder.   deleter7   )pathlibPathtouchtempfileNamedTemporaryFiler;   BaseExceptionshutilmovenamer   unlink)rZ   r.   destr"   sourceerrs         r   rewriterl      s     
 LL		$	$#	O SW	dX. %&tn$% }DIIt$
		$))% % 	E	 sY   <CCB7B+B7AC+B4	0B77	C CCCCC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: rr   rs   z'{}''z\'zexport =
r7   FTN)
ValueErrorisalnumformatreplacerl   r(   r   rF   writer%   stringendswith)r+   rm   rn   ro   rp   r.   quote	value_outline_outrj   ri   replacedmissing_newliner'   s                 r   set_keyr      sf    44/
|<==(" f;\%9%9%;!; 
 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.NFr7   Tz/Key %s not removed from %s - key doesn't exist.)r   rZ   existsr#   r$   rl   r(   r   rF   r|   r%   r}   )r+   r   ro   r.   removedrj   ri   r'   s           r   	unset_keyr      s     77>>+&A;O\!!G	x	0 4NVT2<3GH 	4G{{l*

7++223		44 =|[	
 \!!L  4 4s   	ACCvaluesr0   c                 H   i }| D ]  \  }}|d }nt        |      }i |r1j                  t        j                         j                  |       n0j                  |       j                  t        j                         dj	                  fd|D              }|||<    |S )Nr9   c              3   @   K   | ]  }|j                          y wr2   )resolve).0atomenvs     r   	<genexpr>z$resolve_variables.<locals>.<genexpr>  s     A4T\\#.As   )r   updater   r   join)r   r0   
new_valuesrg   r   resultatomsr   s          @r   rB   rB      s     ,.J "e=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   rZ   r   IOErrorisfiledirnameabspathr   pardir)rZ   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                 V   d }d }|s |       s |       st        t        dd      rt        j                         }n t        j                         }t
        }|j                  j                  |k(  s3t        j                  j                  |j                  j                        sh|j                  J |j                  }|j                  j                  |k(  r4t        j                  j                  |j                  j                        sh|j                  j                  }t        j                  j                  t        j                  j                  |            }t        |      D ]1  }	t        j                  j                  |	|       }
t        |
      s/|
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        t        d      st        t        d      ry	 t        ddddg      } t        | d       S # t        $ r Y yw xY w)	z<Decide whether this is running in a REPL or IPython notebookps1ps2T__main__N__file__)fromlistF)hasattrsys
__import__ModuleNotFoundError)mains    r   _is_interactivez$find_dotenv.<locals>._is_interactive*  sU    3'#u"5	j$
|LD 4,,, # 		s   A   	AAc                  .    t        j                         d uS r2   )r   gettracerV   r   r   _is_debuggerz!find_dotenv.<locals>._is_debugger4  s    ||~T))r   frozenFzFile not foundr9   )getattrr   r   getcwd	_getframer   f_codeco_filenamerZ   r   f_backr   r   r   r   r:   r   )r   r   r   r   r   rZ   framecurrent_fileframe_filenamer   
check_paths              r   find_dotenvr     s5   -* "lnXu8Uyy{ ll&&,6bggnnLL$$?
 <<+++LLE	 ll&&,6bggnnLL$$?

 11wwrww~>? & WW\\'84
J'
  &''r   r,   r-   r/   c                     t               rt        j                  d       y| |
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 with it's default parameters. If you need to change the default parameters
    of `find_dotenv()`, you can explicitly call `find_dotenv()` and pass the result
    to this function as `dotenv_path`.

    If the environment variable `PYTHON_DOTENV_DISABLED` is set to a truthy value,
    .env loading is disabled.
    zSpython-dotenv: .env loading disabled by PYTHON_DOTENV_DISABLED environment variableFr+   r,   r-   r/   r0   r.   )r   r#   debugr   r*   rK   )r+   r,   r-   r0   r/   r.   dotenvs          r   load_dotenvr   R  s\    : a	
 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*   rD   )r+   r,   r-   r/   r.   s        r   dotenv_valuesr     s=    . v~!m dfr   c                     t         j                  j                  |       ry	 t        j                  |       }t        j                  |j                        S # t        t
        f$ r Y yw xY w)zN
    Return True if `path` exists and is either a regular file or a FIFO.
    TF)r   rZ   r   statFileNotFoundErrorOSErrorS_ISFIFOst_mode)rZ   sts     r   r:   r:     sW     
ww~~dWWT] ==$$ w' s   A A('A()utf-8)rr   Fr   )rr   r   )r8   FF)NNFFTr   )NNFTr   )-r=   loggingr   r_   re   r   r   rb   collectionsr   
contextlibr   typingr   r   r   r   r	   r
   r   r   parserr   r   	variablesr   rT   rS   	getLoggerrP   r#   rU   r   r(   r*   rY   rl   r   r   rB   r   r   r   r   r:   rV   r   r   <module>r      sA   	  	    
  # % P P P ) & ''
(			8	$3t 3(7*; @Q P Pl &
P
P
P sm
P c]	
P 
sm eBsGRW$%& 2 %-*-*-* -* 	-*
 -* sm-* 8D>3#$-*f %	!!! ! sm	!
 8D>3!BU3-./ S(3- 28 8 8& %*00"0 0 		0h &* $%.1'".1RW.1 .1 	.1
 .1 sm.1 
.1d &* $%!'"!RW! ! 	!
 sm! 
#x}
!H%7 %t %r   