o
    Ñ­j[9  ã                   @   sÎ  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 e¡Zd	efd
d„Zdee d	ee fdd„Z G dd„ dƒZ!	d<dededee d	ee fdd„Z"e
	d=dedee ded	eeee ee f  fdd„ƒZ#				d>dedededed edee ded	eee eef fd!d"„Z$			d?ded#ededee ded	eee ef fd$d%„Z%d&eeeee f  d'ed	eeee f fd(d)„Z&ded	ee fd*d+„Z'	,		d@d-ed.ed/ed	efd0d1„Z(					2	dAdee d3eee  d4ed'ed5edee d	efd6d7„Z)				2	dBdee d3eee  d4ed5edee d	eeee f fd8d9„Z*ded	efd:d;„Z+dS )Cé    N)ÚOrderedDict)Úcontextmanager)ÚIOÚDictÚIterableÚIteratorÚMappingÚOptionalÚTupleÚUnioné   )ÚBindingÚparse_stream)Úparse_variableszos.PathLike[str]Úreturnc                  C   s$   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)Úvalue© r   úH/var/www/html/CropPilot/venv/lib/python3.10/site-packages/dotenv/main.pyÚ_load_dotenv_disabled   s   
r   Úmappingsc                 c   s,   � | D ]}|j rt d|jj¡ |V  qd S )Nz;python-dotenv could not parse statement starting at line %s)ÚerrorÚloggerÚwarningÚoriginalÚline)r   Úmappingr   r   r   Úwith_warn_for_invalid_lines    s   €þúr%   c                   @   sÄ   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d„Ze	d
e
ee  fdd„ƒZd
eeee f fdd„Zd
e
eeee f  fdd„Zd
efdd„Zded
ee fdd„ZdS )ÚDotEnvNFTÚdotenv_pathÚstreamÚverboseÚencodingÚinterpolateÚoverrider   c                 C   s.   || _ || _d | _|| _|| _|| _|| _d S ©N)r'   r(   Ú_dictr)   r*   r+   r,   )Úselfr'   r(   r)   r*   r+   r,   r   r   r   Ú__init__+   s   	
zDotEnv.__init__c                 c   sŒ   � | j r't| j ƒr't| j | jd��}|V  W d   ƒ d S 1 s w   Y  d S | jd ur2| jV  d S | jr>t d| j p<d¡ t 	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)r/   r(   r   r   r   Ú_get_stream<   s   €"ÿ
þzDotEnv._get_streamc                 C   sD   | j r| j S |  ¡ }| jrtt|| jd�ƒ| _ | j S t|ƒ| _ | j S )zReturn dotenv as dict)r,   )r.   Úparser+   r   Úresolve_variablesr,   )r/   Ú
raw_valuesr   r   r   ÚdictK   s   ÿ
þzDotEnv.dictc                 c   sZ   � |   ¡ �}tt|ƒƒD ]}|jd ur|j|jfV  qW d   ƒ d S 1 s&w   Y  d S r-   )r9   r%   r   Úkeyr   )r/   r(   r$   r   r   r   r:   [   s   €

€þ"ÿzDotEnv.parsec                 C   sJ   |   ¡ sdS |   ¡  ¡ D ]\}}|tjv r| jsq|dur"|tj|< qdS )zI
        Load the current dotenv as system environment variable.
        FNT)r=   Úitemsr   r   r,   )r/   ÚkÚvr   r   r   Úset_as_environment_variablesa   s   
€z#DotEnv.set_as_environment_variablesr>   c                 C   s2   |   ¡ }||v r|| S | jrt d|| j¡ dS )ú zKey %s not found in %s.N)r=   r)   r    r!   r'   )r/   r>   Údatar   r   r   Úgetp   s   z
DotEnv.get)NFNTT)Ú__name__Ú
__module__Ú__qualname__r	   ÚStrPathr   ÚstrÚboolr0   r   r   r9   r   r=   r
   r:   rB   rE   r   r   r   r   r&   *   s6    ùþ
