• File: _inputstream.cpython-37.opt-1.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/html5lib/__pycache__/_inputstream.cpython-37.opt-1.pyc
  • Date Modified: 07/08/2021 11:01 AM
  • File size: 21.58 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eDZeeddgBZdZejr$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'Z.GdBdCdCe'Z/dDdEZ0dS)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.tellcCsH|}d}x0t|j||kr8|t|j|8}|d7}q
W||g|_dS)Nrr	)r#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!rrr_bufferedBytes^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|j|}|t||krb|}|||g|_n"t||}|t|g|_|d7}|||||||8}d}qW|r|||d|S)Nrr	)r r#rr0r*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

rCc@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!rArrrr"s
zHTMLUnicodeInputStream.__init__cCs.d|_d|_d|_g|_d|_d|_d|_dS)Nr)r%	chunkSizechunkOffseterrorsprevNumLinesprevNumCols_bufferedCharacter)r!rrrrMszHTMLUnicodeInputStream.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!rArrrrrKs
z!HTMLUnicodeInputStream.openStreamcCsT|j}|dd|}|j|}|dd|}|dkr@|j|}n||d}||fS)N
rrr	)r%countrRrfindrS)r!r'r%ZnLinesZpositionLineZlastLinePosZpositionColumnrrr	_positions
z HTMLUnicodeInputStream._positioncCs||j\}}|d|fS)z:Returns (line, col) of the current position in the stream.r	)rXrP)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	)rPrO	readChunkr
r%)r!rPcharrrrr\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)
NrNrFr	r
iiz
rU
T)_defaultChunkSizerXrOrRrSr%rPrLr-rTr#ordrFreplace)r!rOr1Zlastvrrrr[s0
 


z HTMLUnicodeInputStream.readChunkcCs,x&ttt|D]}|jdqWdS)Nzinvalid-codepoint)ranger#invalid_unicode_refindallrQr0)r!r1_rrrrG%sz*HTMLUnicodeInputStream.characterErrorsUCS4cCsd}xt|D]}|rqt|}|}t|||drtt|||d}|tkrn|j	
dd}q|dkr|dkr|t|dkr|j	
dqd}|j	
dqWdS)NFzinvalid-codepointTiir	)rcfinditerr`groupstartrZisSurrogatePairZsurrogatePairToCodepointnon_bmp_invalid_codepointsrQr0r#)r!r1skipmatchZ	codepointr$Zchar_valrrrrH)s z*HTMLUnicodeInputStream.characterErrorsUCS2Fc	Csyt||f}WnNtk
r^ddd|D}|s@d|}td|}t||f<YnXg}x|||j|j}|dkr|j|jkrPn0|	}||jkr|
|j|j|||_P|
|j|jd|sfPqfWd|}|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.
        rNcSsg|]}dt|qS)z\x%02x)r`)rcrrrrNsz5HTMLUnicodeInputStream.charsUntil.<locals>.<listcomp>z^%sz[%s]+N)charsUntilRegExKeyErrorr3recompilerlr%rPrOendr0r[)	r!Z
charactersZoppositecharsZregexr4mrrrrrr
charsUntil@s. 

z!HTMLUnicodeInputStream.charsUntilcCs@|dk	r<|jdkr.||j|_|jd7_n|jd8_dS)Nrr	)rPr%rO)r!r\rrrungetos
zHTMLUnicodeInputStream.unget)N)F)r5r6r7r8r_r"rMrKrXr r\r[rGrHrvrwrrrrr?s 
&
/r?c@sLeZdZdZdddZddZd	d
ZdddZd
dZddZ	ddZ
dS)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.

    Nwindows-1252TcCs\|||_t||jd|_d|_||_||_||_||_	||_
|||_|
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)

        idN)rK	rawStreamr?r"numBytesMetanumBytesChardetoverride_encodingtransport_encodingsame_origin_parent_encodinglikely_encodingdefault_encodingdetermineEncodingrJrM)r!rAr}r~rrrZ
useChardetrrrr"szHTMLBinaryInputStream.__init__cCs&|jdj|jd|_t|dS)Nrra)rJZ
codec_infostreamreaderrzrLr?rM)r!rrrrMszHTMLBinaryInputStream.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!rArrrrrKs
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|rbyddl	m
}Wntk
rYnxXg}|}x6|js,|j
|j}|sP||||qW|t|jd}|j
d|dk	rb|dfSt|jdf}|ddk	r|StddfS)NrDrZ	tentativezutf-16)UniversalDetectorencodingzwindows-1252)	detectBOMrIr}r~detectEncodingMetarname
startswithrZchardet.universaldetectorrImportErrorZdonerzr-r|r0Zfeedcloseresultr)r)r!ZchardetrJrZbuffersZdetectorrrrrrrsP


