a „oeJã@s¨dZddlmZddlmZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl ZddlZddlmZddlmZd d lmZd d „ZGd d„deƒZdS)z|upload_docs Implements a Distutils 'upload_docs' subcommand (upload documentation to sites other than PyPi such as devpi). é)Ústandard_b64encode)Úlog)ÚDistutilsOptionErrorNé)Úmetadata)ÚSetuptoolsDeprecationWarningé)ÚuploadcCs | dd¡S)Nzutf-8Úsurrogateescape)Úencode)Ús©r ú?C:\Program Files\Certbot\pkgs\setuptools\command\upload_docs.pyÚ_encodesrc@s‚eZdZdZdZdddejfddgZejZdd „Zd efgZ d d „Z d d„Z dd„Z dd„Z edd„ƒZedd„ƒZdd„ZdS)Ú upload_docszhttps://pypi.python.org/pypi/z;Upload documentation to sites other than PyPi such as devpiz repository=Úrzurl of repository [default: %s])z show-responseNz&display full response text from server)z upload-dir=Nzdirectory to uploadcCst|jduotjddd�ƒS)Nzdistutils.commandsÚ build_sphinx)ÚgroupÚname)ÚboolÚ upload_dirrZ entry_points©Úselfr r rÚ has_sphinx/s  þzupload_docs.has_sphinxrcCst |¡d|_d|_dS)N)r Úinitialize_optionsrÚ target_dirrr r rr7s zupload_docs.initialize_optionscCs†t d¡t |¡|jdur`| ¡rB| d¡}t|jƒd|_ qr| d¡}t j   |j d¡|_ n| d¡|j|_ | d|j ¡dS)NzWUpload_docs command is deprecated. Use Read the Docs (https://readthedocs.org) instead.rZhtmlÚbuildZdocsrzUsing upload directory %s)rÚwarnr Úfinalize_optionsrrZget_finalized_commandÚdictZbuilder_target_dirsrÚosÚpathÚjoinZ build_baseZensure_dirnameÚannounce)rrrr r rr<sÿ     zupload_docs.finalize_optionsc Csºt |d¡}zž| |j¡t |j¡D]x\}}}||jkrP|sPd}t||jƒ‚|D]H}tj ||¡}|t |jƒd…  tjj ¡} tj | |¡} |  || ¡qTq&W|  ¡n |  ¡0dS)NÚwz'no files found in upload directory '%s')ÚzipfileÚZipFileZmkpathrr Úwalkrr!r"ÚlenÚlstripÚsepÚwriteÚclose) rÚfilenameÚzip_fileÚrootÚdirsÚfilesZtmplrZfullÚrelativeÚdestr r rÚcreate_zipfileNs  zupload_docs.create_zipfilec Cs‚tjdddd�| ¡D]}| |¡qt ¡}|jj ¡}t j   |d|¡}z"|  |¡|  |¡Wt |¡n t |¡0dS)NzDeprecated commanda upload_docs is deprecated and will be removed in a future version. Instead, use tools like devpi and Read the Docs; or lower level tools like httpie and curl to interact directly with your hosting service API. )içé é)Zdue_datez%s.zip)rÚemitZget_sub_commandsZ run_commandÚtempfileZmkdtempÚ distributionrÚget_namer r!r"r4Ú upload_fileÚshutilÚrmtree)rZcmd_nameZtmp_dirrr.r r rÚrun^sù     zupload_docs.runccs�|\}}d|}t|tƒs |g}|D]f}t|tƒrL|d|d7}|d}nt|ƒ}|Vt|ƒVdV|V|r$|dd…dkr$dVq$dS) Nz* Content-Disposition: form-data; name="%s"z; filename="%s"rrs éÿÿÿÿó ó )Ú isinstanceÚlistÚtupler)ÚitemÚ sep_boundaryÚkeyÚvaluesÚtitleÚvaluer r rÚ _build_partvs    zupload_docs._build_partc Csnd}d| d¡}|d}|df}tj|j|d�}t|| ¡ƒ}tj |¡}t ||¡} d|} d  | ¡| fS) z= Build up the MIME payload for the POST data z3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254s --Úasciis--rA)rFz multipart/form-data; boundary=%só) r Ú functoolsÚpartialrKÚmapÚitemsÚ itertoolsÚchainÚ from_iterabler") ÚclsÚdataÚboundaryrFZ end_boundaryZ end_itemsZbuilderZ part_groupsÚpartsZ body_itemsÚ content_typer r rÚ_build_multipartŠsþþ  zupload_docs._build_multipartc CsTt|dƒ�}| ¡}Wdƒn1s(0Y|jj}d| ¡tj |¡|fdœ}t|j d|j ƒ}t |ƒ  d¡}d|}|  |¡\}} d|j} | | tj¡tj |j¡\} } } }}}|sÌ|sÌ|rÐJ‚| dkrætj | ¡}n"| d krütj | ¡}n td | ƒ‚d }zZ| ¡| d | ¡| }| d |¡| dtt|ƒƒ¡| d|¡| ¡|  |¡Wn:t!�y }z | t|ƒtj"¡WYd}~dSd}~00| #¡}|j$dk�rÖd|j$|j%f} | | tj¡nb|j$dk�r| &d¡}|du�rd| ¡}d|} | | tj¡nd|j$|j%f} | | tj"¡|j'�rPt(d| ¡dƒdS)NÚrbZ doc_upload)z:actionrÚcontentú:rLzBasic zSubmitting documentation to %sÚhttpÚhttpszunsupported schema ÚZPOSTz Content-typezContent-lengthZ AuthorizationéÈzServer response (%s): %si-ZLocationzhttps://pythonhosted.org/%s/zUpload successful. Visit %szUpload failed (%s): %szK---------------------------------------------------------------------------))ÚopenÚreadr9rr:r r!ÚbasenamerÚusernameÚpasswordrÚdecoderZZ repositoryr#rÚINFOÚurllibÚparseÚurlparser^ZclientZHTTPConnectionZHTTPSConnectionÚAssertionErrorZconnectZ putrequestZ putheaderÚstrr(Z endheadersÚsendÚOSErrorZERRORZ getresponseÚstatusÚreasonZ getheaderZ show_responseÚprint)rr-Úfr\ÚmetarVZ credentialsZauthÚbodyZctÚmsgZschemaÚnetlocÚurlÚparamsÚqueryZ fragmentsZconnrYÚerÚlocationr r rr; sb &ý ÿ         zupload_docs.upload_fileN)Ú__name__Ú __module__Ú __qualname__ZDEFAULT_REPOSITORYÚ descriptionr Z user_optionsZboolean_optionsrZ sub_commandsrrr4r>Ú staticmethodrKÚ classmethodrZr;r r r rrs*ýù    r)Ú__doc__Úbase64rZ distutilsrZdistutils.errorsrr r%r8r<rRrNZ http.clientr^Ú urllib.parseriZ _importlibrÚwarningsrr rrr r r rÚs