ýüûúù
ør&   úutf-8r'   Ú
key_to_getr*   c                 C   s   t | d|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&   rE   )r'   rM   r*   r   r   r   Úget_key}   s   
rN   FÚpathÚfollow_symlinksc           
      c   s–  � |r	t j | ¡} z*t| |d�}zt  | ¡}t |j¡r"t |j¡nd }W n t	y1   | 
¡  ‚ w W n tyC   t d¡}d }Y nw tjd|ddt j t j | ¡¡d��>}t |j¡}d }z|� ||fV  W d   ƒ n1 srw   Y  W n t	yŒ }	 z|	}W Y d }	~	nd }	~	ww W d   ƒ n1 s—w   Y  |d u rÂz|d ur«t  ||¡ t  || ¡ W d S  t	yÁ   |jdd� ‚ w |jdd� |d ‚)	Nr1   r3   ÚwFz.tmp_)Úmoder*   ÚdeleteÚprefixÚdirT)Ú
missing_ok)r   rO   Úrealpathr5   ÚlstatÚstatÚS_ISREGÚst_modeÚS_IMODEÚBaseExceptionÚcloseÚFileNotFoundErrorr7   r8   ÚtempfileÚNamedTemporaryFileÚdirnameÚabspathÚpathlibÚPathÚnameÚchmodÚreplaceÚunlink)
rO   r*   rP   ÚsourceÚ	path_statÚoriginal_modeÚdestÚ	dest_pathr   Úerrr   r   r   ÚrewriteŠ   sh   €

ÿýþû
þûÿ€€ÿ€óþrp   ÚalwaysÚ
key_to_setÚvalue_to_setÚ
quote_modeÚexportc                 C   s  |dvrt d|› �ƒ‚|dkp|dko| ¡  }|r$d | dd¡¡}n|}|r2d|› d	|› d
�}	n|› d	|› d
�}	t| ||d��A\}
}d}d}tt|
ƒƒD ]}|j|kr]| |	¡ d}qN| |j	j
¡ |j	j
 d
¡ }qN|s{|rv| d
¡ | |	¡ W d  ƒ n1 s…w   Y  d||fS )aS  
    Adds or Updates a key/value to the given .env

    The target .env file is created if it doesn't exist.

    This function doesn't follow symlinks by default, to avoid accidentally
    modifying a file at a potentially untrusted path. If you don't need this
    protection and need symlinks to be followed, use `follow_symlinks`.
    )rq   ÚautoÚneverzUnknown quote_mode: rq   rv   z'{}'ú'z\'zexport ú=Ú
©r*   rP   FTN)Ú
ValueErrorÚisalnumÚformatrh   rp   r%   r   r>   Úwriter"   ÚstringÚendswith)r'   rr   rs   rt   ru   r*   rP   ÚquoteÚ	value_outÚline_outrj   rm   ÚreplacedÚmissing_newliner$   r   r   r   Úset_keyÁ   s:   ÿ



€ð
r‡   Úkey_to_unsetc           	      C   s¨   t j | ¡st d| ¡ d|fS d}t| ||d��"\}}tt|ƒƒD ]}|j|kr,d}q"| 	|j
j¡ q"W d  ƒ n1 s>w   Y  |sPt d|| ¡ d|fS ||fS )a„  
    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.

    This function doesn't follow symlinks by default, to avoid accidentally
    modifying a file at a potentially untrusted path. If you don't need this
    protection and need symlinks to be followed, use `follow_symlinks`.
    z(Can't delete from %s - it doesn't exist.NFr{   Tz/Key %s not removed from %s - key doesn't exist.)r   rO   Úexistsr    r!   rp   r%   r   r>   r   r"   r€   )	r'   rˆ   rt   r*   rP   Úremovedrj   rm   r$   r   r   r   Ú	unset_keyø   s&   
üü
ÿr‹   Úvaluesr,   c                    s‚   i }| D ]:\}}|d u rd }n+t |ƒ}i ‰ |r#ˆ  tj¡ ˆ  |¡ nˆ  |¡ ˆ  tj¡ d ‡ fdd„|D ƒ¡}|||< q|S )Nr3   c                 3   s   � | ]}|  ˆ ¡V  qd S r-   )Úresolve)Ú.0Úatom©Úenvr   r   Ú	<genexpr>3  s   € z$resolve_variables.<locals>.<genexpr>)r   Úupdater   r   Újoin)rŒ   r,   Ú
new_valuesrf   r   ÚresultÚatomsr   r�   r   r;   !  s   

