
    f.                     |    d 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 ddlmZ  G d d	e      Zd
 Zy)zhdistutils.command.register

Implements the Distutils 'register' command (register with the repository).
    N)log)warn   always_iterable)PyPIRCCommandc                       e Zd ZdZej
                  ddgz   Zej                  g dz   Zdd fgZd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd ZddZy)registerz7register the distribution with the Python package index)list-classifiersNz list the valid Trove classifiers)strictNzBWill stop the registering if the meta-data are not fully compliant)verifyr   r   checkc                      y)NT selfs    Z/app/.heroku/python/lib/python3.12/site-packages/setuptools/_distutils/command/register.py<lambda>zregister.<lambda>$   s    4    c                 J    t        j                  |        d| _        d| _        y )NF)r   initialize_optionslist_classifiersr   r   s    r   r   zregister.initialize_options&   s    ((. %r   c                     t        j                  |        d| j                  fdd}|| j                  j                  d<   y )Nr
   )r
      )r   restructuredtextr   )r   finalize_optionsr   distributioncommand_options)r   check_optionss     r   r   zregister.finalize_options+   sA    &&t, "4;;/ /
 6C))'2r   c                 $   | j                          | j                          | j                         D ]  }| j                  |        | j                  r| j                          y | j                  r| j                          y | j                          y N)	r   _set_configget_sub_commandsrun_commanddry_runverify_metadatar   classifierssend_metadata)r   cmd_names     r   runzregister.run4   ss     --/HX& 0 <<  """ r   c                     t        dt               | j                  j                  d      }|j	                          | j
                  |_        d|_        |j                          y)zDeprecated API.zVdistutils.command.register.check_metadata is deprecated; use the check command insteadr   TN)r   DeprecationWarningr   get_command_objensure_finalizedr   r   r*   )r   r   s     r   check_metadatazregister.check_metadataC   sR    ,	

 !!11': {{!%		r   c                 @   | j                         }|i k7  r0|d   | _        |d   | _        |d   | _        |d   | _        d| _        y	| j                  d| j                  fvrt        | j                   d      | j                  dk(  r| j                  | _        d| _        y	)
z0Reads the configuration file and set attributes.usernamepassword
repositoryrealmTpypiz not found in .pypircFN)_read_pypircr1   r2   r3   r4   
has_configDEFAULT_REPOSITORY
ValueError)r   configs     r   r"   zregister._set_configP   s    ""$R<":.DM":.DM$\2DODJ"DOvt/F/F&GG DOO#44I!JKK&("&"9"9#DOr   c                     | j                   dz   }t        j                  j                  |      }t	        j
                  | j                  |             y)z.Fetch the list of classifiers from the server.z?:action=list_classifiersN)r3   urllibrequesturlopenr   info_read_pypi_response)r   urlresponses      r   r'   zregister.classifiers`   s<    oo ;;>>))#.))(34r   c                 x    | j                  | j                  d            \  }}t        j                  d||       y)z<Send the metadata to the package index server to be checked.r   Server response (%s): %sN)post_to_serverbuild_post_datar   r?   )r   coderesults      r   r&   zregister.verify_metadataf   s4     ,,T-A-A(-KLv+T6:r   c                 n   | j                   rd}| j                  }| j                  }nd}dx}}dj                         }||vrC| j	                  dt
        j                         t               }|sd}n||vrt        d       ||vrC|dk(  r|st        d      }|s|st        j                  d      }|st        j                  j                         }t        j                  j                  | j                        d	   }|j!                  | j"                  |||       | j%                  | j'                  d
      |      \  }}| j	                  d| d| t
        j                         |dk(  r| j                   r|| j(                  _        y| j	                  dt
        j                         | j	                  d| j+                          dt
        j                         d}|j-                         dvr"t        d      }|sd}|j-                         dvr"|j-                         dk(  r| j/                  ||       yyy|dk(  r#ddi}	dx|	d<   x|	d<   |	d<   d|	d<   |	d   st        d      |	d<   |	d   s|	d   |	d   k7  rr|	d   st        j                  d      |	d<   |	d   s|	d   st        j                  d      |	d<   |	d   s|	d   |	d   k7  rd|	d<   d|	d<   t        d       |	d   |	d   k7  rr|	d   st        d       |	d<   |	d   s| j%                  |	      \  }}|dk7  rt1        j2                  d!||       yt1        j2                  d"       t1        j2                  d#       y|d$k(  rNdd%i}	d|	d<   |	d   st        d&      |	d<   |	d   s| j%                  |	      \  }}t1        j2                  d!||       yy)'a  Send the metadata to the package index server.

        Well, do the following:
        1. figure who the user is, and then
        2. send the data as a Basic auth'ed POST.

        First we try to read the username/password from $HOME/.pypirc,
        which is a ConfigParser-formatted file with a section
        [distutils] containing username and password entries (both
        in clear text). Eg:

            [distutils]
            index-servers =
                pypi

            [pypi]
            username: fred
            password: sekrit

        Otherwise, to figure who the user is, we offer the user three
        choices:

         1. use existing login,
         2. register as a new user, or
         3. set the password to a random string and email the user.

        1x z1 2 3 4zWe need to know who you are, so please choose either:
 1. use your existing login,
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
Your selection [default 1]: z&Please choose one of the four options!z
Username: z
Password: r   submitzServer response (z):    zAI can store your PyPI login so future submissions will be faster.z(the login will be stored in )XynzSave your login (y/N)?ny2:actionusernamer2   emailNconfirmz
 Confirm: z!Password and confirm don't match!z
   EMail: rD   z"You will receive an email shortly.z7Follow the instructions in it to complete registration.3password_resetzYour email address: )r7   r1   r2   splitannounceloggingINFOinputprintgetpassr<   r=   HTTPPasswordMgrparseurlparser3   add_passwordr4   rE   rF   r   _get_rc_filelower_store_pypircr   r?   )
r   choicer1   r2   choicesauthhostrG   rH   datas
             r   r(   zregister.send_metadatal   s   < ??F}}H}}HF"$$Hx //#G#MM  	 WFw&>? G#" S= . "??<8  >>113D<<((9!<Ddjj$(C..t/C/CH/MtTLD&MM-dV3vh?N s{?? 2:D%%.MM:   MM78I8I8K7LAN !F ,,.4!&'?!@%%(F !,,.4 ||~,**8X> -- 2 s]v&D>@@DL@4
