U if@sbddlZddlZddlZddlZddlZddlZddlZddl m Z ddddddd d d d d dddddddgZ dZ dZ dZdZdZdZeejjddejjDZdZdZedjZed jZed!Zed"Z d#d$d%hZ!dAd'd(Z"Gd)d*d*ej#j$Z%d+d,Z&e%fd-d.Z'Gd/ddej(Z)Gd0ddZ*z ddl+Z+Wne,k r\YnXGd1d2d2e*Z-e .d2Gd3dde/Z0Gd4dde0Z1Gd5d d e0Z2Gd6dde0Z3Gd7dde0Z4Gd8d d e0Z5Gd9d d e0Z6Gd:d d e0Z7Gd;d d e7Z8Gddde0Z;Gd?dde0Ze0Z?dS)BN)urlsplit HTTPResponseHTTPConnection HTTPException NotConnectedUnknownProtocolUnknownTransferEncodingUnimplementedFileModeIncompleteRead InvalidURLImproperConnectionStateCannotSendRequestCannotSendHeaderResponseNotReady BadStatusLine LineTooLongRemoteDisconnectederror responsesPiZUNKNOWNZIdlezRequest-startedz Request-sentcCsi|] }||jqS)phrase).0vrr0/opt/alt/python38/lib64/python3.8/http/client.py jsrids[^:\s][^:\r\n]*s\n(?![ \t])|\r(?![ \t\n])z[- ]z[-]ZPATCHZPOSTZPUTdatac Cshz |dWStk rb}z8t|j|j|j|jd|||j|j|fdW5d}~XYnXdS)Nlatin-1z`%s (%.20r) is not valid Latin-1. Use %s.encode('utf-8') if you want to send it encoded in UTF-8.)encodeUnicodeEncodeErrorencodingobjectstartendtitle)rnameerrrrr_encodes r(c@seZdZddZdS) HTTPMessagecCsj|d}t|}g}d}|D]@}|d||krBd}n|ddsVd}|r$||q$|S)N:r)lowerlenkeysisspaceappend)selfr&nZlstZhitlinerrrgetallmatchingheaderss   z!HTTPMessage.getallmatchingheadersN)__name__ __module__ __qualname__r4rrrrr)sr)cCsXg}|td}t|tkr&td||t|tkrHtdt|dkrqTq|S)Nr+ header linezgot more than %d headers  )readline_MAXLINEr-rr0 _MAXHEADERSr)fpheadersr3rrr _read_headerss    rBcCs,t|}d|d}tjj|d|S)Nr< iso-8859-1)_class)rBjoindecodeemailparserZParserZparsestr)r@rDrAZhstringrrr parse_headerss rIcseZdZd@ddZddZddZd d Zd d Zfd dZfddZ ddZ ddZ dAddZ ddZ ddZddZddZdd Zd!d"Zd#d$Zd%d&ZdBd(d)ZdCd*d+ZdDfd,d- Zd.d/Zd0d1Zd2d3ZdEd4d5Zd6d7Zd8d9Zd:d;Zdd?Z Z!S)FrrNcCsR|d|_||_||_d|_|_t|_t|_t|_ t|_ t|_ t|_ t|_ dS)Nrb)Zmakefiler@ debuglevel_methodrAmsg_UNKNOWNversionstatusreasonchunked chunk_leftlength will_close)r1sockrKmethodurlrrr__init__s  zHTTPResponse.__init__c Cst|jtdd}t|tkr*td|jdkrBtdt||sNt dz| dd\}}}WnFt k rz| dd\}}d}Wnt k rd}YnXYnX| d s| t|z$t|}|d ks|d krt|Wnt k rt|YnX|||fS) Nr+rCz status linerzreply:z-Remote end closed connection without responsezHTTP/ri)strr@r=r>r-rrKprintreprrsplit ValueError startswith _close_connrint)r1r3rOrPrQrrr _read_statuss2    zHTTPResponse._read_statusc Cs|jdk rdS|\}}}|tkr&qHt|j}|jdkrDtd|~q||_|_| |_ |dkrnd|_ n| drd|_ nt |t|j|_|_|jdkr|jD]\}}td|d|q|jd }|r|d krd |_d|_nd |_||_d|_|jd }|rb|jsbzt||_Wntk rLd|_YnX|jdkrhd|_nd|_|tks|tksd|krdksn|jdkrd|_|js|js|jdkrd |_dS)Nrzheaders:)zHTTP/1.0zHTTP/0.9 zHTTP/1. header:r*transfer-encodingrRTFcontent-lengthrHEAD)rArdZCONTINUErBr@rKr]coderPstriprQrOrarrIrMitemsgetr,rRrS _check_closerUrTrcr`Z NO_CONTENTZ NOT_MODIFIEDrL) r1rOrPrQZskipped_headershdrvalZtr_encrTrrrbegin5sf               zHTTPResponse.begincCsv|jd}|jdkr.|r*d|kr*dSdS|jdr>dS|rRd|krRdS|jd}|rrd|krrdSdS)NZ connectionrfcloseTFz keep-alivezproxy-connection)rArorOr,)r1ZconnZpconnrrrrp}s    zHTTPResponse._check_closecCs|j}d|_|dSN)r@rt)r1r@rrrrbszHTTPResponse._close_conncs$ztW5|jr|XdSru)r@rbsuperrtr1 __class__rrrtszHTTPResponse.closecst|jr|jdSru)rvflushr@rwrxrrrzs zHTTPResponse.flushcCsdS)NTrrwrrrreadableszHTTPResponse.readablecCs |jdkSru)r@rwrrrisclosedszHTTPResponse.isclosedcCs|jdkrdS|jdkr$|dS|dk rRt|}||}t|d|S|jr`|S|j dkrv|j }n6z| |j }Wnt k r|YnXd|_ ||SdS)Nr<rkr) r@rLrb bytearrayreadinto memoryviewtobytesrR_readall_chunkedrTread _safe_readr )r1amtbr2srrrrs*     zHTTPResponse.readcCs|jdkrdS|jdkr$|dS|jr4||S|jdk r^t||jkr^t|d|j}|j|}|s||r||n&|jdk r|j|8_|js||S)Nrrk) r@rLrbrR_readinto_chunkedrTr-rr~)r1rr2rrrr~s$       zHTTPResponse.readintocCsr|jtd}t|tkr$td|d}|dkrB|d|}z t|dWStk rl|YnXdS)Nr+z chunk size;r) r@r=r>r-rfindrcr`rb)r1r3irrr_read_next_chunk_sizes    z"HTTPResponse._read_next_chunk_sizecCs:|jtd}t|tkr$td|s*q6|dkrq6qdS)Nr+z trailer liner9)r@r=r>r-rr1r3rrr_read_and_discard_trailers z&HTTPResponse._read_and_discard_trailercCsl|j}|sh|dk r|dz |}Wntk rDtdYnX|dkrb||d}||_|S)NrZr<r)rSrrr`r rrb)r1rSrrr_get_chunk_left s  zHTTPResponse._get_chunk_leftcCsbg}z6|}|dkrq0|||d|_qd|WStk r\td|YnXdSNrr<)rr0rrSrEr )r1valuerSrrrr8s zHTTPResponse._readall_chunkedcCsd}t|}zv|}|dkr$|WSt||krN||}|||_||WS|d|}||}||d}||7}d|_qWn(tk rtt|d|YnXdS)Nr)rrr-_safe_readintorSr bytes)r1rZ total_bytesZmvbrSr2Ztemp_mvbrrrrFs"        zHTTPResponse._readinto_chunkedcCs.|j|}t||kr*t||t||Sru)r@rr-r )r1rrrrrr^s  zHTTPResponse._safe_readcCs:t|}|j|}||kr6tt|d||||Sru)r-r@r~r r)r1rrr2rrrrjs  zHTTPResponse._safe_readintocCs|jdks|jdkrdS|jr(||S|jdk rJ|dksD||jkrJ|j}|j|}|sh|rh|n|jdk r|jt|8_|SNrkr<r)r@rLrR_read1_chunkedrTread1rbr-)r1r2resultrrrrrs    zHTTPResponse.read1cCs4|jdks|jdkrdS|jr(||S|j|S)Nrkr<)r@rLrR _peek_chunkedpeek)r1r2rrrrs  zHTTPResponse.peekcs|jdks|jdkrdS|jr*t|S|jdk rL|dksF||jkrL|j}|j|}|sj|rj|n|jdk r|jt|8_|Sr)r@rLrRrvr=rTrbr-)r1limitrrxrrr=s    zHTTPResponse.readlinecCsd|}|dks|dkrdSd|kr0|ks6n|}|j|}|jt|8_|s`td|Sr)rr@rrSr-r )r1r2rSrrrrrs zHTTPResponse._read1_chunkedcCsDz |}Wntk r"YdSX|dkr0dS|j|d|S)Nr<)rr r@r)r1r2rSrrrrs zHTTPResponse._peek_chunkedcCs |jSru)r@filenorwrrrrszHTTPResponse.filenocCsF|jdkrt|j|p|}t|ts4t|ds8|Sd|SdS)N__iter__z, )rArZget_all isinstancer\hasattrrE)r1r&defaultrArrr getheaders zHTTPResponse.getheadercCs|jdkrtt|jSru)rArlistrnrwrrr getheaderss zHTTPResponse.getheaderscCs|SrurrwrrrrszHTTPResponse.__iter__cCs|jSru)rArwrrrinfoszHTTPResponse.infocCs|jSru)rXrwrrrgeturls zHTTPResponse.geturlcCs|jSru)rPrwrrrgetcodeszHTTPResponse.getcode)rNN)N)r)r)r)N)"r5r6r7rYrdrsrprbrtrzr{r|rr~rrrrrrrrrr=rrrrrrrrr __classcell__rrrxrrs< !H  "      c@s eZdZdZdZeZeZdZ dZ e ddZ e ddZ d ejd d fd d Zd7d dZddZddZddZddZddZddZddZddZd8d d!Zd9d"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Z d:dd.d/d0Z!d ifdd.d1d2Z"d3d4Z#d5d6Z$d S);rrfzHTTP/1.1r+rcCs t|tjSru)rio TextIOBase)streamrrr _is_textIOszHTTPConnection._is_textIOcCsf|dkr|tkrdSdSt|dr*dSzt|}|jWStk rNYnXt|trbt|SdS)Nrr) upper_METHODS_EXPECTING_BODYrrnbytes TypeErrorrr\r-)bodyrWZmvrrr_get_content_lengths   z"HTTPConnection._get_content_lengthN cCsn||_||_||_d|_g|_d|_t|_d|_d|_ d|_ i|_ | ||\|_ |_||j tj|_dSru)timeoutsource_address blocksizerV_buffer_HTTPConnection__response_CS_IDLE_HTTPConnection__staterL _tunnel_host _tunnel_port_tunnel_headers _get_hostporthostport_validate_hostsocketZcreate_connection_create_connection)r1rrrrrrrrrY4s zHTTPConnection.__init__cCs<|jrtd|||\|_|_|r.||_n |jdS)Nz.Can't set up tunnel for established connection)rV RuntimeErrorrrrrclear)r1rrrArrr set_tunnelJs zHTTPConnection.set_tunnelcCs|dkr|d}|d}||krzt||dd}WnHtk r||dddkrh|j}ntd||ddYnX|d|}n|j}|r|ddkr|ddkr|dd}||fS) Nr*]r+r[znonnumeric port: '%s'r[r)rfindrcr` default_portr )r1rrrjrrrrbs   zHTTPConnection._get_hostportcCs ||_dSru)rK)r1levelrrrset_debuglevelvszHTTPConnection.set_debuglevelc Csd|j|jf}|d}|||jD](\}}d||f}|d}||q.|d|j|j|jd}| \}} } | t j j kr| td| | f|jtd} t| tkrtd | sq| d krq|jd krtd | qdS) NzCONNECT %s:%d HTTP/1.0 asciiz%s: %s rr:rWzTunnel connection failed: %d %sr+r8r9rrg)rrrsendrrnresponse_classrVrLrdhttp HTTPStatusZOKrtOSErrorrmr@r=r>r-rrKr]rF) r1Z connect_strZ connect_bytesheaderrZ header_strZ header_bytesresponserOrlmessager3rrr_tunnelys4         zHTTPConnection._tunnelcCsB||j|jf|j|j|_|jtjtj d|j r>| dS)Nr+) rrrrrrVZ setsockoptrZ IPPROTO_TCPZ TCP_NODELAYrrrwrrrconnects zHTTPConnection.connectcCsBt|_z|j}|r d|_|W5|j}|rsz/HTTPConnection._send_request..rr+rzaccept-encodingrrirhFrzUnable to determine size of %rTzTransfer-EncodingrRzContent-Lengthrr) frozensetrrrKr]rr\rnrr(r) r1rWrXrrArZ header_namesZskipsZcontent_lengthrqrrrrr s0      zHTTPConnection._send_requestcCs|jr|jrd|_|jtks&|jr0t|j|jdkrR|j|j|j|jd}n|j|j|jd}zNz | Wnt k r| YnXt |_|j r| n||_|WS| YnXdS)Nrr)rr|rrrrKrrVrLrsConnectionErrorrtrrU)r1rrrr getresponses.     zHTTPConnection.getresponse)NN)NF)FF)N)%r5r6r7rrrr HTTP_PORTrrrK staticmethodrrr_GLOBAL_DEFAULT_TIMEOUTrYrrrrrrtrrrrrrrrrrrrr rrrrrrsL     & 6    .csDeZdZeZdddejdfddddfdd ZfddZZ S)HTTPSConnectionNr)contextcheck_hostnamerc stt|j||||| d|dk s2|dk s2|dk rHddl} | dtd||_||_|dkrtt }|j dk rtd|_ |j tj k} |dkr|j }|r| std|s|r||||j dk rd|_ ||_|dk r||j_ dS)N)rrzTkey_file, cert_file and check_hostname are deprecated, use a custom context instead.rZTzMcheck_hostname needs a SSL context with either CERT_OPTIONAL or CERT_REQUIRED)rvrrYwarningswarnDeprecationWarningkey_file cert_filesslZ_create_default_https_contextZpost_handshake_authZ verify_modeZ CERT_NONErr`Zload_cert_chain_context) r1rrrrrrrrrrZ will_verifyrxrrrYcs<    zHTTPSConnection.__init__cs6t|jr|j}n|j}|jj|j|d|_dS)N)server_hostname)rvrrrrZ wrap_socketrV)r1rrxrrrs  zHTTPSConnection.connect) r5r6r7 HTTPS_PORTrrrrYrrrrrxrr\s$rc@s eZdZdS)rNr5r6r7rrrrrsc@s eZdZdS)rNrrrrrrsc@s eZdZdS)r Nrrrrrr sc@seZdZddZdS)rcCs|f|_||_dSru)argsrO)r1rOrrrrYszUnknownProtocol.__init__Nr5r6r7rYrrrrrsc@s eZdZdS)rNrrrrrrsc@s eZdZdS)r Nrrrrrr sc@s$eZdZdddZddZejZdS)r NcCs|f|_||_||_dSru)rpartialexpected)r1r!r"rrrrYszIncompleteRead.__init__cCs2|jdk rd|j}nd}d|jjt|j|fS)Nz, %i more expectedr[z%s(%i bytes read%s))r"ryr5r-r!)r1errr__repr__s  zIncompleteRead.__repr__)N)r5r6r7rYr$r"__str__rrrrr s c@s eZdZdS)r Nrrrrrr sc@s eZdZdS)r Nrrrrrr sc@s eZdZdS)rNrrrrrrsc@s eZdZdS)rNrrrrrrsc@seZdZddZdS)rcCs|s t|}|f|_||_dSru)r^rr3rrrrrYszBadStatusLine.__init__Nr rrrrrsc@seZdZddZdS)rcCst|dt|fdS)Nz&got more than %d bytes when reading %s)rrYr>)r1Z line_typerrrrYszLineTooLong.__init__Nr rrrrrsc@seZdZddZdS)rcOs"t|dtj|f||dS)Nr[)rrYConnectionResetError)r1poskwrrrrYs zRemoteDisconnected.__init__Nr rrrrrs)r)@Z email.parserrGZ email.messagerrrerZcollections.abcrZ urllib.parser__all__rrrNrrrglobalsupdater __members__rrr>r?compile fullmatchrrrrrrr(rZMessager)rBrIBufferedIOBaserrr ImportErrorrr0 Exceptionrrr rrr r r r rrrrr&rrrrrrGs        W 8