
    ;e-                     r    d 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
T ddlmZ  G d de	          ZdS )	zhdistutils.command.register

Implements the Distutils 'register' command (register with the repository).
    N)warn)PyPIRCCommand)*)logc                       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dS )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                     dS )NT selfs    1/usr/lib/python3.11/distutils/command/register.py<lambda>zregister.<lambda>   s    4     c                 J    t          j        |            d| _        d| _        d S )Nr   )r   initialize_optionslist_classifiersr
   r   s    r   r   zregister.initialize_options   s&    (... !r   c                 d    t          j        |            d| j        fdd}|| j        j        d<   d S )Nr   )r      )r
   restructuredtextr   )r   finalize_optionsr
   distributioncommand_options)r   check_optionss     r   r   zregister.finalize_options$   sB    &t,,,$.#<-<> >5B)'222r   c                 J   |                                   |                                  |                                 D ]}|                     |           | j        r|                                  d S | j        r|                                  d S |                                  d S N)	r   _set_configget_sub_commandsrun_commanddry_runverify_metadatar   classifierssend_metadata)r   cmd_names     r   runzregister.run+   s     --// 	' 	'HX&&&&< 	!  """""" 	!     r   c                     t          dt                     | j                            d          }|                                 | j        |_        d|_        |                                 dS )zDeprecated API.zddistutils.command.register.check_metadata is deprecated,               use the check command insteadr   r   N)r   PendingDeprecationWarningr   get_command_objensure_finalizedr
   r   r(   )r   r   s     r   check_metadatazregister.check_metadata:   si     -.G	I 	I 	I!11'::   {!"		r   c                 >   |                                  }|i k    r=|d         | _        |d         | _        |d         | _        |d         | _        d| _        d	S | j        d| j        fvrt          d| j        z            | j        dk    r| j        | _        d| _        d	S )
z: Reads the configuration file and set attributes.
        usernamepassword
repositoryrealmTpypiz%s not found in .pypircFN)_read_pypircr/   r0   r1   r2   
has_configDEFAULT_REPOSITORY
ValueError)r   configs     r   r    zregister._set_configD   s     ""$$R<<":.DM":.DM$\2DODJ"DOOOvt/F&GGG !:T_!LMMM&(("&"9#DOOOr   c                     | j         dz   }t          j                            |          }t	          j        |                     |                     dS )z8 Fetch the list of classifiers from the server.
        z?:action=list_classifiersN)r1   urllibrequesturlopenr   info_read_pypi_response)r   urlresponses      r   r%   zregister.classifiersU   sJ     o99>))#..))(3344444r   c                     |                      |                     d                    \  }}t          j        d||           dS )zF 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_metadata\   sD     ,,T-A-A(-K-KLLv+T6:::::r   c                 $   | j         rd}| j        }| j        }nd}dx}}d                                }||vrJ|                     dt
          j                   t                      }|sd}n||vrt          d           ||vJ|dk    r|st          d          }||st          j	        d          }|t          j                                        }t          j                            | j                  d	         }|                    | j        |||           |                     |                     d
          |          \  }}|                     d|d|t
          j                   |dk    r| j         r|| j        _        dS |                     dt
          j                   |                     d|                                 z  t
          j                   d}|                                dvr)t          d          }|sd}|                                dv)|                                dk    r|                     ||           dS dS dS |dk    rYddi}	dx|	d<   x|	d<   |	d<   d|	d<   |	d         st          d          |	d<   |	d         |	d         |	d         k    r|	d         st          j	        d          |	d<   |	d         |	d         st          j	        d          |	d<   |	d         |	d         |	d         k    rd|	d<   d|	d<   t          d           |	d         |	d         k    |	d         st          d          |	d<   |	d         |                     |	          \  }}|dk    rt          j        d ||           dS t          j        d!           t          j        d"           dS |d#k    r[dd$i}	d|	d<   |	d         st          d%          |	d<   |	d         |                     |	          \  }}t          j        d ||           dS dS )&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 %s)XynzSave your login (y/N)?ny2:actionusernamer0   emailNconfirmz
 Confirm: z!Password and confirm don't match!z
   EMail: rB   z"You will receive an email shortly.z7Follow the instructions in it to complete registration.3password_resetzYour email address: )r5   r/   r0   splitannouncer   INFOinputprintgetpassr:   r;   HTTPPasswordMgrparseurlparser1   add_passwordr2   rC   rD   r   _get_rc_filelower_store_pypircr=   )
