• File: _inputstream.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/html5lib/__pycache__/_inputstream.cpython-37.pyc
  • Date Modified: 07/08/2021 11:01 AM
  • File size: 22.02 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

63)Z~!@sddlmZmZmZddlmZmZddlmZm	Z	ddl
Z
ddlZddlZddl
mZmZmZmZddl
mZddlmZdd	lmZydd
lmZWnek
reZYnXeddeDZed
deDZeddeDZeeddgBZdZejrFeddkr"e ddks&t!e"edde#ddZ$n
e"eZ$e%dddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4g Z&e"d5Z'iZ(Gd6d7d7e)Z*d8d9Z+Gd:d;d;e)Z,Gd<d=d=e,Z-Gd>d?d?e.Z/Gd@dAdAe)Z0GdBdCdCe)Z1dDdEZ2dS)F)absolute_importdivisionunicode_literals)	text_typebinary_type)http_clienturllibN)EOFspaceCharactersasciiLettersasciiUppercase)_ReparseException)_utils)StringIO)BytesIOcCsg|]}|dqS)ascii)encode).0itemrF/opt/alt/python37/lib/python3.7/site-packages/html5lib/_inputstream.py
<listcomp>srcCsg|]}|dqS)r)r)rrrrrrscCsg|]}|dqS)r)r)rrrrrrs><u[---Ÿ﷐-﷯￾￿🿾🿿𯿾𯿿𿿾𿿿񏿾񏿿񟿾񟿿񯿾񯿿񿿾񿿿򏿾򏿿򟿾򟿿򯿾򯿿򿿾򿿿󏿾󏿿󟿾󟿿󯿾󯿿󿿾󿿿􏿾􏿿]]z"\uD800-\uDFFF"iiiiiiiiiiiiiiiii	i	i
i
iiiii
i
iiiiiiz[	-
 -/:-@\[-`{-~]c@sHeZdZdZddZddZddZdd	Zd
dZd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)Nrr)streambufferposition)selfrrrr__init__@szBufferedStream.__init__cCs@d}x(|jd|jdD]}|t|7}qW||jd7}|S)Nrr	)rr len)r!poschunkrrrtellEs
zBufferedStream.tellcCsX||kst|}d}x0t|j||krH|t|j|8}|d7}qW||g|_dS)Nrr	)_bufferedBytesAssertionErrorr#rr )r!r$offsetirrrseekLszBufferedStream.seekcCsT|js||S|jdt|jkrF|jdt|jdkrF||S||SdS)Nrr	r)r_readStreamr r#_readFromBuffer)r!bytesrrrreadUs

zBufferedStream.readcCstdd|jDS)NcSsg|]}t|qSr)r#)rrrrrr_sz1BufferedStream._bufferedBytes.<locals>.<listcomp>)sumr)r!rrrr'^szBufferedStream._bufferedBytescCs<|j|}|j||jdd7<t||jd<|S)Nrr	)rr/rappendr r#)r!r.datarrrr,as
zBufferedStream._readStreamcCs|}g}|jd}|jd}x|t|jkr|dkr|dks@t|j|}|t||krn|}|||g|_n"t||}|t|g|_|d7}|||||||8}d}qW|r|||d|S)Nrr	)r r#rr(r1r,join)r!r.ZremainingBytesrvZbufferIndexZbufferOffsetZbufferedDataZbytesToReadrrrr-hs&


zBufferedStream._readFromBufferN)__name__
__module____qualname____doc__r"r&r+r/r'r,r-rrrrr9s		rcKst|tjs(t|tjjr.t|jtjr.d}n&t|drJt|dt	}n
t|t	}|rdd|D}|rvt
d|t|f|St|f|SdS)NFr/rcSsg|]}|dr|qS)Z	_encoding)endswith)rxrrrrsz#HTMLInputStream.<locals>.<listcomp>z3Cannot set an encoding with a unicode input, set %r)
isinstancerZHTTPResponserZresponseZaddbasefphasattrr/r	TypeErrorHTMLUnicodeInputStreamHTMLBinaryInputStream)sourcekwargsZ	isUnicodeZ	encodingsrrrHTMLInputStreams

rDc@speZdZdZdZddZddZddZd	d
ZddZ	d
dZ
dddZddZddZ
dddZddZdS)r@zProvides 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)aInitialises 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-8certain)rsupports_lone_surrogatesreportCharacterErrorsr#characterErrorsUCS4characterErrorsUCS2ZnewLineslookupEncodingcharEncoding
openStream
dataStreamreset)r!rBrrrr"s
zHTMLUnicodeInputStream.__init__cCs.d|_d|_d|_g|_d|_d|_d|_dS)Nr)r%	chunkSizechunkOffseterrorsprevNumLinesprevNumCols_bufferedCharacter)r!rrrrNszHTMLUnicodeInputStream.resetcCst|dr|}nt|}|S)zvProduces a file object from source.

        source can be either a file object, local filename or a string.

        r/)r>r)r!rBrrrrrLs
z!HTMLUnicodeInputStream.openStreamcCsT|j}|dd|}|j|}|dd|}|dkr@|j|}n||d}||fS)N
rrr	)r%countrSrfindrT)r!r)r%ZnLinesZpositionLineZlastLinePosZpositionColumnrrr	_positions
z HTMLUnicodeInputStream._positioncCs||j\}}|d|fS)z:Returns (line, col) of the current position in the stream.r	)rYrQ)r!linecolrrrr szHTMLUnicodeInputStream.positioncCs6|j|jkr|stS|j}|j|}|d|_|S)zo Read one character from the stream or queue if available. Return
            EOF when EOF is reached.
        r	)rQrP	readChunkr
r%)r!rQcharrrrr]s

zHTMLUnicodeInputStream.charNcCs|dkr|j}||j\|_|_d|_d|_d|_|j|}|j	rX|j	|}d|_	n|s`dSt
|dkrt|d}|dksd|krdkrnn|d|_	|dd}|jr|||
d	d
}|
dd
}||_t
||_dS)
NrOrFr	r
iiz
rV
T)_defaultChunkSizerYrPrSrTr%rQrMr/rUr#ordrGreplace)r!rPr2Zlastvrrrr\s0
 


