3 M(Y@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)serrorsrL/private/tmp/pip-build-nl73fm5q/setuptools/setuptools/command/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)selfeprrr 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_optionsrrget_finalized_commandZbuilder_target_dirr ospathjoin build_baseensure_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')zipfileZipFilemkpathr r$walkrr%r&lenlstripsepwriteclose) rfilenamezip_filerootdirsfilestmplnamefullZrelativedestrrrcreate_zipfileKs   zupload_docs.create_zipfilec Cslx|jD]}|j|q Wtj}|jjj}tjj |d|}z|j ||j |Wdt j |XdS)Nz%s.zip)get_sub_commands run_commandtempfilemkdtemp distributionmetadataget_namer$r%r&r? upload_fileshutilrmtree)rcmd_nameZtmp_dirr<r7rrrrun[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--rM)rSz multipart/form-data; boundary=%sascii) functoolspartialrXmapitems itertoolschain from_iterabledecoder&) clsdataboundaryrSZ end_boundaryZ end_itemsZbuilderZ part_groupspartsZ body_items content_typerrr_build_multipart}s  zupload_docs._build_multipartcCsPt|d}|j}WdQRX|jj}d|jtjj||fd}t|j d|j }t |}t j rn|jd}d|}|j|\}} d|j} |j| tjtjj|j\} } } }}}| r| r| st| 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)rLt*dd|jdddS)NrbZ doc_upload)z:actionr<content:rYzBasic zSubmitting documentation to %shttphttpszunsupported schema POSTz Content-typezContent-length AuthorizationzServer response (%s): %si-Locationzhttps://pythonhosted.org/%s/zUpload successful. Visit %szUpload failed (%s): %s-K)+openreadrDrErFr$r%basenamerusernamepasswordrrr rbrhr)r+rINFOrparseurlparseAssertionErrorrHTTPConnectionHTTPSConnectionconnect putrequest putheaderstrr1 endheaderssendsocketerrorERROR getresponsestatusreason getheader show_responseprint)rr6frjmetard credentialsauthbodyctmsgZschemanetlocurlparamsqueryZ fragmentsconnrgerlocationrrrrGs`              zupload_docs.upload_file)rNr)rNr)__name__ __module__ __qualname__DEFAULT_REPOSITORY descriptionr user_optionsboolean_optionsr sub_commandsrr"r?rK staticmethodrX classmethodrhrGrrrrrs"    r)__doc__base64r distutilsrZdistutils.errorsrr$rr-rBrHr_r[Zsetuptools.externrZsetuptools.extern.six.movesrr pkg_resourcesrr rrrrrrs