z'HTMLBinaryInputStream.determineEncodingcCst|}|dkrdS|jdkr(td}nT||jdkrH|jddf|_n4|jd|df|_|td|jd|fdS)N)zutf-16bezutf-16lezutf-8rrDzEncoding changed from %s to %s)rIrrJrzr)rMr)r!ZnewEncodingrrrchangeEncodings

z$HTMLBinaryInputStream.changeEncodingc
Cstjdtjdtjdtjdtjdi}|jd}||dd}d}|sp||}d}|sp||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-32beNrfr)codecsBOM_UTF8BOM_UTF16_LEBOM_UTF16_BEBOM_UTF32_LEBOM_UTF32_BErzr-getr)rI)r!ZbomDictstringrr)rrrrs"
zHTMLBinaryInputStream.detectBOMcCsH|j|j}t|}|jd|}|dk	rD|jdkrDtd}|S)z9Report the encoding declared by the meta element
        rN)zutf-16bezutf-16lezutf-8)rzr-r{EncodingParserr)getEncodingrrI)r!rparserrrrrr9sz(HTMLBinaryInputStream.detectEncodingMeta)NNNNrxT)T)r5r6r7r8r"rMrKrrrrrrrrr@s
(
>"r@c@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||S)N)r,__new__lower)r!valuerrrrLszEncodingBytes.__new__cCs
d|_dS)Nr)rX)r!rrrrr"PszEncodingBytes.__init__cCs|S)Nr)r!rrr__iter__TszEncodingBytes.__iter__cCs>|jd}|_|t|kr"tn|dkr.t|||dS)Nr	r)rXr#
StopIterationr>)r!prrr__next__WszEncodingBytes.__next__cCs|S)N)r)r!rrrnext_szEncodingBytes.nextcCsB|j}|t|krtn|dkr$t|d|_}|||dS)Nrr	)rXr#rr>)r!rrrrpreviouscszEncodingBytes.previouscCs|jt|krt||_dS)N)rXr#r)r!r rrrsetPositionlszEncodingBytes.setPositioncCs*|jt|krt|jdkr"|jSdSdS)Nr)rXr#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#rX)r!rsrrmrrrrkszEncodingBytes.skipcCsL|j}x:|t|kr@|||d}||kr6||_|S|d7}qW||_dS)Nr	)r r#rX)r!rsrrmrrr	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,rr1r4rrr
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 findrXr#r)r!r,ZnewPositionrrrjumpTos
zEncodingBytes.jumpToN)r5r6r7r8rr"rrrrrrpropertyr rcurrentBytespaceCharactersBytesrkrrrrrrrrHs 	
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)rr1r)r!r1rrrr"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
handleMetahandlePossibleEndTaghandleOtherhandlePossibleStartTagr1rrr)r!ZmethodDispatchreZkeepParsingkeymethodrrrrs&zEncodingParser.getEncodingcCs|jdS)zSkip over commentss-->)r1r)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)	r1rrgetAttributerrIContentAttrParserrparse)r!Z	hasPragmaZpendingEncodingattrZtentativeEncodingcodecZ
contentParserrrrrs:zEncodingParser.handleMetacCs
|dS)NF)handlePossibleTag)r!rrrrsz%EncodingParser.handlePossibleStartTagcCst|j|dS)NT)rr1r)r!rrrrs
z#EncodingParser.handlePossibleEndTagcCsf|j}|jtkr(|r$||dS|t}|dkrD|n|}x|dk	r`|}qNWdS)NTr)r1rasciiLettersBytesrrrspacesAngleBracketsr)r!ZendTagr1rmrrrrrs



z EncodingParser.handlePossibleTagcCs|jdS)Nr)r1r)r!rrrrszEncodingParser.handleOthercCs|j}|ttdgB}|dkr&dSg}g}xt|dkr@|r@PnX|tkrT|}PnD|dkrjd|dfS|tkr||n|dkrdS||t|}q0W|dkr|	d|dfSt||}|dkr:|}xt|}||krt|d|d|fS|tkr*||q||qWnJ|dkrRd|dfS|tkrl||n|dkrzdS||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/)rNN=)rrr2)'"r)r1rkr	frozensetr3asciiUppercaseBytesr0rrrr)r!r1rmZattrNameZ	attrValueZ	quoteCharrrrrsf










zEncodingParser.getAttributeN)
r5r6r7r8r"rrrrrrrrrrrrrs$rc@seZdZddZddZdS)rcCs
||_dS)N)r1)r!r1rrrr"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)r1rr rkrrrr)r!Z	quoteMarkZoldPositionrrrrjs.

zContentAttrParser.parseN)r5r6r7r"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)rrrrrIs

rI)1Z
__future__rrrZsixrrZ	six.movesrrrrprZ	constantsr
rrr
rrNriorrrrrrrrZinvalid_unicode_no_surrogaterErqevalrcsetrjZascii_punctuation_rernobjectrrCr?r@r,rrrrIrrrr<module>sV









JgIh6'