z HTMLUnicodeInputStream.readChunkcCs,x&ttt|D]}|jdqWdS)Nzinvalid-codepoint)ranger#invalid_unicode_refindallrRr1)r!r2_rrrrH%sz*HTMLUnicodeInputStream.characterErrorsUCS4cCsd}xt|D]}|rqt|}|}t|||drtt|||d}|tkrn|j	
dd}q|dkr|dkr|t|dkr|j	
dqd}|j	
dqWdS)NFzinvalid-codepointTiir	)rdfinditerragroupstartrZisSurrogatePairZsurrogatePairToCodepointnon_bmp_invalid_codepointsrRr1r#)r!r2skipmatchZ	codepointr$Zchar_valrrrrI)s z*HTMLUnicodeInputStream.characterErrorsUCS2Fc
Csyt||f}Wnltk
r|x|D]}t|dks&tq&Wddd|D}|s^d|}td|}t||f<YnXg}x|||j|j	}|dkr|j	|j
krPn0|}||j
kr||j|j	|||_	P||j|j	d|
sPqWd|}	|	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.
        rOcSsg|]}dt|qS)z\x%02x)ra)rcrrrrNsz5HTMLUnicodeInputStream.charsUntil.<locals>.<listcomp>z^%sz[%s]+N)charsUntilRegExKeyErrorrar(r4recompilermr%rQrPendr1r\)
r!Z
charactersZoppositecharsroZregexr5mrtrrrr
charsUntil@s2
 