r;   c                 c   s€   � t j | ¡stdƒ‚t j | ¡rt j | ¡} d}t j | ¡}||kr>|V  t j t j |t jj¡¡}||}}||ks#dS dS )zL
    Yield directories starting from the given directory up to the root
    zStarting path not foundN)	r   rO   r‰   ÚIOErrorÚisfilerb   rc   r”   Úpardir)rO   Úlast_dirÚcurrent_dirÚ
parent_dirr   r   r   Ú_walk_to_root:  s   €
ýrž   r2   ÚfilenameÚraise_error_if_not_foundÚusecwdc                 C   sæ   dd„ }dd„ }|s|ƒ s|ƒ st tddƒrt ¡ }n:t ¡ }t}|jj|ks/tj 	|jj¡sG|j
dus6J ‚|j
}|jj|ks/tj 	|jj¡r/|jj}tj tj |¡¡}t|ƒD ]}	tj |	| ¡}
t|
ƒrj|
  S qY|rqt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                  S   sP   t tdƒs
t tdƒrdS ztddddgd�} W n
 ty!   Y dS 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)Úmainr   r   r   Ú_is_interactiveW  s   ÿz$find_dotenv.<locals>._is_interactivec                   S   s   t  ¡ d uS r-   )r¨   Úgettracer   r   r   r   Ú_is_debuggera  s   z!find_dotenv.<locals>._is_debuggerÚfrozenFNzFile not foundr3   )Úgetattrr¨   r   ÚgetcwdÚ	_getframer¥   Úf_codeÚco_filenamerO   r‰   Úf_backrb   rc   rž   r”   r4   r˜   )rŸ   r    r¡   r¬   r®   rO   ÚframeÚcurrent_fileÚframe_filenamerb   Ú
check_pathr   r   r   Úfind_dotenvL  s0   

ÿüÿÿrº   Tr(   r)   r+   c                 C   sF   t ƒ r
t d¡ dS | du r|du rtƒ } t| |||||d�}| ¡ 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+   r,   r*   )r   r    Údebugrº   r&   rB   )r'   r(   r)   r,   r+   r*   Údotenvr   r   r   Úload_dotenv  s    ÿúr¾   c                 C   s.   | du r|du rt ƒ } t| |||d|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*   r   r   r   Údotenv_values°  s   úùr¿   c              	   C   sD   t j | ¡rdS zt  | ¡}W n ttfy   Y dS w t |j¡S )zN
    Return True if `path` exists and is either a regular file or a FIFO.
    TF)r   rO   r™   rY   r_   ÚOSErrorÚS_ISFIFOr[   )rO   Ústr   r   r   r4   Ô  s   ÿr4   )rL   )F)rq   FrL   F)rq   rL   F)r2   FF)NNFFTrL   )NNFTrL   ),r7   Úloggingr   rd   rY   r¨   r`   Úcollectionsr   Ú
contextlibr   Útypingr   r   r   r   r   r	   r
   r   Úparserr   r   Ú	variablesr   rJ   rI   Ú	getLoggerrF   r    rK   r   r%   r&   rN   rp   r‡   r‹   r;   rž   rº   r¾   r¿   r4   r   r   r   r   Ú<module>   s   (


Výÿþý
üýÿþýü:ùÿþýüûúù
ø:ûÿþýüû
ú)ÿþ
ýýÿþý
ü4úÿ
þýüûú
ù2ûÿ
þýüû
ú$