
    +h                        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 	 d dlZddlmZmZmZ ddlmZ d	 Z ej4                          ej6                  d
d e        ej8                  d      d       ej6                  ddd ej:                  g d      d       ej6                  dddej<                  d       ej>                  e      ej@                  dejB                  de	de	de	ddf
d                                          Z"ed ejF                  deee$      fd!       Z%e"jM                         ej@                   ej6                  d"d# ej:                  g d$      d%      dejB                  d&e'ddfd'                     Z(e"jM                         ej@                   ejR                  d(d)       ejR                  d*d)      dejB                  d(e	d*e	ddfd+                            Z*e"jM                         ej@                   ejR                  d(d)      dejB                  d(e	ddfd,                     Z+e"jM                         ej@                   ejR                  d(d)      dejB                  d(e	ddfd-                     Z,e"jM                  d.di/      ej@                   ej6                  d0dd12       ejR                  d3d4ejZ                  5      dejB                  d6e'd3ee$   ddfd7                            Z.d8ee$   d9e
e$e$f   de/fd:Z0y# e$ r1 ej                   j#                  d        ej$                  d       Y #w xY w);    N)contextmanager)Popen)AnyDictIOIteratorListzkIt seems python-dotenv is not installed with cli option. 
Run pip install "python-dotenv[cli]" to fix this.   )dotenv_valuesset_key	unset_key)__version__c                      	 t        j                         } t         j                  j	                  | d      }|S # t        $ r Y yw xY w)zZ
    Return a path for the ${pwd}/.env file.

    If pwd does not exist, return None.
    Nz.env)osgetcwdFileNotFoundErrorpathjoin)cwdr   s     =/var/www/html/venv/lib/python3.12/site-packages/dotenv/cli.pyenumerate_envr      sA    iik 77<<V$DK  s   8 	AAz-fz--fileT)	file_okayzNLocation of the .env file, defaults to .env file in current working directory.)defaulttypehelpz-qz--quotealways)r   neverautozbWhether to quote or not the variable values. Default mode is always. This does not affect parsing.z-ez--exportFz;Whether to write the dot file as an executable bash script.)versionctxfilequoteexportreturnc                     |||d| _         y)zAThis script is used to set, get or unset values from a .env file.)QUOTEEXPORTFILEN)obj)r    r!   r"   r#   s       r   clir*   "   s     >CG    r   c              #      K   	 t        |       5 }| ddd       y# 1 sw Y   yxY w# t        $ r3}t        d| t        j                         t        d       Y d}~yd}~ww xY ww)z~
    Open a file and yield the corresponding (decoded) stream.

    Exits with error code 2 if the file cannot be opened.
    NzError opening env file: )r!      )openOSErrorprintsysstderrexit)r   streamexcs      r   stream_filer6   3   s[     $Z 	6L	 	 	 (.SZZ@QsC   A() ) A(&) A() 	A%)A A( A%%A(z--formatsimple)r7   jsonshellr#   zlThe format in which to display the list. Default format is simple, which displays name=value without quotes.formatc                    | j                   d   }t        |      5 }t        |      }ddd       |dk(  r,t        j                  t        j                  dd             y|dk(  rd	nd
}t              D ]?  }||   }||dv rt        j                  |      }t        j                  | | d|        A y# 1 sw Y   xY w)z!Display all the stored key/value.r(   r4   Nr8   r-   T)indent	sort_keysr#   zexport  )r#   r9   =)
r)   r6   r   clickechor8   dumpssortedshlexr"   )r    r:   r!   r4   valuesprefixkvs           r   listrJ   C   s     776?D	T	 .ff-. 

4::fQ$?@$0b 	/Aq	A}00AA

fXaS!-.	/. .s   B88Ckey)requiredvaluec                     | j                   d   }| j                   d   }| j                   d   }t        |||||      \  }}}|rt        j                  | d|        yt	        d       y)zStore the given key/value.r(   r&   r'   r@   r
   N)r)   r   rA   rB   r3   )r    rK   rM   r!   r"   r#   successs          r   setrP   \   sg     776?DGGGEWWXF!$UE6BGS%

cU!E7#$Qr+   c                     | j                   d   }t        |      5 }t        |      }ddd       j                  |      }|rt	        j
                  |       yt        d       y# 1 sw Y   >xY w)z%Retrieve the value for the given key.r(   r<   Nr
   )r)   r6   r   getrA   rB   r3   )r    rK   r!   r4   rF   stored_values         r   rR   rR   l   s_    
 776?D	T	 .ff-. ::c?L

< Q. .s   A%%A.c                     | j                   d   }| j                   d   }t        |||      \  }}|rt        j                  d|        yt	        d       y)zRemoves the given key.r(   r&   zSuccessfully removed r
   N)r)   r   rA   rB   r3   )r    rK   r!   r"   rO   s        r   unsetrU   }   sO    
 776?DGGGET3.LGS

*3%01Qr+   ignore_unknown_options)context_settingsz--override/--no-overridezKOverride variables from the environment file with those from the .env file.)r   r   commandline)nargsr   overridec                    | j                   d   }t        j                  j                  |      st	        j
                  d| d|       t        |      j                         D ci c]  \  }}||s|t        j                  vr||  }}}|s t	        j                  d       t        d       t        ||      }t        |       yc c}}w )z/Run command with environment variables present.r(   zInvalid value for '-f' "z" does not exist.)r    NzNo command given.r
   )r)   r   r   isfilerA   BadParameterr   itemsenvironrB   r3   run_command)r    r[   rX   r!   rH   rI   dotenv_as_dictrets           r   runrd      s     776?D77>>$  (.?@
 	
 $D)//1Q=h!2::*= 	
1N  

&'Q
k>
2CIs   &#Ccommandenvc                     t         j                  j                         }|j                  |       t	        | ddd|      }|j                         \  }}|j                  S )aw  Run command in sub process.

    Runs the command in a sub process with the variables from `env`
    added in the current environment variables.

    Parameters
    ----------
    command: List[str]
        The command and it's parameters
    env: Dict
        The additional environment variables

    Returns
    -------
    int
        The return code of the command

    Tr   F)universal_newlinesbufsizer9   rf   )r   r`   copyupdater   communicate
returncode)re   rf   cmd_envp_s        r   ra   ra      sS    * jjooGNN3g!%		A
 ==?DAq<<r+   )1r8   r   rE   r1   
contextlibr   
subprocessr   typingr   r   r   r   r	   rA   ImportErrorr2   writer3   mainr   r   r   r   r   r   groupoptionPathChoiceBOOLversion_optionpass_contextContextr*   PathLikestrr6   re   boolrJ   argumentrP   rR   rU   UNPROCESSEDrd   intra    r+   r   <module>r      s    	  
 %  0 0 4 3   dHmo5::-ce dIx5<< ;<wy dJ::PR k*?U]] ?# ?c ?3 ?4 ?  +Rye ?
 bkk hr#w&7   j(5<< EF?@/emm /T /d /	@  /& %$'	U]] 	 	S 	T 	 ( &  	 %U]]    &   %u}} 3 4  &   7>?	V
 Re.?.?@U]] d c t  A  @*c c3h C {  JJ I JCHHQKs   L 2MM