3 ”Rea~ã @sìddlmZmZmZddlmZddlmZmZddl Z ddl Z ddl m Z m Z ddlmZddlmZmZmZmZdd lmZdd lmZed d „eDƒƒZed d „eDƒƒZedd „eDƒƒZeeddgƒBZdZej�redEdkrøejdƒdksüt ‚e j!eddF…e"dƒdƒZ#n e j!eƒZ#ddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3h Z$e j!d4ƒZ%iZ&Gd5d6„d6e'ƒZ(d7d8„Z)Gd9d:„d:e'ƒZ*Gd;d<„d„d>e,ƒZ-Gd?d@„d@e'ƒZ.GdAdB„dBe'ƒZ/dCdD„Z0dS)Gé)Úabsolute_importÚdivisionÚunicode_literals)Ú text_type)Ú http_clientÚurllibN)ÚBytesIOÚStringIO)Ú webencodingsé)ÚEOFÚspaceCharactersÚ asciiLettersÚasciiUppercase)Ú_ReparseException)Ú_utilscCsg|]}|jdƒ‘qS)Úascii)Úencode)Ú.0Úitem©rú�/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/html5lib/_inputstream.pyú srcCsg|]}|jdƒ‘qS)r)r)rrrrrrscCsg|]}|jdƒ‘qS)r)r)rrrrrrsó>ó.)Úsumr)r!rrrr'XszBufferedStream._bufferedBytescCs<|jj|ƒ}|jj|ƒ|jdd7<t|ƒ|jd<|S)Nrr )rr/rÚappendr r#)r!r.Údatarrrr,[s   zBufferedStream._readStreamcCsÔ|}g}|jd}|jd}x˜|t|jƒkr´|dkr´|dks@t‚|j|}|t|ƒ|krn|}|||g|_n"t|ƒ|}|t|ƒg|_|d7}|j||||…ƒ||8}d}qW|rÊ|j|j|ƒƒdj|ƒS)Nrr ó)r r#rr(r1r,Újoin)r!r.ÚremainingBytesÚrvÚ bufferIndexÚ bufferOffsetÚ bufferedDataÚ bytesToReadrrrr-bs&     zBufferedStream._readFromBufferN) Ú__name__Ú __module__Ú __qualname__Ú__doc__r"r&r+r/r'r,r-rrrrr3s  rcKs’t|tjƒs(t|tjjƒr.t|jtjƒr.d}n&t|dƒrJt|jdƒt ƒ}n t|t ƒ}|r‚dd„|Dƒ}|rvt d|ƒ‚t |f|ŽSt |f|ŽSdS)NFr/rcSsg|]}|jdƒr|‘qS)Ú _encoding)Úendswith)rÚxrrrr‹sz#HTMLInputStream..z3Cannot set an encoding with a unicode input, set %r) Ú isinstancerÚ HTTPResponserÚresponseÚaddbaseÚfpÚhasattrr/rÚ TypeErrorÚHTMLUnicodeInputStreamÚHTMLBinaryInputStream)ÚsourceÚkwargsÚ isUnicodeÚ encodingsrrrÚHTMLInputStream}s     rOc@speZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z ddd„Z dd„Z dd„Z ddd„Zdd„ZdS)rIz×Provides 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|_ntdƒdkr$|j|_n|j|_dg|_tdƒdf|_|j |ƒ|_ |j ƒdS)a¿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 rzutf-8Úcertain) rÚsupports_lone_surrogatesÚreportCharacterErrorsr#ÚcharacterErrorsUCS4ÚcharacterErrorsUCS2ÚnewLinesÚlookupEncodingÚ charEncodingÚ openStreamÚ dataStreamÚreset)r!rKrrrr"žs   zHTMLUnicodeInputStream.__init__cCs.d|_d|_d|_g|_d|_d|_d|_dS)NÚr)r%Ú chunkSizeÚ chunkOffsetÚerrorsÚ prevNumLinesÚ prevNumColsÚ_bufferedCharacter)r!rrrrZ¾szHTMLUnicodeInputStream.resetcCst|dƒr|}nt|ƒ}|S)zvProduces a file object from source. source can be either a file object, local filename or a string. r/)rGr )r!rKrrrrrXÌs z!HTMLUnicodeInputStream.openStreamcCsT|j}|jdd|ƒ}|j|}|jdd|ƒ}|dkr@|j|}n ||d}||fS)NÚ rr r)r%Úcountr_Úrfindr`)r!r)r%ÚnLinesÚ positionLineÚ lastLinePosÚpositionColumnrrrÚ _positionÚs   z HTMLUnicodeInputStream._positioncCs|j|jƒ\}}|d|fS)z:Returns (line, col) of the current position in the stream.r )rir])r!ÚlineÚcolrrrr åszHTMLUnicodeInputStream.positioncCs6|j|jkr|jƒstS|j}|j|}|d|_|S)zo Read one character from the stream or queue if available. Return EOF when EOF is reached. r )r]r\Ú readChunkr r%)r!r]Úcharrrrrmês   zHTMLUnicodeInputStream.charNcCsê|dkr|j}|j|jƒ\|_|_d|_d|_d|_|jj|ƒ}|j rX|j |}d|_ n|s`dSt |ƒdkr®t |d ƒ}|dks˜d|ko’dknr®|d |_ |dd…}|j r¾|j |ƒ|j dd ƒ}|j d d ƒ}||_t |ƒ|_d S)Nr[rFr é iØiÿÛz rbú Trrr)Ú_defaultChunkSizerir\r_r`r%r]rYr/rar#ÚordrRÚreplace)r!r\r2Úlastvrrrrlùs0           z HTMLUnicodeInputStream.readChunkcCs,x&tttj|ƒƒƒD]}|jjdƒqWdS)Nzinvalid-codepoint)Úranger#Úinvalid_unicode_reÚfindallr^r1)r!r2Ú_rrrrSsz*HTMLUnicodeInputStream.characterErrorsUCS4cCsºd}x°tj|ƒD]¢}|rqt|jƒƒ}|jƒ}tj|||d…ƒrttj|||d…ƒ}|tkrn|j j dƒd}q|dkr¢|dkr¢|t |ƒdkr¢|j j dƒqd}|j j dƒqWdS)NFézinvalid-codepointTiØiÿßr ) ruÚfinditerrqÚgroupÚstartrÚisSurrogatePairÚsurrogatePairToCodepointÚnon_bmp_invalid_codepointsr^r1r#)r!r2ÚskipÚmatchÚ codepointr$Úchar_valrrrrT#s   z*HTMLUnicodeInputStream.characterErrorsUCS2Fc Csyt||f}Wnltk r|x|D]}t|ƒdks&t‚q&Wdjdd„|Dƒƒ}|s^d|}tjd|ƒ}t||f<YnXg}x||j|j|j ƒ}|dkr¬|j |j krÜPn0|j ƒ}||j krÜ|j |j|j |…ƒ||_ P|j |j|j d…ƒ|j ƒs„Pq„Wdj|ƒ} | 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. é€r[cSsg|]}dt|ƒ‘qS)z\x%02x)rq)rÚcrrrrHsz5HTMLUnicodeInputStream.charsUntil..z^%sz[%s]+N)ÚcharsUntilRegExÚKeyErrorrqr(r4ÚreÚcompiler€r%r]r\Úendr1rl) r!Ú charactersÚoppositeÚcharsr„Úregexr6Úmr‰ÚrrrrÚ charsUntil:s2     z!HTMLUnicodeInputStream.charsUntilcCsT|tk rP|jdkr.||j|_|jd7_n"|jd8_|j|j|ksPt‚dS)Nrr )r r]r%r\r()r!rmrrrÚungetis   zHTMLUnicodeInputStream.unget)N)F)r;r<r=r>rpr"rZrXrir rmrlrSrTr�r‘rrrrrI”s   & /rIc@sLeZdZdZddd„Zdd„Zd d „Zdd d „Zd d„Zdd„Z dd„Z dS)rJz×Provides 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. Nú windows-1252TcCsn|j|ƒ|_tj||jƒd|_d|_||_||_||_||_ ||_ |j |ƒ|_ |j ddk sbt ‚|jƒdS)a¿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) iédrN)rXÚ rawStreamrIr"Ú numBytesMetaÚnumBytesChardetÚoverride_encodingÚtransport_encodingÚsame_origin_parent_encodingÚlikely_encodingÚdefault_encodingÚdetermineEncodingrWr(rZ)r!rKr—r˜r™ršr›Ú useChardetrrrr"‚s  zHTMLBinaryInputStream.__init__cCs&|jdjj|jdƒ|_tj|ƒdS)Nrrr)rWÚ codec_infoÚ streamreaderr”rYrIrZ)r!rrrrZ¬szHTMLBinaryInputStream.resetc CsLt|dƒr|}nt|ƒ}y|j|jƒƒWntk rFt|ƒ}YnX|S)zvProduces a file object from source. source can be either a file object, local filename or a string. r/)rGrr+r&Ú Exceptionr)r!rKrrrrrX°s z HTMLBinaryInputStream.openStreamc Cs |jƒdf}|ddk r|St|jƒdf}|ddk r:|St|jƒdf}|ddk rX|S|jƒdf}|ddk rt|St|jƒdf}|ddk r¤|djjdƒ r¤|St|jƒdf}|ddk rÂ|S|�rtyddl m }Wnt k rìYnˆXg}|ƒ}xF|j �s>|j j|jƒ}t|tƒ�s t‚|�s(P|j|ƒ|j|ƒqúW|jƒt|jdƒ}|j jdƒ|dk �rt|dfSt|jƒdf}|ddk �r”|StdƒdfS)NrPrÚ tentativezutf-16)ÚUniversalDetectorÚencodingz windows-1252)Ú detectBOMrVr—r˜ÚdetectEncodingMetar™ÚnameÚ startswithršÚ%pip._vendor.chardet.universaldetectorr¢Ú ImportErrorÚdoner”r/r–rBr.r(r1ÚfeedÚcloseÚresultr+r›)r!ÚchardetrWr¢ÚbuffersÚdetectorrr£rrrrœÃsR           z'HTMLBinaryInputStream.determineEncodingcCsž|jddkst‚t|ƒ}|dkr&dS|jdkrFtdƒ}|dk sšt‚nT||jdkrf|jddf|_n4|jjdƒ|df|_|jƒtd|jd|fƒ‚dS) Nr rPúutf-16beúutf-16lezutf-8rzEncoding changed from %s to %s)r±r²)rWr(rVr¦r”r+rZr)r!Ú newEncodingrrrÚchangeEncodings   z$HTMLBinaryInputStream.changeEncodingc Csªtjdtjdtjdtjdtjdi}|jjdƒ}t|t ƒsr"rZrXrœr´r¤r¥rrrrrJzs ( >"rJc@sŽeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z e e e ƒZ dd„Ze eƒZefdd„Zdd„Zdd„Zdd„ZdS)Ú EncodingBytesz£String-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|tƒst‚tj||jƒƒS)N)rBr.r(Ú__new__Úlower)r!ÚvaluerrrrÆFszEncodingBytes.__new__cCs d|_dS)Nr r)ri)r!rÈrrrr"JszEncodingBytes.__init__cCs|S)Nr)r!rrrÚ__iter__NszEncodingBytes.__iter__cCs>|jd}|_|t|ƒkr"t‚n |dkr.t‚|||d…S)Nr r)rir#Ú StopIterationrH)r!ÚprrrÚ__next__Qs  zEncodingBytes.__next__cCs|jƒS)N)rÌ)r!rrrÚnextYszEncodingBytes.nextcCsB|j}|t|ƒkrt‚n |dkr$t‚|d|_}|||d…S)Nrr )rir#rÊrH)r!rËrrrÚprevious]s zEncodingBytes.previouscCs|jt|ƒkrt‚||_dS)N)rir#rÊ)r!r rrrÚ setPositionfszEncodingBytes.setPositioncCs*|jt|ƒkrt‚|jdkr"|jSdSdS)Nr)rir#rÊ)r!rrrÚ getPositionks  zEncodingBytes.getPositioncCs||j|jd…S)Nr )r )r!rrrÚgetCurrentByteuszEncodingBytes.getCurrentBytecCsL|j}x:|t|ƒkr@|||d…}||kr6||_|S|d7}qW||_dS)zSkip past a list of charactersr N)r r#ri)r!rŒrËr„rrrrzs zEncodingBytes.skipcCsL|j}x:|t|ƒkr@|||d…}||kr6||_|S|d7}qW||_dS)Nr )r r#ri)r!rŒrËr„rrrÚ skipUntil†s zEncodingBytes.skipUntilcCs(|j||jƒ}|r$|jt|ƒ7_|S)zÓLook 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)r§r r#)r!r.r6rrrÚ matchBytes‘szEncodingBytes.matchBytesc Cs>y |j||jƒt|ƒd|_Wntk r8t‚YnXdS)z�Look 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#riÚ ValueErrorrÊ)r!r.rrrÚjumpTošs   zEncodingBytes.jumpToN)r;r<r=r>rÆr"rÉrÌrÍrÎrÏrÐÚpropertyr rÑÚ currentByteÚspaceCharactersBytesrrÒrÓrÖrrrrrÅBs      rÅc@sXeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dS)rÂz?Mini parser for detecting character encoding from meta elementscCst|ƒ|_d|_dS)z3string - the data to work on for encoding detectionN)rÅr2r£)r!r2rrrr"§s zEncodingParser.__init__cCsÐd|jkrdSd|jfd|jfd|jfd|jfd|jfd|jff}x†|jD]|}d}y|jjdƒWntk rxPYnXxD|D]<\}}|jj|ƒr€y |ƒ}PWq€tk rºd}PYq€Xq€W|sJPqJW|j S) Ns)r2rÖ)r!rrrrÚÊszEncodingParser.handleCommentcCsä|jjtkrdSd}d}xÆ|jƒ}|dkr.dS|ddkr^|ddk}|rÜ|dk rÜ||_dSq|ddkrŽ|d}t|ƒ}|dk rÜ||_dSq|ddkrtt|dƒƒ}|jƒ}|dk rt|ƒ}|dk r|rØ||_dS|}qWdS) NTFrs http-equivr s content-typescharsetscontent) r2rØrÙÚ getAttributer£rVÚContentAttrParserrÅÚparse)r!Ú hasPragmaÚpendingEncodingÚattrÚtentativeEncodingÚcodecÚ contentParserrrrrÛÎs:      zEncodingParser.handleMetacCs |jdƒS)NF)ÚhandlePossibleTag)r!rrrrÞòsz%EncodingParser.handlePossibleStartTagcCst|jƒ|jdƒS)NT)rÍr2rì)r!rrrrÜõs z#EncodingParser.handlePossibleEndTagcCsf|j}|jtkr(|r$|jƒ|jƒdS|jtƒ}|dkrD|jƒn|jƒ}x|dk r`|jƒ}qNWdS)NTr)r2rØÚasciiLettersBytesrÎrÝrÒÚspacesAngleBracketsrã)r!ÚendTagr2r„rèrrrrìùs     z EncodingParser.handlePossibleTagcCs |jjdƒS)Nr)r2rÖ)r!rrrrÝszEncodingParser.handleOthercCs|j}|jttdgƒBƒ}|dks2t|ƒdks2t‚|d kr>dSg}g}xt|dkrX|rXPnX|tkrl|jƒ}PnD|d kr‚dj|ƒdfS|tkrš|j|j ƒƒn|dkr¦dS|j|ƒt |ƒ}qHW|dkrÚ|j ƒdj|ƒdfSt |ƒ|jƒ}|d k�rT|}x¤t |ƒ}||k�r(t |ƒdj|ƒdj|ƒfS|tk�rB|j|j ƒƒn |j|ƒ�qúWnJ|dk�rldj|ƒdfS|tk�r†|j|j ƒƒn|dk�r”dS|j|ƒx^t |ƒ}|t k�rÆdj|ƒdj|ƒfS|tk�rà|j|j ƒƒn|dk�rîdS|j|ƒ�q WdS) z_Return a name,value pair for the next attribute in the stream, if one is found, or Noneó/Nr ró=r3ó'ó")rN)rðr)ròró) r2rrÙÚ frozensetr#r(r4ÚasciiUppercaseBytesr1rÇrÍrÎrî)r!r2r„ÚattrNameÚ attrValueÚ quoteCharrrrrãsh             zEncodingParser.getAttributeN) r;r<r=r>r"rÃrÚrÛrÞrÜrìrÝrãrrrrr¤s$rÂc@seZdZdd„Zdd„ZdS)räcCst|tƒst‚||_dS)N)rBr.r(r2)r!r2rrrr"aszContentAttrParser.__init__cCsyê|jjdƒ|jjd7_|jjƒ|jjdks8dS|jjd7_|jjƒ|jjdkr¢|jj}|jjd7_|jj}|jj|ƒrœ|j||jj…SdSnF|jj}y|jjtƒ|j||jj…Stk ræ|j|d…SXWntk �rdSXdS)Nscharsetr rñrórò)rórò)r2rÖr rrØrÒrÙrÊ)r!Ú quoteMarkÚ oldPositionrrrråes.       zContentAttrParser.parseN)r;r<r=r"rårrrrrä`sräcCs`t|tƒr.y|jdƒ}Wntk r,dSX|dk rXy tj|ƒStk rTdSXndSdS)z{Return the python codec name corresponding to an encoding or None if the string doesn't correspond to a valid encoding.rN)rBr.ÚdecodeÚUnicodeDecodeErrorr ÚlookupÚAttributeError)r£rrrrV‡s  rVrr)1Ú __future__rrrZpip._vendor.sixrÚpip._vendor.six.movesrrr·r‡Úiorr Ú pip._vendorr Ú constantsr r rrrr[rrôrÙrírõrîÚinvalid_unicode_no_surrogaterQrcr(rˆÚevalrur~Úascii_punctuation_rer…ÚobjectrrOrIrJr.rÅrÂrärVrrrrÚsP             JgIb='