r   choicer/   r0   choicesauthhostrE   rF   datas
             r   r&   zregister.send_metadatac   s   < ? 	%F}H}HHF"$$Hx //##G##MM   "%+ + + WWF @w&&>??? G## S== / ..  / 9"?<88  9 >1133D<((99!<Ddj$(CCC..t/C/CH/M/M LD&MMMffE($ $ $ s{{? ? 2:D%...MM $ACF8M M MMM"D"&"3"3"5"5#67:xA A A F ,,..44!&'?!@!@% )%(F !,,..44 ||~~,,**8X>>>>>! { -, s]]v&D>@@DL@4
+d7m"DO6l 3$\22V 6l 3z"d9o55z* E'.|'D'DD$ z* Ey/ D&-ol&C&CDO y/ D
#tI66')D$&*DO=>>> z"d9o55 7m 4 %l 3 3W 7m 4..t44LD&s{{3T6BBBBB=>>> 3 5 5 5 5 5s]]/0DDM7m > %&< = =W 7m >..t44LD&H/v>>>>> ]r   c                    | j         j        }i d|ddd|                                d|                                d|                                d|                                d|                                d	|                                d
|                                d|	                                d|
                                d|                                d|                                d|                                d|                                d|                                d|                                }|d         s|d         s|d         rd|d<   |S )NrR   metadata_versionz1.0rT   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metarj   s       r   rD   zregister.build_post_data   s     )
v

 DMMOO
 t''))	

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


zutf-8z/multipart/form-data; boundary=%s; charset=utf-8)zContent-typezContent-length)password_mgrrJ   )rL   OKNi  zK---------------------------------------------------------------------------)rZ   r1   r   r[   ioStringIOitemstypestrwritegetvalueencodelenr:   r;   Requestbuild_openerHTTPBasicAuthHandleropenshow_responser>   error	HTTPErrorfpreadrE   msgURLErrorjoin)r   rj   rh   boundarysep_boundaryend_boundarybodykeyvalueheadersreqopenerrF   er   s                  r   rC   zregister.post_to_server   s    T>>MMMDLLL48OOE47H> > > I(#d*{}}**,, 	% 	%JCE{{488T2ZZ"888 % %E



<(((

HLMMM

6"""

5!!! %U2Y$..JJt$$$% 	

<   

4}}%%g.. NhV!#d))nn
 
 n$$T_dGDD ,,N//T/BB
 
 	[[%%F ! 8//77FF |% 	# 	# 	#! #tyy{{VQU]FFFFFF|$ 	! 	! 	!#a&&[FFFFFF	!  	)))XtX677CMM#sx(((s$   H: :J3.JJ3J..J3r   )__name__
__module____qualname__rs   r   user_optionsboolean_optionssub_commandsr   r   r(   r-   r    r%   r$   r&   rD   rC   r   r   r   r   r      s	       LK -	-	O1
 
L $3 70 70 70 0O //01L  
C C C! ! !  $ $ $"5 5 5; ; ;x? x? x?t  87 7 7 7 7 7r   r   )__doc__r^   r   urllib.parser:   urllib.requestwarningsr   distutils.corer   distutils.errors	distutilsr   r   r   r   r   <module>r      s      				 # # # # # # # #       ( ( ( ( ( (          _ _ _ _ _} _ _ _ _ _r   