+d7m"DO6l$\2V 6lz"d9o5z*'.|'DD$ z*y/&-ool&CDO y/
#tI6')D$&*DO=> z"d9o5 7m %l 3W 7m..t4LD&s{3T6B=>RSs]/0DDM7m %&< =W 7m..t4LD&HH/v> r   c                 h   | j                   j                  }i d|ddd|j                         d|j                         d|j	                         d|j                         d|j                         d	|j                         d
|j                         d|j                         d|j                         d|j                         d|j                         d|j                         d|j                         d|j                         d|j!                         }|d   s
|d   s|d   rd|d<   |S )NrU   metadata_versionz1.0rW   versionsummary	home_pageauthorauthor_emaillicensedescriptionkeywordsplatformr'   download_urlprovidesrequires	obsoletesz1.1)r   metadataget_nameget_versionget_descriptionget_urlget_contactget_contact_emailget_licenceget_long_descriptionget_keywordsget_platformsget_classifiersget_download_urlget_providesget_requiresget_obsoletes)r   actionmetarn   s       r   rF   zregister.build_post_data   s      ))
v

 DMMO
 t'')	

 t++-
 
 d&&(
 D224
 t'')
 4446
 ))+
 **,
 4//1
 D113
  ))+!
" ))+#
$ ++-%
( 
tJ/43D',D#$r   Nc                    d|v r=| j                  dj                  |d   | j                        t        j                         d}d|z   }|dz   }t        j                         }|j                         D ]  \  }}t        t        t        |            D ]g  }	|j                  |       |j                  d| d       |j                  d       |j                  |	       |	sN|	d	   d
k(  sW|j                  d       i  |j                  |       |j                  d       |j                         j                  d      }d| dt        t        |            d}
t        j                   j#                  | j                  ||
      }t        j                   j%                  t        j                   j'                  |            }d}	 |j)                  |      }| j*                  r| j-                  |      }d}| j*                  r4dj=                  d|df      }| j                  |t        j                         |S # t        j.                  j0                  $ rH}| j*                  r|j2                  j5                         }|j6                  |j8                  f}Y d}~d}~wt        j.                  j:                  $ r}dt        |      f}Y d}~d}~ww xY w)z9Post a query to the server, and return a string response.rW   zRegistering {} to {}z3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254z
--z--z'
Content-Disposition: form-data; name=""z


zutf-8zmultipart/form-data; boundary=z; charset=utf-8)zContent-typezContent-length)password_mgrrL   )rN   OKNi  zK---------------------------------------------------------------------------)r]   formatr3   r^   r_   ioStringIOitemsmapstrmake_iterablewritegetvalueencodelenr<   r=   Requestbuild_openerHTTPBasicAuthHandleropenshow_responser@   error	HTTPErrorfpreadrG   msgURLErrorjoin)r   rn   rl   boundarysep_boundaryend_boundarybodykeyvaluesvalueheadersreqopenerrH   er   s                   r   rE   zregister.post_to_server	  sF   T>MM&--d6lDOOL
 I(#d*{{}::<KCS-"78

<(

EcU!LM

6"

5!U2Y$.JJt$ 9 ( 	

< 

4}}%%g. =XJoV!#d)n
 nn$$T__dGD ,,NN//T/B
 	[[%F !!//7F))XtX67CMM#w||, ||%% 	#!!ttyy{VVQUU]F||$$ 	!#a&[F	!s$   H6 6K>J K6KKr!   )__name__
__module____qualname__rw   r   user_optionsboolean_optionssub_commandsr   r   r*   r/   r"   r'   r&   r(   rF   rE   r   r   r   r
   r
      s    KK --F	
1 L $33 7 O /01L
C!$ 5;?B83r   r
   c                 "    | d gS t        |       S r!   r   )r   s    r   r   r   ?  s    ~v6""r   )__doc__rb   r   r^   urllib.parser<   urllib.requestdistutils._logr   warningsr   
_itertoolsr   corer   r
   r   r   r   r   <module>r      s;     	      (  h} hV	#r   