
    k 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j        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$	 	 	 d0dedededededee         d	eee         eef         fdZ%	 	 d1d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(	 	 	 d2d$ed%ed&ed	efd'Z)	 	 	 	 	 	 d3dee         d)eee                  d*ed ed+edee         d	efd,Z*	 	 	 	 	 d4d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,dS )5    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dS t           j        d                                         } | dv S )z8
    Determine if dotenv loading has been disabled.
    PYTHON_DOTENV_DISABLEDF>   1tyyestrue)osenvironcasefold)values    B/var/www/findabus/venv/lib/python3.11/site-packages/dotenv/main.py_load_dotenv_disabledr      s;      rz11uJ/099;;E222    mappingsc              #   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     r   with_warn_for_invalid_linesr(   #   sX        = 	NNM %    r   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dS )DotEnvNFTdotenv_pathstreamverboseencodinginterpolateoverrider   c                 h    || _         || _        d | _        || _        || _        || _        || _        d S N)r+   r,   _dictr-   r.   r/   r0   )selfr+   r,   r-   r.   r/   r0   s          r   __init__zDotEnv.__init__.   s;     /:)/9=
$'/!,&r   c              #   V  K   | j         rNt          | 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+   _is_file_or_fifoopenr.   r,   r-   r#   infoioStringIO)r4   r,   s     r   _get_streamzDotEnv._get_stream?   s      	" 01A B B 	"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)r0   )r3   parser/   r   resolve_variablesr0   )r4   
raw_valuess     r   dictzDotEnv.dictN   sj    : 	:ZZ\\
 	1$!*t}EEE 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 r2   )r?   r(   r   keyr   )r4   r,   r'   s      r   rA   zDotEnv.parse^   s       	566|F7K7KLL 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)rD   itemsr   r   r0   )r4   kvs      r   set_as_environment_variablesz#DotEnv.set_as_environment_variablesd   sj     yy{{ 	5IIKK%%'' 	" 	"DAqBJt}} !
1tr   rF   c                     |                                  }||v r||         S | j        r!t                              d|| j                   dS ) zKey %s not found in %s.N)rD   r-   r#   r$   r+   )r4   rF   datas      r   getz
DotEnv.gets   sL    yy{{$;;9< 	MNN4c4;KLLLtr   )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 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*   rO   )r+   rX   r.   s      r   get_keyrZ      s'     +th???CCJOOOr   pathc              #     K   t          j        |                                            t          j        d|d          5 }d }	 t          | |          5 }||fV  d d d            n# 1 swxY w Y   n# t          $ r}|}Y d }~nd }~ww xY wd d d            n# 1 swxY w Y   |t          j        |j	        |            d S t          j        |j	                   |d )NwF)moder.   deleter7   )pathlibPathtouchtempfileNamedTemporaryFiler;   BaseExceptionshutilmovenamer   unlink)r[   r.   destr"   sourceerrs         r   rewriterm      sx     
 L		$#	O	O	O SW	dX... %&tn$$$% % % % % % % % % % % % % % % 	 	 	EEEEEE	               }DIt$$$$$
	$)s`    BA4A(A4(A,	,A4/A,	0A43B4
B
>B BB

BB B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| d	| d
}n| d	| 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
    )rn   autoneverzUnknown quote_mode: rn   rt   z'{}''z\'zexport =
r7   FTN)
ValueErrorisalnumformatreplacerm   r(   r   rF   writer%   stringendswith)r+   ro   rp   rq   rr   r.   quote	value_outline_outrk   rj   replacedmissing_newliner'   s                 r   set_keyr      s    444<
<<===(" f;\%9%9%;%;!; 
  !MM,"6"6sE"B"BCC		 	 17Z77)777 009000	x	0	0	0 !NVT2<3G3GHH 	M 	MG{j((

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

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

4   JJx   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! \))s   B7E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.NFr7   Tz/Key %s not removed from %s - key doesn't exist.)r   r[   existsr#   r$   rm   r(   r   rF   r}   r%   r~   )r+   r   rq   r.   removedrk   rj   r'   s           r   	unset_keyr      s:    7>>+&& "A;OOO\!!G	x	0	0	0 4NVT2<3G3GHH 	4 	4G{l**

7+23333		44 4 4 4 4 4 4 4 4 4 4 4 4 4 4  "=|[	
 	
 	
 \!!L  s   AB//B36B3valuesr0   c                 j   i }| D ]\  }}|d }nt          |          }i |r5                    t          j                                       |           n4                    |                               t          j                   d                    fd|D                       }|||<   |S )Nr9   c              3   B   K   | ]}|                               V  d S r2   )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   r0   
new_valuesrh   r   resultatomsr   s          @r   rB   rB      s     ,.J " "e=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[   r   IOErrorisfile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
!
!W__RW\\+rw~%N%NOO
 +Z+ k
!
!
!
!
!
!r   r8   filenameraise_error_if_not_foundusecwdc                    d }d }|s* |            s  |            st          t          dd          rt          j                    }nt          j                    }t
          }|j        j        |k    s)t          j        	                    |j        j                  sI|j
        J |j
        }|j        j        |k     t          j        	                    |j        j                  I|j        j        }t          j                            t          j                            |                    }t          |          D ]5}	t          j                            |	|           }
t          |
          r|
c S 6|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                      t          t          d          st          t          d          rdS 	 t          ddddg          } n# t          $ r Y dS w xY wt          | d           S )	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*  s~    3 	'#u"5"5 	4	j$
|LLLDD" 	 	 	55	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   frozenFNzFile not foundr9   )getattrr   r   getcwd	_getframer   f_codeco_filenamer[   r   f_backr   r   r   r   r:   r   )r   r   r   r   r   r[   framecurrent_fileframe_filenamer   
check_paths              r   find_dotenvr     s   - - -* * *  @"" @llnn @Xu8U8U @y{{ l&,66bgnnL$?
 ?
6 <+++LE	 l&,66bgnnL$?
 ?
6
 1wrw~>>?? &&  W\\'844
J'' 		   (&'''2r   Tr,   r-   r/   c                     t                      rt                              d           dS | |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 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 variableFNr+   r,   r-   r/   r0   r.   )r   r#   debugr   r*   rK   )r+   r,   r-   r0   r/   r.   dotenvs          r   load_dotenvr   R  s    :  a	
 	
 	
 u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*   rD   )r+   r,   r-   r/   r.   s        r   dotenv_valuesr     sK    . v~!mm   dffr   c                     t           j                            |           rdS 	 t          j        |           }n# t          t
          f$ r Y dS w xY wt          j        |j                  S )zN
    Return True if `path` exists and is either a regular file or a FIFO.
    TF)r   r[   r   statFileNotFoundErrorOSErrorS_ISFIFOst_mode)r[   sts     r   r:   r:     sn     
w~~d tWT]]w'   uu =$$$s   8 AA)rW   )rn   FrW   )rn   rW   )r8   FF)NNFFTrW   )NNFTrW   )-r=   loggingr   r`   rf   r   r   rc   collectionsr   
contextlibr   typingr   r   r   r   r	   r
   r   r   parserr   r   	variablesr   rT   rS   	getLoggerrP   r#   rU   r   r(   r*   rZ   rm   r   r   rB   r   r   r   r   r:   rV   r   r   <module>r      s   				  				    



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