Format: application/x-python-code
⬇ Download File (10.4 KB)
   1  o
   2  
   3  +'hd0�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
   4  Z
   5  ddlmZm
   6  Z
   7  mZmZmZmZmZmZddlmZmZddlmZeedfZe�e�Zd	eed
   8  eefdd�ZGd
   9  d�d�Z	d7dededeed
  10  eefdd�Z e
  11  dedeed
  12  eeeeeeffdd��Z!			d8dedededede"deed
  13  eee"eeffdd�Z#		d9ded ededeed
  14  eee"eff
  15  d!d"�Z$d#eeeeefd$e"d
  16  eeeeffd%d&�Z%ded
  17  eefd'd(�Z&	)		d:d*ed+e"d,e"d
  18  efd-d.�Z'					/	d;deed0eeed1e"d$e"d2e"deed
  19  e"fd3d4�Z(				/	d<deed0eeed1e"d2e"deed
  20  e
  21  eeeffd5d6�Z)dS)=�N)�OrderedDict)�contextmanager)�IO�Dict�Iterable�Iterator�Mapping�Optional�Tuple�Union�)�Binding�parse_stream)�parse_variableszos.PathLike[str]�mappings�returnccs,�|D]}|jrt�d|jj�|VqdS)Nz;python-dotenv could not parse statement starting at line %s)�error�logger�warning�original�line)r�mapping�r�AC:\Users\shubh\Videos\agent\nova\Lib\site-packages\dotenv/main.py�with_warn_for_invalid_liness���rc@s�eZdZ					ddeedeeededeeded	ed
  22  dfdd�Ze	d
  23  e
  24  eefd
  25  d��Zd
  26  eeeeffdd�Z
  27  d
  28  e
  29  eeeeffdd�Zd
  30  efdd�Zded
  31  eefdd�ZdS)�DotEnvNFT�dotenv_path�stream�verbose�encoding�interpolate�overridercCs.||_||_d|_||_||_||_||_dS�N)rr�_dictrrr r!)�selfrrrrr r!rrr�__init__#s	
  32  zDotEnv.__init__ccs��|jr)tj�|j�r)t|j|jd��}|VWd�dS1s"wYdS|jdur4|jVdS|jr@t�	d|jp>d�t
  33  �d�VdS)N�rz3python-dotenv could not find configuration file %s.�.env�)r�os�path�isfile�openrrrr�info�io�StringIO)r$rrrr�_get_stream4s�"�
  34  �zDotEnv._get_streamcCsD|jr|jS|��}|jrtt||jd��|_|jSt|�|_|jS)zReturn dotenv as dict)r!)r#�parser r�resolve_variablesr!)r$Z
  35  raw_valuesrrr�dictCs�
  36  �zDotEnv.dictccsZ�|���}tt|��D]}|jdur|j|jfVqWd�dS1s&wYdSr")r0rr�key�value)r$rrrrrr1Ss�
  37  
  38  ��"�zDotEnv.parsecCsJ|��sdS|����D]\}}|tjvr|jsq|dur"|tj|<qdS)zI
  39          Load the current dotenv as system environment variable.
  40          FNT)r3�itemsr)�environr!)r$�k�vrrr�set_as_environment_variablesYs
  41  �z#DotEnv.set_as_environment_variablesr4cCs2|��}||vr||S|jrt�d||j�dS)� zKey %s not found in %s.N)r3rrrr)r$r4�datarrr�gethsz
  42  DotEnv.get)NFNTT)�__name__�
  43  __module__�__qualname__r	�StrPathr�str�boolr%rrr0rr3r
  44  r1r:r=rrrrr"s6��
  45  �����
  46  �r�utf-8r�
  47  key_to_getrcCst|d|d��|�S)z
  48      Get the value of a given key from the given .env.
  49  
  50      Returns `None` if the key isn't found or doesn't have a value.
  51      T)rr)rr=)rrErrrr�get_keyus
  52  rFr*ccs��t�|���tjd|dd��<}d}zt||d��
  53  }||fVWd�n1s*wYWntyD}z|}WYd}~nd}~wwWd�n1sOwY|durat�|j	|�dSt
  54  �|j	�|d�)N�wF)�moder�deleter&)�pathlib�Path�touch�tempfile�NamedTemporaryFiler,�
  55  BaseException�shutil�move�namer)�unlink)r*r�destr�source�errrrr�rewrite�s&�������rW�alwaysF�
  56  key_to_set�value_to_set�
  57  quote_mode�exportcCs|dvrtd|����|dkp|dko|��}|r$d�|�dd��}n|}|r2d|�d	|�d
  58  �}n|�d	|�d
  59  �}t||d��A\}	}
  60  d}d}tt|	��D]}
  61  |
  62  j|kr\|
  63  �|�d
  64  }qM|
  65  �|
  66  j	j
  67  �|
  68  j	j
  69  �d
  70  �}qM|sz|ru|
  71  �d
  72  �|
  73  �|�Wd�n1s�wYd
  74  ||fS)z�
  75      Adds or Updates a key/value to the given .env
  76  
  77      If the .env path given doesn't exist, fails instead of risking creating
  78      an orphan .env somewhere in the filesystem
  79      )rX�auto�neverzUnknown quote_mode: rXr]z'{}'�'z\'zexport �=�
  80  r&FTN)�
  81  ValueError�isalnum�format�replacerWrrr4�writer�string�endswith)rrYrZr[r\r�quoteZ	value_outZline_outrUrTZreplacedZmissing_newlinerrrr�set_key�s6�
  82  
  83  
  84  
  85  ��
  86  rj�key_to_unsetcCs�tj�|�st�d|�d|fSd}t||d��"\}}tt|��D]}|j|kr+d}q!|�	|j
  87  j�q!Wd�n1s=wY|sOt�d||�d|fS||fS)z�
  88      Removes a given key from the given `.env` file.
  89  
  90      If the .env path given doesn't exist, fails.
  91      If the given key doesn't exist in the .env, fails.
  92      z(Can't delete from %s - it doesn't exist.NFr&Tz/Key %s not removed from %s - key doesn't exist.)r)r*�existsrrrWrrr4rfrrg)rrkr[r�removedrUrTrrrr�	unset_key�s"
  93  ���rn�valuesr!cs�i}|D]:\}}|durd}n+t|�}i�|r#��tj���|�n��|���tj�d��fdd�|D��}|||<q|S)Nr(c3s�|]}|���VqdSr")�resolve)�.0Zatom��envrr�	<genexpr>�s�z$resolve_variables.<locals>.<genexpr>)r�updater)r7�join)ror!�
  94  new_valuesrRr5�resultZatomsrrrrr2�s
  95  
  96  r2ccs��tj�|�std��tj�|�rtj�|�}d}tj�|�}||kr>|Vtj�tj�|tjj��}||}}||ks#dSdS)zL
  97      Yield directories starting from the given directory up to the root
  98      zStarting path not foundN)	r)r*rl�IOErrorr+�dirname�abspathrv�pardir)r*Zlast_dirZcurrent_dir�
  99  parent_dirrrr�
 100  _walk_to_roots�
 101  �r~r'�filename�raise_error_if_not_found�usecwdcCs�dd�}dd�}|s|�s|�sttdd�rt��}n:t��}t}|jj|ks/tj�	|jj�sG|j
 102  dus6J�|j
 103  }|jj|ks/tj�	|jj�r/|jj}tj�tj�|��}t
 104  |�D]}	tj�|	|�}
 105  tj�|
 106  �rl|
 107  SqY|rstd��d	S)
 108  z�
 109      Search in increasingly higher folders for the given file
 110  
 111      Returns path to the file if found, or an empty string otherwise
 112      cSs8ztddddgd�}Wn
 113  tyYdSwt|d�S)z<Decide whether this is running in a REPL or IPython notebook�__main__N�__file__)�fromlistF)�
 114  __import__�ModuleNotFoundError�hasattr)�mainrrr�_is_interactives�z$find_dotenv.<locals>._is_interactivecSst��duSr")�sys�gettracerrrr�_is_debugger'sz!find_dotenv.<locals>._is_debugger�frozenFNzFile not foundr()�getattrr�r)�getcwd�	_getframer��f_code�co_filenamer*rl�f_backrzr{r~rvr+ry)rr�r�r�r�r*�frameZcurrent_file�frame_filenamerz�
 115  check_pathrrr�find_dotenvs0
 116  ����r�Trrr cCs2|dur|durt�}t||||||d�}|��S)a�Parse a .env file and then load all the variables found as environment variables.
 117  
 118      Parameters:
 119          dotenv_path: Absolute or relative path to .env file.
 120          stream: Text stream (such as `io.StringIO`) with .env content, used if
 121              `dotenv_path` is `None`.
 122          verbose: Whether to output a warning the .env file is missing.
 123          override: Whether to override the system environment variables with the variables
 124              from the `.env` file.
 125          encoding: Encoding to be used to read the file.
 126      Returns:
 127          Bool: True if at least one environment variable is set else False
 128  
 129      If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
 130      .env file with it's default parameters. If you need to change the default parameters
 131      of `find_dotenv()`, you can explicitly call `find_dotenv()` and pass the result
 132      to this function as `dotenv_path`.
 133      N�rrrr r!r)r�rr:)rrrr!r rZdotenvrrr�load_dotenvEs�r�cCs.|dur|durt�}t||||d|d���S)a�
 134      Parse a .env file and return its content as a dict.
 135  
 136      The returned dict will have `None` values for keys without values in the .env file.
 137      For example, `foo=bar` results in `{"foo": "bar"}` whereas `foo` alone results in
 138      `{"foo": None}`
 139  
 140      Parameters:
 141          dotenv_path: Absolute or relative path to the .env file.
 142          stream: `StringIO` object with .env content, used if `dotenv_path` is `None`.
 143          verbose: Whether to output a warning if the .env file is missing.
 144          encoding: Encoding to be used to read the file.
 145  
 146      If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used to find the
 147      .env file.
 148      NTr�)r�rr3)rrrr rrrr�
 149  dotenv_valuesms��r�)rD)rXFrD)rXrD)r'FF)NNFFTrD)NNFTrD)*r.�loggingr)rJrPr�rM�collectionsr�
 150  contextlibr�typingrrrrrr	r
 151  r�parserr
 152  r�	variablesrrBrA�	getLoggerr>rrrrFrWrCrjrnr2r~r�r�r�rrrr�<module>s�(
 153  
 154  V����
 155  �
 156  ����������
 157  �3�����
 158  �!��
 159  �����
 160  �2��
 161  �����
 162  �)��
 163  �����