z!HTMLUnicodeInputStream.charsUntilcCsT|dk	rP|jdkr.||j|_|jd7_n"|jd8_|j|j|ksPtdS)Nrr	)rQr%rPr()r!r]rrrungetos
zHTMLUnicodeInputStream.unget)N)F)r6r7r8r9r`r"rNrLrYr r]r\rHrIrxryrrrrr@s 
&
/r@c@sLeZdZdZdddZddZd	d
ZdddZd
dZddZ	ddZ
dS)rAzProvides 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|||_t||jd|_d|_||_||_||_||_	||_
|||_|jddk	sbt
|dS)aInitialises 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)

        idrN)rL	rawStreamr@r"numBytesMetanumBytesChardetoverride_encodingtransport_encodingsame_origin_parent_encodinglikely_encodingdefault_encodingdetermineEncodingrKr(rN)r!rBrrrrrZ
useChardetrrrr"szHTMLBinaryInputStream.__init__cCs&|jdj|jd|_t|dS)Nrrb)rKZ
codec_infostreamreaderr|rMr@rN)r!rrrrNszHTMLBinaryInputStream.resetcCsDt|dr|}nt|}y||Wnt|}YnX|S)zvProduces a file object from source.

        source can be either a file object, local filename or a string.

        r/)r>rr+r&r)r!rBrrrrrLs
z HTMLBinaryInputStream.openStreamcCs|df}|ddk	r|St|jdf}|ddk	r:|St|jdf}|ddk	rX|S|df}|ddk	rt|St|jdf}|ddk	r|djds|St|jdf}|ddk	r|S|rryddl	m
}Wntk
rYnXg}|}xF|js<|j
|j}t|tst|s&P||||qW|t|jd}|j
d|dk	rr|dfSt|jdf}|ddk	r|StddfS)NrErZ	tentativezutf-16)UniversalDetectorencodingzwindows-1252)	detectBOMrJrrdetectEncodingMetarname
startswithrZchardet.universaldetectorrImportErrorZdoner|r/r~r<r.r(r1Zfeedcloseresultr+r)r!ZchardetrKrZbuffersZdetectorrrrrrrsR


z'HTMLBinaryInputStream.determineEncodingcCs|jddkstt|}|dkr&dS|jdkrFtd}|dk	stnT||jdkrf|jddf|_n4|jd|df|_|td|jd|fdS)Nr	rE)zutf-16bezutf-16lezutf-8rzEncoding changed from %s to %s)rKr(rJrr|r+rNr)r!ZnewEncodingrrrchangeEncodings

z$HTMLBinaryInputStream.changeEncodingc
Cstjdtjdtjdtjdtjdi}|jd}t|t	s<t
||dd}d}|s~||}d}|s~||dd	}d	}|r|j|t
|S|jd
dSdS)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 Nonezutf-8zutf-16lezutf-16bezutf-32lezutf-32beNrgr)codecsBOM_UTF8BOM_UTF16_LEBOM_UTF16_BEBOM_UTF32_LEBOM_UTF32_BEr|r/r<r.r(getr+rJ)r!ZbomDictstringrr+rrrrs$
zHTMLBinaryInputStream.detectBOMcCsV|j|j}t|tstt|}|jd|}|dk	rR|j	dkrRt
d}|S)z9Report the encoding declared by the meta element
        rN)zutf-16bezutf-16lezutf-8)r|r/r}r<r.r(EncodingParserr+getEncodingrrJ)r!rparserrrrrr9sz(HTMLBinaryInputStream.detectEncodingMeta)NNNNrzT)T)r6r7r8r9r"rNrLrrrrrrrrrAs
(
>"rAc@seZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZeee
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|tstt||S)N)r<r.r(__new__lower)r!valuerrrrLszEncodingBytes.__new__cCs
d|_dS)Nr)rY)r!rrrrr"PszEncodingBytes.__init__cCs|S)Nr)r!rrr__iter__TszEncodingBytes.__iter__cCs>|jd}|_|t|kr"tn|dkr.t|||dS)Nr	r)rYr#
StopIterationr?)r!prrr__next__WszEncodingBytes.__next__cCs|S)N)r)r!rrrnext_szEncodingBytes.nextcCsB|j}|t|krtn|dkr$t|d|_}|||dS)Nrr	)rYr#rr?)r!rrrrpreviouscszEncodingBytes.previouscCs|jt|krt||_dS)N)rYr#r)r!r rrrsetPositionlszEncodingBytes.setPositioncCs*|jt|krt|jdkr"|jSdSdS)Nr)rYr#r)r!rrrgetPositionqs

zEncodingBytes.getPositioncCs||j|jdS)Nr	)r )r!rrrgetCurrentByte{szEncodingBytes.getCurrentBytecCsL|j}x:|t|kr@|||d}||kr6||_|S|d7}qW||_dS)zSkip past a list of charactersr	N)r r#rY)r!rurrorrrrlszEncodingBytes.skipcCsL|j}x:|t|kr@|||d}||kr6||_|S|d7}qW||_dS)Nr	)r r#rY)r!rurrorrr	skipUntilszEncodingBytes.skipUntilcCs>|j}|||t|}||}|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)r r#r)r!r.rr2r5rrr
matchBytess
zEncodingBytes.matchBytescCsR||jd|}|dkrJ|jdkr,d|_|j|t|d7_dStdS)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 matchNrrr	T)r findrYr#r)r!r.ZnewPositionrrrjumpTos
zEncodingBytes.jumpToN)r6r7r8r9rr"rrrrrrpropertyr rcurrentBytespaceCharactersBytesrlrrrrrrrrHs 	
rc@sXeZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZddZdS)rz?Mini parser for detecting character encoding from meta elementscCst||_d|_dS)z3string - the data to work on for encoding detectionN)rr2r)r!r2rrrr"s
zEncodingParser.__init__c
Csd|jfd|jfd|jfd|jfd|jfd|jff}x^|jD]T}d}xD|D]<\}}|j|rJy|}PWqJtk
rd}PYqJXqJW|s<Pq<W|jS)	Ns<!--s<metas</s<!s<?rTF)	
handleComment
handleMetahandlePossibleEndTaghandleOtherhandlePossibleStartTagr2rrr)r!ZmethodDispatchrfZkeepParsingkeymethodrrrrs&zEncodingParser.getEncodingcCs|jdS)zSkip over commentss-->)r2r)r!rrrrszEncodingParser.handleCommentcCs|jjtkrdSd}d}x|}|dkr.dS|ddkr^|ddk}|r|dk	r||_dSq|ddkr|d}t|}|dk	r||_dSq|ddkrtt|d}|}|dk	rt|}|dk	r|r||_dS|}qWdS)	NTFrs
http-equivr	scontent-typescharsetscontent)	r2rrgetAttributerrJContentAttrParserrparse)r!Z	hasPragmaZpendingEncodingattrZtentativeEncodingcodecZ
contentParserrrrrs:zEncodingParser.handleMetacCs
|dS)NF)handlePossibleTag)r!rrrrsz%EncodingParser.handlePossibleStartTagcCst|j|dS)NT)rr2r)r!rrrrs
z#EncodingParser.handlePossibleEndTagcCsf|j}|jtkr(|r$||dS|t}|dkrD|n|}x|dk	r`|}qNWdS)NTr)r2rasciiLettersBytesrrrspacesAngleBracketsr)r!ZendTagr2rorrrrrs



