o
    ;ÊÆhœ.  ã                   @   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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e d
ee fdd„ZG dd„ dƒZ	d7dededee d
ee fdd„Ze	dedee d
eeee ee f  fdd„ƒZ 			d8dedededede!dee d
eee! eef fdd„Z"		d9ded edede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d-d.„Z&					/	d;dee d0eee  d1e!d$e!d2e!dee d
e!fd3d4„Z'				/	d<dee d0eee  d1e!d2e!dee d
eeee f fd5d6„Z(dS )=é    N)ÚOrderedDict)Úcontextmanager)ÚIOÚDictÚIterableÚIteratorÚMappingÚOptionalÚTupleÚUnioné   )ÚBindingÚparse_stream)Úparse_variableszos.PathLike[str]ÚmappingsÚreturnc                 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   Úmapping© r   úX/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/dotenv/main.pyÚ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 | j ¡r)t| j | jd��}|V  W d   ƒ d S 1 s"w   Y  d S | jd ur4| 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   ÚosÚpathÚisfileÚopenr   r   r   r   ÚinfoÚioÚStringIO)r$   r   r   r   r   Ú_get_stream4   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   ÚdictC   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"   )r0   r   r   ÚkeyÚvalue)r$   r   r   r   r   r   r1   Q   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)r4   Úitemsr)   Úenvironr!   )r$   ÚkÚvr   r   r   Úset_as_environment_variablesW   s   
€z#DotEnv.set_as_environment_variablesr5   c                 C   s2   |   ¡ }||v r|| S | jrt d|| j¡ dS )z	
        zKey %s not found in %s.N)r4   r   r   r   r   )r$   r5   Údatar   r   r   Úgetf   s   z
DotEnv.get)NFNTT)Ú__name__Ú
__module__Ú__qualname__r	   ÚStrPathr   ÚstrÚboolr%   r   r   r0   r   r4   r
   r1   r;   r=   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   r=   )r   rE   r   r   r   r   Úget_keyt   s   
rF   r*   c              	   c   sà   � t j | ¡s#t| d|d��}| d¡ W d   ƒ n1 sw   Y  tjd|dd��4}zt| |d��}||fV  W d   ƒ n1 sCw   Y  W n tyW   t  |j	¡ ‚ w W d   ƒ n1 sbw   Y  t
 |j	| ¡ d S )NÚw)Úmoder   r(   F)rH   r   Údeleter&   )r)   r*   r+   r,   ÚwriteÚtempfileÚNamedTemporaryFileÚBaseExceptionÚunlinkÚnameÚshutilÚmove)r*   r   ÚsourceÚdestr   r   r   Úrewrite�   s$   €ÿÿ€þ€ürT   ÚalwaysFÚ
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}qM|
 |j	j
¡ |j	j
 d
¡ }qM|sz|ru|
 d
¡ |
 |¡ W d  ƒ n1 s„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
    )rU   ÚautoÚneverzUnknown quote_mode: rU   rZ   z'{}'ú'z\'zexport ú=Ú
r&   FTN)Ú
ValueErrorÚisalnumÚformatÚreplacerT   r   r   r5   rJ   r   ÚstringÚendswith)r   rV   rW   rX   rY   r   ÚquoteÚ	value_outÚline_outrR   rS   ÚreplacedÚmissing_newliner   r   r   r   Úset_key“   s6   þ



€ó
rj   Ú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  |sOt 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.NFr&   Tz/Key %s not removed from %s - key doesn't exist.)r)   r*   Úexistsr   r   rT   r   r   r5   rJ   r   rc   )r   rk   rX   r   ÚremovedrR   rS   r   r   r   r   Ú	unset_keyÄ   s   
üÿrn   Ú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 )Nr(   c                 3   s   � | ]}|  ˆ ¡V  qd S r"   )Úresolve)Ú.0Úatom©Úenvr   r   Ú	<genexpr>õ   s   € z$resolve_variables.<locals>.<genexpr>)r   Úupdater)   r8   Újoin)ro   r!   Ú
new_valuesrO   r6   ÚresultÚatomsr   rs   r   r2   ã   s   

r2   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)   r*   rl   ÚIOErrorr+   ÚdirnameÚabspathrw   Úpardir)r*   Úlast_dirÚcurrent_dirÚ
parent_dirr   r   r   Ú_walk_to_rootü   s   €
ýr‚   r'   ÚfilenameÚraise_error_if_not_foundÚusecwdc           
      C   s¼   dd„ }|s|ƒ st tddƒrt ¡ }n*t ¡ }t}|jj|kr0|jdus'J ‚|j}|jj|ks |jj}tj	 
tj	 |¡¡}t|ƒD ]}tj	 || ¡}	tj	 |	¡rU|	  S qB|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                  S   s   t ddddgd�} t| dƒ S )z> Decide whether this is running in a REPL or IPython notebook Ú__main__NÚ__file__)Úfromlist)Ú
__import__Úhasattr)Úmainr   r   r   Ú_is_interactive  s   z$find_dotenv.<locals>._is_interactiveÚfrozenFNzFile not foundr(   )ÚgetattrÚsysr)   ÚgetcwdÚ	_getframer‡   Úf_codeÚco_filenameÚf_backr*   r|   r}   r‚   rw   r+   r{   )
rƒ   r„   r…   rŒ   r*   ÚframeÚcurrent_fileÚframe_filenamer|   Ú
check_pathr   r   r   Úfind_dotenv  s&   
þÿr™   Tr   r   r    c                 C   s2   | 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.
    N©r   r   r   r    r!   r   )r™   r   r;   )r   r   r   r!   r    r   Údotenvr   r   r   Úload_dotenv7  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   r4   )r   r   r   r    r   r   r   r   Údotenv_values]  s   úùr�   )rD   )rU   FrD   )rU   rD   )r'   FF)NNFFTrD   )NNFTrD   ))r.   Úloggingr)   rP   r�   rK   Úcollectionsr   Ú
contextlibr   Útypingr   r   r   r   r   r	   r
   r   Úparserr   r   Ú	variablesr   rB   rA   Ú	getLoggerr>   r   r   r   rF   rT   rC   rj   rn   r2   r‚   r™   rœ   r�   r   r   r   r   Ú<module>   sö    (

Uýÿþý
üÿþýúÿþýüûú
ù4üÿþýü
ûÿþ
ýýÿþý
ü*úÿ
þýüûú
ù'ûÿ
þýüûú