
    fj                     P    d Z ddlZddlZddlmZ ddlmZ dZ G d de      Z	d	 Z
y)
zdistutils.pypirc

Provides the PyPIRCCommand class, the base class for the command classes
that uses .pypirc in the distutils.command package.
    N)RawConfigParser   )CommandzE[distutils]
index-servers =
    pypi

[pypi]
username:%s
password:%s
c                   `    e Zd ZdZdZdZdZdZddde dfd	gZd
gZ	d Z
d Zd Zd Zd Zd Zy)PyPIRCCommandz6Base command that knows how to handle the .pypirc filezhttps://upload.pypi.org/legacy/pypiNzrepository=rzurl of repository [default: ])show-responseNz&display full response text from serverr   c                 |    t         j                  j                  t         j                  j                  d      d      S )zReturns rc file path.~z.pypirc)ospathjoin
expanduserselfs    P/app/.heroku/python/lib/python3.12/site-packages/setuptools/_distutils/config.py_get_rc_filezPyPIRCCommand._get_rc_file'   s&    ww||BGG..s3Y??    c                    | j                         }t        j                  |t        j                  t        j                  z  d      }t        j
                  |dd      5 }|j                  t        ||fz         ddd       y# 1 sw Y   yxY w)zCreates a default .pypirc file.i  wutf-8encodingN)r   r   openO_CREATO_WRONLYfdopenwriteDEFAULT_PYPIRC)r   usernamepasswordrcrawfs         r   _store_pypirczPyPIRCCommand._store_pypirc+   sl     ggb"**r{{2E:YYsC'2 	;aGGNh%99:	; 	; 	;s   BBc                 "   | j                         }t        j                  j                  |      r| j	                  d|        | j
                  xs | j                  }t               }|j                  |d       |j                         }d|v r|j                  dd      }|j                  d      D cg c]%  }|j                         dk7  r|j                         ' }}|g k(  r
d|v rdg}ni S |D ]  }d	|i}|j                  |d
      |d
<   d| j                  fd| j                  fdfD ]2  \  }	}
|j                  ||	      r|j                  ||	      ||	<   .|
||	<   4 |dk(  r#|| j                  dfv r| j                  |d<   |c S |d	   |k(  s	|d   |k(  s|c S  i S d|v red}|j                  |d      r|j                  |d      }n| j                  }|j                  |d
      |j                  |d      ||| j                  dS i S c c}w )zReads the .pypirc file.zUsing PyPI login from r   r   	distutilszindex-servers
 r   serverr"   
repositoryrealm)r#   Nzserver-loginr#   )r"   r#   r-   r,   r.   )r   r   r   existsannouncer-   DEFAULT_REPOSITORYr   readsectionsgetsplitstripDEFAULT_REALM
has_option)r   r$   r-   configr3   index_serversr,   _serverscurrentkeydefaults              r   _read_pypirczPyPIRCCommand._read_pypirc2   sH    77>>"MM22$78CD,C,CJ$&FKKWK-(Hh& &

; H #0"5"5d";||~+ LLN 
 r>)$*8  "	&F'0G*0**VZ*HGJ' &t'>'>? $"4"45*)W
 ",,VS9+1::fc+BGCL+2GCL) 'J//; - 150G0G-&  )Z7"<0J>&; 'Z 	  8+'$$V\:!'FL!AJ!%!8!8J &

6: > &

6: >",$!//  	us   6*Hc                 v    |j                  dd      }|j                         j                  t        |            S )z%Read and decode a PyPI HTTP response.content-typez
text/plain)	getheaderr2   decode_extract_encoding)r   responsecontent_types      r   _read_pypi_responsez!PyPIRCCommand._read_pypi_response{   s1    )).,G}}%%&7&EFFr   c                 .    d| _         d| _        d| _        y)zInitialize options.NF)r-   r.   show_responser   s    r   initialize_optionsz PyPIRCCommand.initialize_options   s    
"r   c                 z    | j                   | j                  | _         | j                  | j                  | _        yy)zFinalizes options.N)r-   r1   r.   r7   r   s    r   finalize_optionszPyPIRCCommand.finalize_options   s5    ??""55DO::++DJ r   )__name__
__module____qualname____doc__r1   r7   r-   r.   user_optionsboolean_optionsr   r'   r?   rG   rJ   rL    r   r   r   r      sh    @:MJE 
;<N;OqQRIL
 ''O@;GRG
#,r   r   c                     t         j                  j                         }| |d<   |d   j                  j	                  dd      S )z{
    >>> _extract_encoding('text/plain')
    'ascii'
    >>> _extract_encoding('text/html; charset="utf8"')
    'utf8'
    rA   charsetascii)emailmessageEmailMessageparamsr4   )rF   msgs     r   rD   rD      s>     --
$
$
&C&C~%%)))W==r   )rP   email.messagerW   r   configparserr   cmdr   r!   r   rD   rS   r   r   <module>r_      s3     	 ( s,G s,l	>r   