3 K]@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}|jd|S)Nsurrogateescapestrictzutf-8)rPY3encode)serrorsr!/usr/lib/python3.6/upload_docs.py_encodesrc@seZdZdZdZdddejfddgZejZd d Zd efgZ ddZ ddZ ddZ ddZ eddZeddZddZdS) upload_docszhttps://pypi.python.org/pypi/zUpload documentation to PyPIz repository=rzurl of repository [default: %s] show-responseN&display full response text from server upload-dir=directory to uploadcCs$|jdkr xtddD]}dSWdS)Nzdistutils.commands build_sphinxT) upload_dirr)selfZeprrr has_sphinx/s zupload_docs.has_sphinxrcCstj|d|_d|_dS)N)r initialize_optionsr target_dir)rrrrr6s zupload_docs.initialize_optionscCstj||jdkrN|jr0|jd}|j|_q`|jd}tjj |j d|_n|j d|j|_d|j krtt jd|jd|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)rrr rrrr!;s        zupload_docs.finalize_optionsc Cstj|d}z|j|jxtj|jD]~\}}}||jkrT| rTd}t||jxP|D]H}tjj||}|t |jdj tjj } tjj| |} |j || qZWq(WWd|j XdS)Nwz'no files found in upload directory '%s')zipfileZZipFileZmkpathrr"walkrr#r$lenlstripsepwriteclose) rfilenamezip_filerootdirsfilesZtmplnameZfullZrelativedestrrrcreate_zipfileKs   zupload_docs.create_zipfilec Cslx|jD]}|j|q Wtj}|jjj}tjj |d|}z|j ||j |Wdt j |XdS)Nz%s.zip)Zget_sub_commandsZ run_commandtempfileZmkdtemp distributionmetadataget_namer"r#r$r7 upload_fileshutilZrmtree)rZcmd_nameZtmp_dirr5r1rrrrun[s  zupload_docs.runccs|\}}d|}t|ts |g}xn|D]f}t|trN|d|d7}|d}nt|}|Vt|VdV|V|r&|dddkr&dVq&WdS) 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||j}tjj|}tj||} d|jd} dj | | fS) z= Build up the MIME payload for the POST data s3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254s --s--r@)rFz multipart/form-data; boundary=%sascii) functoolspartialrKmapitems itertoolschain from_iterabledecoder$) clsdataboundaryrFZ end_boundaryZ end_itemsZbuilderZ part_groupspartsZ body_items content_typerrr_build_multipart}s  zupload_docs._build_multipartcCs:t|d}|j}WdQRX|jj}d|jtjj||fd}t|j d|j }t |}t j rn|jd}d|}|j|\}} d|j} |j| tjtjj|j\} } } }}}| dkrtj| }n | d krtj| }n td | d }yZ|j|jd | | }|jd ||jdtt||jd||j |j!|Wn6t"j#k r~}z|jt|tj$dSd}~XnX|j%}|j&dkrd|j&|j'f} |j| tjnb|j&dkr|j(d}|dkrd|j}d|} |j| tjnd|j&|j'f} |j| tj$|j)r6t*dd|jdddS)NrbZ doc_upload)z:actionr5content:rLzBasic zSubmitting documentation to %sZhttpZhttpszunsupported schema ZPOSTz Content-typezContent-lengthZ AuthorizationzServer response (%s): %si-ZLocationzhttps://pythonhosted.org/%s/zUpload successful. Visit %szUpload failed (%s): %s-K)+openreadr9r:r;r"r#basenamerZusernameZpasswordrrr rUr[r%r'rINFOrparseZurlparserZHTTPConnectionZHTTPSConnectionAssertionErrorZconnectZ putrequestZ putheaderstrr+Z endheaderssendsocketerrorZERRORZ getresponseZstatusreasonZ getheaderZ show_responseprint)rr0fr]metarWZ credentialsZauthZbodyZctmsgZschemaZnetlocZurlZparamsZqueryZ fragmentsZconnrZerlocationrrrr<s^              zupload_docs.upload_file)rNr)rNr)__name__ __module__ __qualname__ZDEFAULT_REPOSITORY descriptionr Z user_optionsZboolean_optionsrZ sub_commandsrr!r7r> staticmethodrK classmethodr[r<rrrrrs"    r)__doc__base64rZ distutilsrZdistutils.errorsrr"rkr)r8r=rRrNZsetuptools.externrZsetuptools.extern.six.movesrrZ pkg_resourcesrr rrrrrrs