o aia~@sddlmZmZmZddlmZddlmZmZddl Z ddl Z ddl m Z m Z ddlmZddlmZmZmZmZdd lmZdd lmZed d eDZed d eDZedd eDZeeddgBZdZejreddkr{eddks}Je edde!ddZ"ne eZ"hdZ#e dZ$iZ%Gddde&Z'ddZ(Gddde&Z)Gddde)Z*Gdd d e+Z,Gd!d"d"e&Z-Gd#d$d$e&Z.d%d&Z/dS)')absolute_importdivisionunicode_literals) text_type) http_clienturllibN)BytesIOStringIO) webencodings)EOFspaceCharacters asciiLettersasciiUppercase)_ReparseException)_utilscCg|]}|dqSasciiencode.0itemr/builddir/build/BUILDROOT/alt-python310-pip-21.3.1-5.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_vendor/html5lib/_inputstream.py rcCrrrrrrrrrcCrrrrrrrrr> i iii iiiiiiiiii iii ii i iiiiii i i ii iiz[ - -/:-@\[-`{-~]c@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)BufferedStreamzBuffering for streams that do not have buffering of their own The buffer is implemented as a list of chunks on the assumption that joining many strings will be slow since it is O(n**2) cCs||_g|_ddg|_dS)Nr r)streambufferposition)selfr#rrr__init__:szBufferedStream.__init__cCs<d}|jd|jdD]}|t|7}q ||jd7}|SNrr )r$r%len)r&poschunkrrrtell?s zBufferedStream.tellcCsd||ksJ|}d}t|j||kr+|t|j|8}|d7}t|j||ks||g|_dSr()_bufferedBytesr)r$r%)r&r*offsetirrrseekFszBufferedStream.seekcCsP|js||S|jdt|jkr#|jdt|jdkr#||S||S)Nrr r )r$ _readStreamr%r)_readFromBufferr&bytesrrrreadOs    zBufferedStream.readcCstdd|jDS)NcSsg|]}t|qSr)r)rrrrrYsz1BufferedStream._bufferedBytes..)sumr$r&rrrr-XzBufferedStream._bufferedBytescCs<|j|}|j||jdd7<t||jd<|Sr()r#r5r$appendr%r))r&r4datarrrr1[s  zBufferedStream._readStreamcCs|}g}|jd}|jd}|t|jkrc|dkrc|dksJ|j|}|t||kr6|}|||g|_nt||}|t|g|_|d7}|||||||8}d}|t|jkrc|dks|rm|||d|S)Nrr )r%r)r$r9r1join)r&r4remainingBytesrv bufferIndex bufferOffset bufferedData bytesToReadrrrr2bs(      zBufferedStream._readFromBufferN) __name__ __module__ __qualname____doc__r'r,r0r5r-r1r2rrrrr"3s   r"cKst|tjst|tjjrt|jtjrd}nt|dr%t|dt }nt|t }|rCdd|D}|r;t d|t |fi|St |fi|S)NFr5rcSsg|] }|dr|qS) _encoding)endswith)rxrrrrsz#HTMLInputStream..z3Cannot set an encoding with a unicode input, set %r) isinstancer HTTPResponserresponseaddbasefphasattrr5r TypeErrorHTMLUnicodeInputStreamHTMLBinaryInputStream)sourcekwargs isUnicode encodingsrrrHTMLInputStream}s      rWc@speZdZdZdZddZddZddZd d Zd d Z d dZ dddZ ddZ ddZ dddZddZdS)rQProvides a unicode stream of characters to the HTMLTokenizer. This class takes care of character encoding and removing or replacing incorrect byte-sequences and also provides column and line tracking. i(cCsZtjsd|_ntddkr|j|_n|j|_dg|_tddf|_| ||_ | dS)Initialises the HTMLInputStream. HTMLInputStream(source, [encoding]) -> Normalized stream from source for use by html5lib. source can be either a file-object, local filename or a string. The optional encoding parameter must be a string that indicates the encoding. If specified, that encoding will be used, regardless of any BOM or later declaration (such as in a meta element) Nu􏿿r rutf-8certain) rsupports_lone_surrogatesreportCharacterErrorsr)characterErrorsUCS4characterErrorsUCS2newLineslookupEncoding charEncoding openStream dataStreamreset)r&rSrrrr's    zHTMLUnicodeInputStream.__init__cCs.d|_d|_d|_g|_d|_d|_d|_dS)Nr)r+ chunkSize chunkOffseterrors prevNumLines prevNumCols_bufferedCharacterr7rrrres zHTMLUnicodeInputStream.resetcCst|dr |}|St|}|SzvProduces a file object from source. source can be either a file object, local filename or a string. r5)rOr r&rSr#rrrrcs z!HTMLUnicodeInputStream.openStreamcCsZ|j}|dd|}|j|}|dd|}|dkr#|j|}||fS||d}||fS)N rr r )r+countrjrfindrk)r&r.r+nLines positionLine lastLinePospositionColumnrrr _positions   z HTMLUnicodeInputStream._positioncCs||j\}}|d|fS)z:Returns (line, col) of the current position in the stream.r )rvrh)r&linecolrrrr%s zHTMLUnicodeInputStream.positioncCs6|j|jkr |s tS|j}|j|}|d|_|S)zo Read one character from the stream or queue if available. Return EOF when EOF is reached. r )rhrg readChunkr r+)r&rhcharrrrrzs   zHTMLUnicodeInputStream.charNcCs|dur|j}||j\|_|_d|_d|_d|_|j|}|j r,|j |}d|_ n|s0dSt |dkrWt |d}|dksLd|krJdkrWnn |d|_ |dd}|j r_| || d d }| d d }||_t ||_d S) NrfrFr r iz ro T)_defaultChunkSizervrgrjrkr+rhrdr5rlr)ordr]replace)r&rgr:lastvrrrrys0           z HTMLUnicodeInputStream.readChunkcCs(ttt|D]}|jdq dS)Ninvalid-codepoint)ranger)invalid_unicode_refindallrir9)r&r:_rrrr^sz*HTMLUnicodeInputStream.characterErrorsUCS4cCsd}t|D]Q}|r qt|}|}t|||dr9t|||d}|tvr6|j dd}q|dkrP|dkrP|t |dkrP|j dqd}|j dqdS)NFrTr|ir ) rfinditerrgroupstartrisSurrogatePairsurrogatePairToCodepointnon_bmp_invalid_codepointsrir9r))r&r:skipmatch codepointr*char_valrrrr_#s"  z*HTMLUnicodeInputStream.characterErrorsUCS2Fc Cszt||f}Wn4ty< |D] }t|dksJqddd|D}|s-d|}td|}t||f<Ynwg} ||j|j}|durT|j|j krSn*n| }||j krl| |j|j|||_n| |j|jd| s|nq@d|} | S) z Returns a string of characters from the stream up to but not including any character in 'characters' or EOF. 'characters' must be a container that supports the 'in' method and iteration over its characters. TrfcSsg|]}dt|qS)z\x%02x)r)rcrrrrHsz5HTMLUnicodeInputStream.charsUntil..z^%sz[%s]+N) charsUntilRegExKeyErrorrr<recompilerr+rhrgendr9ry) r& charactersoppositecharsrregexr>mrrrrr charsUntil:s:     z!HTMLUnicodeInputStream.charsUntilcCsZ|tur)|jdkr||j|_|jd7_dS|jd8_|j|j|ks+JdSdSr()r rhr+rg)r&rzrrrungetis   zHTMLUnicodeInputStream.ungetN)F)rCrDrErFr~r'rercrvr%rzryr^r_rrrrrrrQs   &  /rQc@sReZdZdZ   dddZddZd d Zdd d Zd dZddZ ddZ dS)rRrXN windows-1252TcCsn|||_t||jd|_d|_||_||_||_||_ ||_ | ||_ |j ddus1J| dS)rYidrN)rc rawStreamrQr' numBytesMetanumBytesChardetoverride_encodingtransport_encodingsame_origin_parent_encodinglikely_encodingdefault_encodingdetermineEncodingrbre)r&rSrrrrr useChardetrrrr's   zHTMLBinaryInputStream.__init__cCs&|jdj|jd|_t|dS)Nrr)rb codec_info streamreaderrrdrQrer7rrrreszHTMLBinaryInputStream.resetcCsJt|dr|}nt|}z ||W|Sty$t|}Y|Swrm)rOrr0r, Exceptionr"rnrrrrcs  z HTMLBinaryInputStream.openStreamcCs|df}|ddur|St|jdf}|ddur|St|jdf}|ddur,|S|df}|ddur:|St|jdf}|ddurQ|djdsQ|St|jdf}|ddur`|S|rzddl m }Wn t ysYn@wg}|}|j s|j |j}t|tsJ|sn |||||j r||t|jd}|j d|dur|dfSt|jdf}|ddur|StddfS)Nr[r tentativezutf-16)UniversalDetectorencodingr) detectBOMrarrdetectEncodingMetarname startswithr%pip._vendor.chardet.universaldetectorr ImportErrordonerr5rrJr4r9feedcloseresultr0r)r&chardetrbrbuffersdetectorr$rrrrrsV             z'HTMLBinaryInputStream.determineEncodingcCs|jddks Jt|}|durdS|jdvr$td}|dus"JdS||jdkr5|jddf|_dS|jd|df|_|td|jd|f)Nr r[utf-16beutf-16lerZrzEncoding changed from %s to %s)rbrarrr0rer)r& newEncodingrrrchangeEncodings   z$HTMLBinaryInputStream.changeEncodingc Cstjdtjdtjdtjdtjdi}|jd}t|t sJ| |dd}d}|s?| |}d}|s?| |dd }d }|rK|j |t |S|j d dS) zAttempts to detect at BOM at the start of the stream. If an encoding can be determined from the BOM return the name of the encoding otherwise return NonerZrrzutf-32lezutf-32beNrr) codecsBOM_UTF8 BOM_UTF16_LE BOM_UTF16_BE BOM_UTF32_LE BOM_UTF32_BErr5rJr4getr0ra)r&bomDictstringrr0rrrrs&      zHTMLBinaryInputStream.detectBOMcCsV|j|j}t|tsJt|}|jd|}|dur)|jdvr)t d}|S)z9Report the encoding declared by the meta element rNrrZ) rr5rrJr4EncodingParserr0 getEncodingrra)r&r$parserrrrrr3s z(HTMLBinaryInputStream.detectEncodingMeta)NNNNrT)T) rCrDrErFr'rercrrrrrrrrrRzs * > "rRc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ e e e Z ddZe eZefddZddZddZddZdS) EncodingByteszString-like object with an associated position and various extra methods If the position is ever greater than the string length then an exception is raisedcCst|tsJt||Sr)rJr4__new__lowerr&valuerrrrFszEncodingBytes.__new__cCs d|_dS)Nr )rvrrrrr'Js zEncodingBytes.__init__cCs|Srrr7rrr__iter__NszEncodingBytes.__iter__cCs<|jd}|_|t|krt|dkrt|||dS)Nr rrvr) StopIterationrPr&prrr__next__Qs  zEncodingBytes.__next__cCs|Sr)rr7rrrnextYszEncodingBytes.nextcCs@|j}|t|kr t|dkrt|d|_}|||dSr(rrrrrprevious]s zEncodingBytes.previouscCs|jt|kr t||_dSrrvr)r)r&r%rrr setPositionfs zEncodingBytes.setPositioncCs&|jt|kr t|jdkr|jSdS)Nrrr7rrr getPositionks  zEncodingBytes.getPositioncCs||j|jdSNr )r%r7rrrgetCurrentByteur8zEncodingBytes.getCurrentBytecCsR|j}|t|kr$|||d}||vr||_|S|d7}|t|ks ||_dS)zSkip past a list of charactersr Nr%r)rvr&rrrrrrrzs  zEncodingBytes.skipcCsR|j}|t|kr$|||d}||vr||_|S|d7}|t|ks ||_dSrrrrrr skipUntils  zEncodingBytes.skipUntilcCs(|||j}|r|jt|7_|S)zLook for a sequence of bytes at the start of a string. If the bytes are found return True and advance the position to the byte after the match. Otherwise return False and leave the position alone)rr%r))r&r4r>rrr matchBytesszEncodingBytes.matchBytescCs6z|||jt|d|_WdStytw)zLook for the next sequence of bytes matching a given sequence. If a match is found advance the position to the last byte of the matchr T)indexr%r)rv ValueErrorrr3rrrjumpTos  zEncodingBytes.jumpToN)rCrDrErFrr'rrrrrrpropertyr%r currentBytespaceCharactersBytesrrrrrrrrrBs"     rc@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS)rz?Mini parser for detecting character encoding from meta elementscCst||_d|_dS)z3string - the data to work on for encoding detectionN)rr:rr&r:rrrr's  zEncodingParser.__init__c Csd|jvrdSd|jfd|jfd|jfd|jfd|jfd|jff}|jD]?}d}z|jdWn ty<Y|j Sw|D]\}}|j|r\z|}Wn ty[d}Ynwq?|sc|j Sq$|j S) Nsr:rr7rrrrs zEncodingParser.handleCommentcCs|jjtvrdSd}d} |}|durdS|ddkr/|ddk}|r.|dur.||_dSn?|ddkrG|d}t|}|durF||_dSn'|ddkrntt|d}|}|durnt|}|durn|rl||_dS|}q ) NTFrs http-equivr s content-typecharsetscontent) r:rr getAttributerraContentAttrParserrparse)r& hasPragmapendingEncodingattrtentativeEncodingcodec contentParserrrrrs@      zEncodingParser.handleMetacCs |dS)NF)handlePossibleTagr7rrrrs z%EncodingParser.handlePossibleStartTagcCst|j|dS)NT)rr:rr7rrrrs  z#EncodingParser.handlePossibleEndTagcCsj|j}|jtvr|r||dS|t}|dkr#|dS|}|dur3|}|dus+dS)NTr)r:rasciiLettersBytesrrrspacesAngleBracketsr)r&endTagr:rrrrrrs  z EncodingParser.handlePossibleTagcCr)Nrrr7rrrrs zEncodingParser.handleOthercCs|j}|ttdgB}|dust|dksJ|dvrdSg}g} |dkr+|r+n0|tvr4|}n'|dvr?d|dfS|tvrK||n |durQdS||t |}q$|dkrj| d|dfSt ||}|d vr|} t |}||krt |d|d|fS|tvr||n||qy|d krd|dfS|tvr||n |durdS|| t |}|t vrd|d|fS|tvr||n |durdS||q) z_Return a name,value pair for the next attribute in the stream, if one is found, or None/Nr )rNT=)r rr;)'"r) r:rr frozensetr)r<asciiUppercaseBytesr9rrrr)r&r:rattrName attrValue quoteCharrrrrsn      zEncodingParser.getAttributeN) rCrDrErFr'rrrrrrrrrrrrrs$ rc@seZdZddZddZdS)rcCst|tsJ||_dSr)rJr4r:rrrrr'as zContentAttrParser.__init__cCszy|jd|jjd7_|j|jjdksWdS|jjd7_|j|jjdvrS|jj}|jjd7_|jj}|j|rP|j||jjWSWdS|jj}z|jt|j||jjWWStyy|j|dYWSwtyYdSw)Nrr r )r r )r:rr%rrrrr)r& quoteMark oldPositionrrrres2         zContentAttrParser.parseN)rCrDrEr'rrrrrr`s rcCs\t|trz|d}Wn tyYdSw|dur,zt|WSty+YdSwdS)z{Return the python codec name corresponding to an encoding or None if the string doesn't correspond to a valid encoding.rN)rJr4decodeUnicodeDecodeErrorr lookupAttributeError)rrrrras    ra)0 __future__rrrZpip._vendor.sixrpip._vendor.six.movesrrrriorr pip._vendorr constantsr r rrrrfrrrrrrinvalid_unicode_no_surrogater\rprevalrrascii_punctuation_rerobjectr"rWrQrRr4rrrrarrrrsJ      JgIb= '