Re@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)uploadcCs%tjrdnd}|jd|S)Nsurrogateescapestrictzutf-8)rPY3encode)serrorsr/builddir/build/BUILDROOT/alt-python35-setuptools-36.3.0-4.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/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/szupload_docs.has_sphinxrcCs#tj|d|_d|_dS)N)r initialize_optionsr target_dir)rrrrr6s  zupload_docs.initialize_optionscCstj||jdkrs|jrF|jd}|j|_q|jd}tjj |j d|_n|j d|j|_d|j krt 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]\}}}||jkrv| rvd}t||jxp|D]h}tjj||}|t |jdj tjj } tjj| |} |j || q}Wq8WWd|j XdS)Nwz'no files found in upload directory '%s')zipfileZipFilemkpathr r$walkrr%r&lenlstripsepwriteclose) rfilenamezip_filerootdirsfilestmplnamefullZrelativedestrrrcreate_zipfileKs" (zupload_docs.create_zipfilec Csx!|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}x|D]{}t|tri|d|d7}|d}n t|}|Vt|VdV|V|r5|dddkr5dVq5WdS) Nz* Content-Disposition: form-data; name="%s"z; filename="%s"rr s s s ) isinstancelisttupler)item sep_boundarykeyvaluestitlevaluerrr _build_partis       zupload_docs._build_partc Csd}d|}|d}|df}tj|jd|}t||j}tjj|}tj||} d|jd} dj | | fS) z= Build up the MIME payload for the POST data s3--------------GHSKFJDLGDS7543FJKLFHRE75642756743254s --s--s rQz multipart/form-data; boundary=%sascii) functoolspartialrVmapitems itertoolschain from_iterabledecoder&) clsdataboundaryrQZ end_boundaryZ end_itemsZbuilderZ part_groupspartsZ body_items content_typerrr_build_multipart}s     zupload_docs._build_multipartcCs&t|d}|j}WdQRX|jj}ddd|jdtjj||fi}t|j d|j }t |}t j r|jd}d|}|j|\}} d |j} |j| tjtjj|j\} } } }}}| r| r| s t| d kr>tj| }n.| d kr\tj| }ntd | d }yw|j|jd| | }|jd||jdtt||jd||j |j!|WnEt"j#k r0}z"|jt|tj$dSWYdd}~XnX|j%}|j&dkrxd|j&|j'f} |j| tjn|j&dkr|j(d}|dkrd|j}d|} |j| tjn)d|j&|j'f} |j| tj$|j)r"t*dd|jdddS)Nrbz:actionZ doc_uploadr<content:rWzBasic zSubmitting documentation to %shttphttpszunsupported schema POSTz Content-typezContent-length AuthorizationzServer response (%s): %si-ZLocationzhttps://pythonhosted.org/%s/zUpload successful. Visit %szUpload failed (%s): %s-K)+openreadrDrErFr$r%basenamerusernamepasswordrrr r`rfr)r+rINFOrparseurlparseAssertionErrorrHTTPConnectionHTTPSConnectionconnect putrequest putheaderstrr1 endheaderssendsocketerrorERROR getresponsestatusreason getheader show_responseprint)rr6frhmetarb credentialsauthbodyctmsgZschemanetlocurlparamsquery fragmentsconnreerlocationrrrrGs`      '        zupload_docs.upload_file)rNr)rNr)__name__ __module__ __qualname__DEFAULT_REPOSITORY descriptionr user_optionsboolean_optionsr sub_commandsrr"r?rK staticmethodrV classmethodrfrGrrrrrs"         r)__doc__base64r distutilsrdistutils.errorsrr$rr-rBrHr]rYZsetuptools.externrZsetuptools.extern.six.movesrr pkg_resourcesrr rrrrrrs