z EncodingParser.handlePossibleTagcCs|jdS)Nr)r2r)r!rrrrszEncodingParser.handleOthercCs|j}|ttdgB}|dks2t|dks2t|dkr>dSg}g}xt|dkrX|rXPnX|tkrl|}PnD|dkrd|dfS|tkr||	n|dkrdS||t
|}qHW|dkr|d|dfSt
||}|dkrR|}xt
|}||kr(t
|d|d|fS|tkrB||	q||qWnJ|d	krjd|dfS|tkr||	n|dkrdS||x^t
|}|tkrd|d|fS|tkr||	n|dkrdS||qWdS)
z_Return a name,value pair for the next attribute in the stream,
        if one is found, or None/Nr	)rN=)rrr3)'"r)
r2rlr	frozensetr#r(r4asciiUppercaseBytesr1rrrr)r!r2roZattrNameZ	attrValueZ	quoteCharrrrrsh










zEncodingParser.getAttributeN)
r6r7r8r9r"rrrrrrrrrrrrrs$rc@seZdZddZddZdS)rcCst|tst||_dS)N)r<r.r(r2)r!r2rrrr"fszContentAttrParser.__init__cCsy|jd|jjd7_|j|jjdks8dS|jjd7_|j|jjdkr|jj}|jjd7_|jj}|j|r|j||jjSdSnF|jj}y|jt|j||jjStk
r|j|dSXWntk
rdSXdS)Nscharsetr	r)rr)r2rr rlrrrr)r!Z	quoteMarkZoldPositionrrrrjs.

zContentAttrParser.parseN)r6r7r8r"rrrrrresrcCs`t|tr.y|d}Wntk
r,dSX|dk	rXy
t|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)r<rdecodeUnicodeDecodeErrorwebencodingslookupAttributeError)rrrrrJs

rJ)3Z
__future__rrrZsixrrZ	six.movesrrrrrrZ	constantsr
rrr
rrOriorrrrrrrrZinvalid_unicode_no_surrogaterFrWr(rsevalrdsetrkZascii_punctuation_rerpobjectrrDr@rAr.rrrrJrrrr<module>sX
"








JgIh6'