ReQddlZddlZddlZddlZddlZddlZ ddlmZn#e$r ddl mZYnwxYwddl m Z ddl m Z mZmZmZmZmZddlmZmZejeZdZdZGd d eZdS) N)Thread)DistlibException)HTTPBasicAuthHandlerRequestHTTPPasswordMgrurlparse build_opener string_types)zip_dir ServerProxyzhttps://pypi.org/pypipypiceZdZdZdZddZdZdZdZdZ d Z d Z dd Z dd Z dd Z ddZdZ ddZ ddZddZdZdZddZdS) PackageIndexzc This class represents a package index compatible with PyPI, the Python Package Index. s.----------ThIs_Is_tHe_distlib_index_bouNdaRY_$Nc|pt|_|t|j\}}}}}}|s|s|s|dvrt d|jzd|_d|_d|_d|_ttj d5}dD];} tj | dg||} | dkr | |_n,#t$rY8wxYwddddS#1swxYwYdS) z Initialise an instance. :param url: The URL of the index. If not specified, the URL for PyPI is used. )httphttpszinvalid repository: %sNw)gpggpg2z --versionstdoutstderrr) DEFAULT_INDEXurlread_configurationr rpassword_handler ssl_verifierrgpg_homeopenosdevnull subprocess check_callOSError) selfrschemenetlocpathparamsqueryfragsinksrcs /builddir/build/BUILDROOT/alt-python311-pip-21.3.1-3.el8.x86_64/opt/alt/python311/lib/python3.11/site-packages/pip/_vendor/distlib/index.py__init__zPackageIndex.__init__$s~'- !!!4    '''''' dr6c|j|jtdt}t |j\}}}}}}||j||j|jt||_ dS)zp Check that ``username`` and ``password`` have been set, and raise an exception if not. Nz!username and password must be set) r9r:rrr r add_passwordr;rr)r&pm_r(s r0rAzPackageIndex.check_credentials_s} = DM$9"#FGG G    ( 2 261aA  FDM4=III 4R 8 8r6c|||}d|d<||g}||}d|d<||g}||S)aq Register a distribution on PyPI, using the provided metadata. :param metadata: A :class:`Metadata` instance defining at least a name and version number for the distribution to be registered. :return: The HTTP response received from PyPI upon submission of the request. verify:actionsubmit)rAvalidatetodictencode_requestitems send_request)r&metadatadrequestresponses r0registerzPackageIndex.registerks     OO  ) %%aggii44$$W--) %%aggii44  )))r6c |}|sn\|d}||t|d|s|dS)ar Thread runner for reading lines of from a subprocess into a buffer. :param name: The logical name of the stream (used for logging only). :param stream: The stream to read from. This will typically a pipe connected to the output stream of a subprocess. :param outbuf: The list to append the read lines to. Tutf-8z: N)readlinedecoderstripappendloggerdebugclose)r&namestreamoutbufr.s r0_readerzPackageIndex._readers /!!A !!((**A MM!    LLTTT11- . . .  /  r6c |jdddg}||j}|r|d|g||gdtj}t j|t j|dz}|dd d |d ||gt d d |||fS)a Return a suitable command for signing a file. :param filename: The pathname to the file to be signed. :param signer: The identifier of the signer of the file. :param sign_password: The passphrase for the signer's private key used for signing. :param keystore: The path to a directory which contains the keys used in verification. If not specified, the instance's ``gpg_home`` attribute is used instead. :return: The signing command as a list suitable to be passed to :class:`subprocess.Popen`. --status-fd2--no-ttyN --homedir)z--batchz--passphrase-fd0z.ascz --detach-signz--armorz --local-userz--output invoking: %s ) rrextendtempfilemkdtempr!r)joinbasenamer[r\)r&filenamesigner sign_passwordkeystorer5tdsfs r0get_sign_commandzPackageIndex.get_sign_commandsxZ8  }H  0 JJ X. / / /  $ JJ::: ; ; ;     W\\"bg..x886A B B OYJH6 7 7 7 ^SXXc]]333Bwr6c@tjtjd}|tj|d<g}g}tj|fi|}t|jd|j|f}|t|jd|j|f}||3|j ||j | | | |j ||fS)a Run a command in a child process , passing it any input data specified. :param cmd: The command to run. :param input_data: If specified, this must be a byte string containing data to be sent to the child process. :return: A tuple consisting of the subprocess' exit code, a list of lines read from the subprocess' ``stdout``, and a list of lines read from the subprocess' ``stderr``. rNstdinr)targetargsr)r#PIPEPopenrrarstartrrwwriter]waitrm returncode) r&r5 input_datakwargsrrpt1t2s r0 run_commandzPackageIndex.run_commands!o o    !(oF7O  S + +F + +4> > OO    48 4JKKKK>>(FM*244 (D ! ! !QI ! ! ! ! ! ! ! ! ! ! ! ! ! ! ![++5577 y11;;==  $ # "$*      RW--h77CD  5h%% $6688 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ LL/27+;+;H+E+E!# $ $ $ M"'//(33 4 4 4%%aggii77  )))s$<CC!$C!F&&F*-F*c(|tj|st d|ztj|d}tj|st d|z||j|j }}t| }dd|fd|fg}d||fg}| ||} | | S)a2 Upload documentation to the index. :param metadata: A :class:`Metadata` instance defining at least a name and version number for the documentation to be uploaded. :param doc_dir: The pathname of the directory which contains the documentation. This should be the directory that contains the ``index.html`` for the documentation. :return: The HTTP response received from PyPI upon submission of the request. znot a directory: %rz index.htmlz not found: %r)rI doc_uploadr^versionr)rAr!r)isdirrrmrrKr^rr getvaluerMrO) r&rPdoc_dirfnr^rzip_datafieldsrrRs r0upload_documentationz!PackageIndex.upload_documentation!s    w}}W%% D"#87#BCC C W\\'< 0 0w~~b!! 9"?R#788 8 x'7g7##,,..+4.9g"68T8,-%%fe44  )))r6c|jdddg}||j}|r|d|g|d||gtdd||S) a| Return a suitable command for verifying a file. :param signature_filename: The pathname to the file containing the signature. :param data_filename: The pathname to the file containing the signed data. :param keystore: The path to a directory which contains the keys used in verification. If not specified, the instance's ``gpg_home`` attribute is used instead. :return: The verifying command as a list suitable to be passed to :class:`subprocess.Popen`. rcrdreNrfz--verifyrhri)rrrjr[r\rm)r&signature_filename data_filenamerrr5s r0get_verify_commandzPackageIndex.get_verify_command=s}xZ8  }H  0 JJ X. / / / J 2MBCCC ^SXXc]]333 r6c|jstd||||}||\}}}|dvrtd|z|dkS)a6 Verify a signature for a file. :param signature_filename: The pathname to the file containing the signature. :param data_filename: The pathname to the file containing the signed data. :param keystore: The path to a directory which contains the keys used in verification. If not specified, the instance's ``gpg_home`` attribute is used instead. :return: True if the signature was verified, else False. z0verification unavailable because gpg unavailable)rrz(verify command failed with error code %sr)rrrr)r&rrrrr5r/rrs r0verify_signaturezPackageIndex.verify_signatureUsx 2"$122 2%%&8-&.00!--c22FF V  "$')+$,-- -Qwr6c <|d}tdn^t|ttfr|\}}nd}t t |}td|zt|d5}|t|} | } d} d} d} d} d | vrt| d } |r || | |  | | }|snS| t|z } |||r||| d z } |r || | | k |n#|wxYw dddn #1swxYwY| dkr| | krt#d | | fz|rQ|}||krt#|d|d|d|td|dSdS)a This is a convenience method for downloading a file from an URL. Normally, this will be a file from the index, though currently no check is made for this (i.e. a file can be downloaded from anywhere). The method is just like the :func:`urlretrieve` function in the standard library, except that it allows digest computation to be done during download and checking that the downloaded data matched any expected value. :param url: The URL of the file to be downloaded (assumed to be available via an HTTP GET request). :param destfile: The pathname where the downloaded file is to be saved. :param digest: If specified, this must be a (hasher, value) tuple, where hasher is the algorithm used (e.g. ``'md5'``) and ``value`` is the expected value. :param reporthook: The same as for :func:`urlretrieve` in the standard library. NzNo digest specifiedrzDigest specified: %swbi rzcontent-lengthzContent-LengthTrz1retrieval incomplete: got only %d out of %d bytesz digest mismatch for z : expected z, got zDigest verified: %s)r[r\ isinstancelisttuplegetattrrr rOrinfointrlenr}rr]rr)r&rdestfiledigest reporthookdigesterhasherdfpsfpheaders blocksizesizerblocknumblockactuals r0 download_filezPackageIndex.download_filens, >H LL. / / / /&4-00 !'/ww//11H LL/&8 9 9 9(D ! ! S##GCLL11C ((** #w..w'7899D:JxD999 >HHY//E CJJ&DIIe$$$/ ...MH!>" 8Y=== >  5               : 199"C,     8''))F&7=vvxxx7=vvvv(GHHH LL. 7 7 7 7 7  8 8s+#F2B0E8#F8FFF"%F"cg}|jr||j|jr||jt|}||S)z Send a standard library :class:`Request` to PyPI and return its response. :param req: The request to send. :return: The HTTP response from PyPI (a standard library HTTPResponse). )rrZrr r )r&reqhandlersopeners r0rOzPackageIndex.send_requestse   3 OOD1 2 2 2   / OOD- . . .x({{3r6c Lg}|j}|D]n\}}t|ttfs|g}|D]G}|d|zd|zdd|dfHo|D]<\}} } |d|zd|d| ddd| f=|d|zdzdfd|} d |z} | tt| d } t|j | | S) a& Encode fields and files for posting to an HTTP server. :param fields: The fields to send as a list of (fieldname, value) tuples. :param files: The files to send as a list of (fieldname, filename, file_bytes) tuple. s--z)Content-Disposition: form-data; name="%s"rVr6z&Content-Disposition: form-data; name="z "; filename=""s smultipart/form-data; boundary=)z Content-typezContent-length) boundaryrrrrjrrmstrrrr)r&rrpartsrkvaluesvkeyrovaluebodyctrs r0rMzPackageIndex.encode_requests|= ( (IAvftUm44 "  ( ( H$@wHHW%% '(((( (%*   C5 LL  ##xxx!"(&//       eh&.4555||E"" . 9!#d))nn  txw///r6ct|trd|i}t|jd} |||pd|dS#|dwxYw)Nr^g@)timeoutandr])rr r rsearch)r&termsoperator rpc_proxys r0rzPackageIndex.searchs e\ * * $UOE#666  !##E8+rsc '       '''&&&&&&&&';;;;;;;;;;;;;;;;&&&&&&&&  8 $ $'  a!a!a!a!a!6a!a!a!a!a!s ! //