U Qab@sdZddlmZddlmZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZmZddlmZd d lmZd d ZGd ddeZdS)zpupload_docs Implements a Distutils 'upload_docs' subcommand (upload documentation to PyPI's pythonhosted.org). )standard_b64encode)log)DistutilsOptionErrorN)six) http_clienturllib)iter_entry_points)uploadcCstjr dnd}|d|S)Nsurrogateescapestrictzutf-8)rPY3encode)serrorsrB/usr/lib/python3.8/site-packages/setuptools/command/upload_docs.py_encodesrc@seZdZdZdZdddejfddgZejZdd Zd efgZ d d Z d dZ ddZ ddZ eddZeddZddZdS) upload_docszhttps://pypi.python.org/pypi/zUpload documentation to PyPIz repository=rzurl of repository [default: %s])z show-responseNz&display full response text from server)z upload-dir=Nzdirectory to uploadcCs"|jdkrtddD]}dSdS)Nzdistutils.commands build_sphinxT) upload_dirr)selfZeprrr has_sphinx/s zupload_docs.has_sphinxrcCst|d|_d|_dS)N)r initialize_optionsr target_dir)rrrrr6s zupload_docs.initialize_optionscCst||jdkrN|r0|d}|j|_q`|d}tj |j d|_n| d|j|_d|j krtt d|d|jdS)NrbuildZdocsrzpypi.python.orgz3Upload_docs command is deprecated. Use RTD instead.zUsing upload directory %s)r finalize_optionsrrZget_finalized_commandZbuilder_target_dirrospathjoinZ build_baseZensure_dirname repositoryrwarnannounce)rrrrrrr;s        zupload_docs.finalize_optionsc Cst|d}z||jt|jD]x\}}}||jkrP|sPd}t||j|D]H}tj ||}|t |jd tjj } tj | |} | || qTq&W5|XdS)Nwz'no files found in upload directory '%s')zipfileZZipFilecloseZmkpathrrwalkrrr lenlstripsepwrite) rfilenamezip_filerootdirsfilesZtmplnameZfullrelativedestrrrcreate_zipfileKs  zupload_docs.create_zipfilec Csh|D]}||qt}|jj}tj |d|}z| || |W5t |XdS)Nz%s.zip)Zget_sub_commandsZ run_commandtempfileZmkdtemp distributionmetadataget_namerrr shutilZrmtreer4 upload_file)rZcmd_nameZtmp_dirr1r-rrrrun[s    zupload_docs.runccs|\}}d|}t|ts |g}|D]f}t|trL|d|d7}|d}nt|}|Vt|VdV|V|r$|dddkr$dVq$dS) Nz* Content-Disposition: form-data; name="%s"z; filename="%s"rr s   ) isinstancelisttupler)item sep_boundarykeyvaluestitlevaluerrr _build_partis    zupload_docs._build_partc Csnd}d|}|d}|df}tj|j|d}t||}tj|}t||} d|d} d | | fS) z= Build up the MIME payload for the POST data s3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254s --s--r>)rCz multipart/form-data; boundary=%sascii) functoolspartialrHmapitems itertoolschain from_iterabledecoder ) clsdataboundaryrCZ end_boundaryZ end_itemsZbuilderZ part_groupspartsZ body_items content_typerrr_build_multipart}s  zupload_docs._build_multipartc Cs:t|d}|}W5QRX|jj}d|tj||fd}t|j d|j }t |}t j rn|d}d|}||\}} d|j} || tjtj|j\} } } }}}| dkrt| }n | d krt| }n td | d }zZ||d | | }|d ||dtt||d|| |!|Wn>t"j#k r}z|t|tj$WYdSd}~XYnX|%}|j&dkrd|j&|j'f} || tjnb|j&dkr|(d}|dkrd|}d|} || tjnd|j&|j'f} || tj$|j)r6t*d|ddS)NrbZ doc_upload)z:actionr1content:rIzBasic zSubmitting documentation to %sZhttpZhttpszunsupported schema ZPOSTz Content-typezContent-lengthZ AuthorizationzServer response (%s): %si-ZLocationzhttps://pythonhosted.org/%s/zUpload successful. Visit %szUpload failed (%s): %szK---------------------------------------------------------------------------)+openreadr6r7r8rrbasenamerZusernameZpasswordrrr rRrXr!r#rINFOrparseZurlparserZHTTPConnectionZHTTPSConnectionAssertionErrorZconnectZ putrequestZ putheaderstrr(Z endheaderssendsocketerrorZERRORZ getresponseZstatusreasonZ getheaderZ show_responseprint)rr,frZmetarTZ credentialsZauthZbodyZctmsgZschemaZnetlocZurlZparamsZqueryZ fragmentsZconnrWerlocationrrrr:sb               zupload_docs.upload_fileN)__name__ __module__ __qualname__ZDEFAULT_REPOSITORY descriptionr Z user_optionsZboolean_optionsrZ sub_commandsrrr4r; staticmethodrH classmethodrXr:rrrrrs(   r)__doc__base64rZ distutilsrZdistutils.errorsrrrfr%r5r9rOrKZsetuptools.externrZsetuptools.extern.six.movesrrZ pkg_resourcesrr rrrrrrs