B
    @)H[Ã‚  ã            !   @   s  d dl mZmZmZ d dlmZmZ d dlmZm	Z	 d dl
Z
d dlZd dlmZ ddlmZmZmZmZ ddlmZ dd	lmZ d d
lmZ yd dlmZ W n ek
r´   eZY nX edd„ eD ƒƒZedd„ eD ƒƒZedd„ eD ƒƒZeeddgƒB ZdZej �rJed dk�r&e !d¡dk�s*t"‚e #edd… e$dƒ d ¡Z%n
e #e¡Z%e&ddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5g ƒZ'e #d6¡Z(i Z)G d7d8„ d8e*ƒZ+d9d:„ Z,G d;d<„ d<e*ƒZ-G d=d>„ d>e-ƒZ.G d?d@„ d@e/ƒZ0G dAdB„ dBe*ƒZ1G dCdD„ dDe*ƒZ2dEdF„ Z3dS )Gé    )Úabsolute_importÚdivisionÚunicode_literals)Ú	text_typeÚbinary_type)Úhttp_clientÚurllibN)Úwebencodingsé   )ÚEOFÚspaceCharactersÚasciiLettersÚasciiUppercase)Ú_ReparseException)Ú_utils)ÚStringIO)ÚBytesIOc             C   s   g | ]}|  d ¡‘qS )Úascii)Úencode)Ú.0Úitem© r   úbC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_vendor\html5lib\_inputstream.pyú
<listcomp>   s    r   c             C   s   g | ]}|  d ¡‘qS )r   )r   )r   r   r   r   r   r      s    c             C   s   g | ]}|  d ¡‘qS )r   )r   )r   r   r   r   r   r      s    ó   >ó   <uš   [---ÂŸï·�-ï·¯ï¿¾ï¿¿ðŸ¿¾ðŸ¿¿ð¯¿¾ð¯¿¿ð¿¿¾ð¿¿¿ñ�¿¾ñ�¿¿ñŸ¿¾ñŸ¿¿ñ¯¿¾ñ¯¿¿ñ¿¿¾ñ¿¿¿ò�¿¾ò�¿¿òŸ¿¾òŸ¿¿ò¯¿¾ò¯¿¿ò¿¿¾ò¿¿¿ó�¿¾ó�¿¿óŸ¿¾óŸ¿¿ó¯¿¾ó¯¿¿ó¿¿¾ó¿¿¿ô�¿¾ô�¿¿]éÿÿÿÿú]z"\uD800-\uDFFF"iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ iþÿ	 iÿÿ	 iþÿ
 iÿÿ
 iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ iþÿ iÿÿ z[	- -/:-@\[-`{-~]c               @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )ÚBufferedStreamzÆBuffering 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)
    c             C   s   || _ g | _ddg| _d S )Nr   r   )ÚstreamÚbufferÚposition)Úselfr   r   r   r   Ú__init__@   s    zBufferedStream.__init__c             C   s@   d}x(| j d | jd … D ]}|t|ƒ7 }qW || jd 7 }|S )Nr   r
   )r    r!   Úlen)r"   ÚposÚchunkr   r   r   ÚtellE   s
    zBufferedStream.tellc             C   sX   ||   ¡ kst‚|}d}x0t| j| ƒ|k rH|t| j| ƒ8 }|d7 }qW ||g| _d S )Nr   r
   )Ú_bufferedBytesÚAssertionErrorr$   r    r!   )r"   r%   ÚoffsetÚir   r   r   ÚseekL   s    zBufferedStream.seekc             C   sT   | j s|  |¡S | jd t| j ƒkrF| jd t| j d ƒkrF|  |¡S |  |¡S d S )Nr   r
   r   )r    Ú_readStreamr!   r$   Ú_readFromBuffer)r"   Úbytesr   r   r   ÚreadU   s    

zBufferedStream.readc             C   s   t dd„ | jD ƒƒS )Nc             S   s   g | ]}t |ƒ‘qS r   )r$   )r   r   r   r   r   r   _   s    z1BufferedStream._bufferedBytes.<locals>.<listcomp>)Úsumr    )r"   r   r   r   r(   ^   s    zBufferedStream._bufferedBytesc             C   s<   | j  |¡}| j |¡ | jd  d7  < t|ƒ| jd< |S )Nr   r
   )r   r0   r    Úappendr!   r$   )r"   r/   Údatar   r   r   r-   a   s
    zBufferedStream._readStreamc             C   sÔ   |}g }| j d }| j d }x˜|t| jƒk r´|dkr´|dks@t‚| j| }|t|ƒ| krn|}||| g| _ n"t|ƒ| }|t|ƒg| _ |d7 }| |||| … ¡ ||8 }d}qW |rÊ| |  |¡¡ d |¡S )Nr   r
   ó    )r!   r$   r    r)   r2   r-   Újoin)r"   r/   ÚremainingBytesÚrvÚbufferIndexÚbufferOffsetÚbufferedDataÚbytesToReadr   r   r   r.   h   s&    


zBufferedStream._readFromBufferN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r'   r,   r0   r(   r-   r.   r   r   r   r   r   9   s   		r   c             K   s’   t | tjƒs(t | tjjƒr.t | jtjƒr.d}n&t| dƒrJt |  d¡t	ƒ}n
t | t	ƒ}|r‚dd„ |D ƒ}|rvt
d| ƒ‚t| f|ŽS t| f|ŽS d S )NFr0   r   c             S   s   g | ]}|  d ¡r|‘qS )Ú	_encoding)Úendswith)r   Úxr   r   r   r   ‘   s    z#HTMLInputStream.<locals>.<listcomp>z3Cannot set an encoding with a unicode input, set %r)Ú
isinstancer   ÚHTTPResponser   ÚresponseÚaddbaseÚfpÚhasattrr0   r   Ú	TypeErrorÚHTMLUnicodeInputStreamÚHTMLBinaryInputStream)ÚsourceÚkwargsÚ	isUnicodeÚ	encodingsr   r   r   ÚHTMLInputStreamƒ   s    

rP   c               @   sp   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
ddd„Zdd„ Zdd„ Zddd„Zdd„ ZdS )rJ   z×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 (  c             C   sZ   t jsd| _ntdƒdkr$| j| _n| j| _dg| _tdƒdf| _|  	|¡| _
|  ¡  dS )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
   r   zutf-8Úcertain)r   Úsupports_lone_surrogatesÚreportCharacterErrorsr$   ÚcharacterErrorsUCS4ÚcharacterErrorsUCS2ÚnewLinesÚlookupEncodingÚcharEncodingÚ
openStreamÚ
dataStreamÚreset)r"   rL   r   r   r   r#   ¤   s    
zHTMLUnicodeInputStream.__init__c             C   s.   d| _ d| _d| _g | _d| _d| _d | _d S )NÚ r   )r&   Ú	chunkSizeÚchunkOffsetÚerrorsÚprevNumLinesÚprevNumColsÚ_bufferedCharacter)r"   r   r   r   r[   Ä   s    zHTMLUnicodeInputStream.resetc             C   s   t |dƒr|}nt|ƒ}|S )zvProduces a file object from source.

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

        r0   )rH   r   )r"   rL   r   r   r   r   rY   Ò   s    
z!HTMLUnicodeInputStream.openStreamc             C   sT   | j }| dd|¡}| j| }| dd|¡}|dkr@| j| }n||d  }||fS )NÚ
r   r   r
   )r&   Úcountr`   Úrfindra   )r"   r*   r&   ÚnLinesÚpositionLineÚlastLinePosÚpositionColumnr   r   r   Ú	_positionà   s    
z HTMLUnicodeInputStream._positionc             C   s   |   | j¡\}}|d |fS )z:Returns (line, col) of the current position in the stream.r
   )rj   r^   )r"   ÚlineÚcolr   r   r   r!   ë   s    zHTMLUnicodeInputStream.positionc             C   s6   | j | jkr|  ¡ stS | 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^   Úcharr   r   r   rn   ð   s    

zHTMLUnicodeInputStream.charNc             C   sê   |d kr| j }|  | j¡\| _| _d| _d| _d| _| j |¡}| j	rX| j	| }d | _	n|s`dS t
|ƒdkr®t|d ƒ}|dks˜d|  kr”dkr®n n|d | _	|d d… }| jr¾|  |¡ | d	d
¡}| dd
¡}|| _t
|ƒ| _dS )Nr\   r   Fr
   r   é   i Ø  iÿÛ  z
rc   úT)Ú_defaultChunkSizerj   r]   r`   ra   r&   r^   rZ   r0   rb   r$   ÚordrS   Úreplace)r"   r]   r3   Úlastvr   r   r   rm   ÿ   s0    
 


z HTMLUnicodeInputStream.readChunkc             C   s,   x&t tt |¡ƒƒD ]}| j d¡ qW d S )Nzinvalid-codepoint)Úranger$   Úinvalid_unicode_reÚfindallr_   r2   )r"   r3   Ú_r   r   r   rT   %  s    z*HTMLUnicodeInputStream.characterErrorsUCS4c             C   sº   d}x°t  |¡D ]¢}|rqt| ¡ ƒ}| ¡ }t |||d … ¡rtt |||d … ¡}|tkrn| j	 
d¡ d}q|dkr¢|dkr¢|t|ƒd kr¢| j	 
d¡ qd}| j	 
d¡ qW d S )NFé   zinvalid-codepointTi Ø  iÿß  r
   )rv   Úfinditerrr   ÚgroupÚstartr   ÚisSurrogatePairÚsurrogatePairToCodepointÚnon_bmp_invalid_codepointsr_   r2   r$   )r"   r3   ÚskipÚmatchÚ	codepointr%   Úchar_valr   r   r   rU   )  s     z*HTMLUnicodeInputStream.characterErrorsUCS2Fc       
      C   s  yt ||f }W nl tk
r|   x|D ]}t|ƒdk s&t‚q&W d dd„ |D ƒ¡}|s^d| }t d| ¡ }t ||f< Y nX g }x|| | j| j	¡}|dkr¬| j	| j
krÜP n0| ¡ }|| j
krÜ| | j| j	|… ¡ || _	P | | j| j	d… ¡ |  ¡ s„P q„W 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.
        é€   r\   c             S   s   g | ]}d t |ƒ ‘qS )z\x%02x)rr   )r   Úcr   r   r   r   N  s    z5HTMLUnicodeInputStream.charsUntil.<locals>.<listcomp>z^%sz[%s]+N)ÚcharsUntilRegExÚKeyErrorrr   r)   r5   ÚreÚcompiler�   r&   r^   r]   Úendr2   rm   )
r"   Ú
charactersÚoppositeÚcharsr…   Úregexr7   ÚmrŠ   Úrr   r   r   Ú
charsUntil@  s2    
 

z!HTMLUnicodeInputStream.charsUntilc             C   sT   |d k	rP| j dkr.|| j | _|  jd7  _n"|  j d8  _ | j| j  |ksPt‚d S )Nr   r
   )r^   r&   r]   r)   )r"   rn   r   r   r   Úungeto  s    
zHTMLUnicodeInputStream.unget)N)F)r<   r=   r>   r?   rq   r#   r[   rY   rj   r!   rn   rm   rT   rU   r‘   r’   r   r   r   r   rJ   š   s    
&
/rJ   c               @   sL   e Zd ZdZddd„Zdd„ Zd	d
„ Zddd„Zdd„ Zdd„ Z	dd„ Z
dS )rK   z×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-1252Tc             C   sn   |   |¡| _t | | j¡ d| _d| _|| _|| _|| _|| _	|| _
|  |¡| _| jd dk	sbt‚|  ¡  dS )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   éd   r   N)rY   Ú	rawStreamrJ   r#   ÚnumBytesMetaÚnumBytesChardetÚoverride_encodingÚtransport_encodingÚsame_origin_parent_encodingÚlikely_encodingÚdefault_encodingÚdetermineEncodingrX   r)   r[   )r"   rL   r˜   r™   rš   r›   rœ   Ú
useChardetr   r   r   r#   ˆ  s    zHTMLBinaryInputStream.__init__c             C   s&   | j d j | jd¡| _t | ¡ d S )Nr   rs   )rX   Ú
codec_infoÚstreamreaderr•   rZ   rJ   r[   )r"   r   r   r   r[   ²  s    zHTMLBinaryInputStream.resetc             C   sD   t |dƒr|}nt|ƒ}y| | ¡ ¡ W n   t|ƒ}Y nX |S )zvProduces a file object from source.

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

        r0   )rH   r   r,   r'   r   )r"   rL   r   r   r   r   rY   ¶  s    
z HTMLBinaryInputStream.openStreamc             C   sž  |   ¡ df}|d d k	r|S t| jƒdf}|d d k	r:|S t| jƒdf}|d d k	rX|S |  ¡ df}|d d k	rt|S t| jƒdf}|d d k	r¢|d j d¡s¢|S t| jƒdf}|d d k	rÀ|S |�rryddl	m
} W n tk
rê   Y nˆX g }|ƒ }xF|j�s<| j | j¡}t|tƒ�st‚|�s&P | |¡ | |¡ qøW | ¡  t|jd ƒ}| j d¡ |d k	�rr|dfS t| jƒdf}|d d k	�r’|S tdƒdfS )NrQ   r   Ú	tentativezutf-16)ÚUniversalDetectorÚencodingzwindows-1252)Ú	detectBOMrW   r˜   r™   ÚdetectEncodingMetarš   ÚnameÚ
startswithr›   Ú%pip._vendor.chardet.universaldetectorr¢   ÚImportErrorÚdoner•   r0   r—   rC   r/   r)   r2   ÚfeedÚcloseÚresultr,   rœ   )r"   ÚchardetrX   r¢   ÚbuffersÚdetectorr    r£   r   r   r   r�   É  sR    


z'HTMLBinaryInputStream.determineEncodingc             C   sž   | j d dkst‚t|ƒ}|d kr&d S |jdkrFtdƒ}|d k	sšt‚nT|| j d krf| j d df| _ n4| j d¡ |df| _ |  ¡  td| j d |f ƒ‚d S )Nr
   rQ   )zutf-16bezutf-16lezutf-8r   zEncoding changed from %s to %s)rX   r)   rW   r¦   r•   r,   r[   r   )r"   ÚnewEncodingr   r   r   ÚchangeEncoding  s    

z$HTMLBinaryInputStream.changeEncodingc          
   C   sª   t jdt jdt jdt jdt jdi}| j d¡}t|t	ƒs<t
‚| |dd… ¡}d}|s~| |¡}d}|s~| |dd	… ¡}d	}|r–| j |¡ t|ƒS | j d
¡ dS dS )z©Attempts 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 Nonezutf-8zutf-16lezutf-16bezutf-32lezutf-32beé   Né   ry   r   )ÚcodecsÚBOM_UTF8ÚBOM_UTF16_LEÚBOM_UTF16_BEÚBOM_UTF32_LEÚBOM_UTF32_BEr•   r0   rC   r/   r)   Úgetr,   rW   )r"   ÚbomDictÚstringr£   r,   r   r   r   r¤     s$    
zHTMLBinaryInputStream.detectBOMc             C   sV   | j  | j¡}t|tƒst‚t|ƒ}| j  d¡ | ¡ }|dk	rR|j	dkrRt
dƒ}|S )z9Report the encoding declared by the meta element
        r   N)zutf-16bezutf-16lezutf-8)r•   r0   r–   rC   r/   r)   ÚEncodingParserr,   ÚgetEncodingr¦   rW   )r"   r    Úparserr£   r   r   r   r¥   9  s    z(HTMLBinaryInputStream.detectEncodingMeta)NNNNr“   T)T)r<   r=   r>   r?   r#   r[   rY   r�   r²   r¤   r¥   r   r   r   r   rK   €  s     
(
>"rK   c               @   sŽ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zeee
ƒZdd„ ZeeƒZefdd„Zdd„ Zdd„ Zdd„ ZdS )Ú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
    raisedc             C   s   t |tƒst‚t | | ¡ ¡S )N)rC   r/   r)   Ú__new__Úlower)r"   Úvaluer   r   r   rÂ   L  s    zEncodingBytes.__new__c             C   s
   d| _ d S )Nr   )rj   )r"   rÄ   r   r   r   r#   P  s    zEncodingBytes.__init__c             C   s   | S )Nr   )r"   r   r   r   Ú__iter__T  s    zEncodingBytes.__iter__c             C   s>   | j d  }| _ |t| ƒkr"t‚n|dk r.t‚| ||d … S )Nr
   r   )rj   r$   ÚStopIterationrI   )r"   Úpr   r   r   Ú__next__W  s    zEncodingBytes.__next__c             C   s   |   ¡ S )N)rÈ   )r"   r   r   r   Únext_  s    zEncodingBytes.nextc             C   sB   | j }|t| ƒkrt‚n|dk r$t‚|d  | _ }| ||d … S )Nr   r
   )rj   r$   rÆ   rI   )r"   rÇ   r   r   r   Úpreviousc  s    zEncodingBytes.previousc             C   s   | j t| ƒkrt‚|| _ d S )N)rj   r$   rÆ   )r"   r!   r   r   r   ÚsetPositionl  s    zEncodingBytes.setPositionc             C   s*   | j t| ƒkrt‚| j dkr"| j S d S d S )Nr   )rj   r$   rÆ   )r"   r   r   r   ÚgetPositionq  s
    
zEncodingBytes.getPositionc             C   s   | | j | j d … S )Nr
   )r!   )r"   r   r   r   ÚgetCurrentByte{  s    zEncodingBytes.getCurrentBytec             C   sL   | j }x:|t| ƒk r@| ||d … }||kr6|| _|S |d7 }qW || _dS )zSkip past a list of charactersr
   N)r!   r$   rj   )r"   r�   rÇ   r…   r   r   r   r€   €  s    zEncodingBytes.skipc             C   sL   | j }x:|t| ƒk r@| ||d … }||kr6|| _|S |d7 }qW || _d S )Nr
   )r!   r$   rj   )r"   r�   rÇ   r…   r   r   r   Ú	skipUntilŒ  s    zEncodingBytes.skipUntilc             C   s>   | j }| ||t|ƒ … }| |¡}|r:|  j t|ƒ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/   rÇ   r3   r7   r   r   r   Ú
matchBytes—  s    
zEncodingBytes.matchBytesc             C   sR   | | j d…  |¡}|dkrJ| jdkr,d| _|  j|t|ƒ d 7  _dS t‚dS )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 matchNr   r   r
   T)r!   Úfindrj   r$   rÆ   )r"   r/   ÚnewPositionr   r   r   ÚjumpTo¢  s    
zEncodingBytes.jumpToN)r<   r=   r>   r?   rÂ   r#   rÅ   rÈ   rÉ   rÊ   rË   rÌ   Úpropertyr!   rÍ   ÚcurrentByteÚspaceCharactersBytesr€   rÎ   rÏ   rÒ   r   r   r   r   rÁ   H  s    	
rÁ   c               @   sX   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )r¾   z?Mini parser for detecting character encoding from meta elementsc             C   s   t |ƒ| _d| _dS )z3string - the data to work on for encoding detectionN)rÁ   r3   r£   )r"   r3   r   r   r   r#   ³  s    
zEncodingParser.__init__c          
   C   sš   d| j fd| jfd| jfd| jfd| jfd| jff}x^| jD ]T}d}xD|D ]<\}}| j |¡rJy|ƒ }P W qJ tk
r„   d}P Y qJX qJW |s<P q<W | jS )	Ns   <!--s   <metas   </s   <!s   <?r   TF)	ÚhandleCommentÚ
handleMetaÚhandlePossibleEndTagÚhandleOtherÚhandlePossibleStartTagr3   rÏ   rÆ   r£   )r"   ÚmethodDispatchrx   ÚkeepParsingÚkeyÚmethodr   r   r   r¿   ¸  s&    zEncodingParser.getEncodingc             C   s   | j  d¡S )zSkip over commentss   -->)r3   rÒ   )r"   r   r   r   rÖ   Ï  s    zEncodingParser.handleCommentc             C   sä   | j jtkrdS d}d }xÆ|  ¡ }|d kr.dS |d dkr^|d dk}|rÜ|d k	rÜ|| _dS q|d dkrŽ|d }t|ƒ}|d k	rÜ|| _dS q|d dkrtt|d ƒƒ}| ¡ }|d k	rt|ƒ}|d k	r|rØ|| _dS |}qW d S )	NTFr   s
   http-equivr
   s   content-types   charsets   content)	r3   rÔ   rÕ   ÚgetAttributer£   rW   ÚContentAttrParserrÁ   Úparse)r"   Ú	hasPragmaÚpendingEncodingÚattrÚtentativeEncodingÚcodecÚcontentParserr   r   r   r×   Ó  s:    zEncodingParser.handleMetac             C   s
   |   d¡S )NF)ÚhandlePossibleTag)r"   r   r   r   rÚ   ÷  s    z%EncodingParser.handlePossibleStartTagc             C   s   t | jƒ |  d¡S )NT)rÉ   r3   rè   )r"   r   r   r   rØ   ú  s    
z#EncodingParser.handlePossibleEndTagc             C   sf   | j }|jtkr(|r$| ¡  |  ¡  dS | t¡}|dkrD| ¡  n|  ¡ }x|d k	r`|  ¡ }qNW dS )NTr   )r3   rÔ   ÚasciiLettersBytesrÊ   rÙ   rÎ   ÚspacesAngleBracketsrß   )r"   ÚendTagr3   r…   rä   r   r   r   rè   þ  s    



z EncodingParser.handlePossibleTagc             C   s   | j  d¡S )Nr   )r3   rÒ   )r"   r   r   r   rÙ     s    zEncodingParser.handleOtherc             C   s   | j }| ttdgƒB ¡}|dks2t|ƒdks2t‚|dkr>dS g }g }xt|dkrX|rXP nX|tkrl| ¡ }P nD|dkr‚d |¡dfS |tkrš| | 	¡ ¡ n|dkr¦dS | |¡ t
|ƒ}qHW |dkrÚ| ¡  d |¡dfS t
|ƒ | ¡ }|dk�rR|}x¢t
|ƒ}||k�r(t
|ƒ d |¡d |¡fS |tk�rB| | 	¡ ¡ qú| |¡ qúW nJ|d	k�rjd |¡dfS |tk�r„| | 	¡ ¡ n|dk�r’dS | |¡ x^t
|ƒ}|tk�rÄd |¡d |¡fS |tk�rÞ| | 	¡ ¡ n|dk�rìdS | |¡ �qžW dS )
z_Return a name,value pair for the next attribute in the stream,
        if one is found, or Noneó   /Nr
   )r   Nó   =)rì   r   r4   )ó   'ó   "r   )r3   r€   rÕ   Ú	frozensetr$   r)   r5   ÚasciiUppercaseBytesr2   rÃ   rÉ   rÊ   rê   )r"   r3   r…   ÚattrNameÚ	attrValueÚ	quoteCharr   r   r   rß     sh    










zEncodingParser.getAttributeN)r<   r=   r>   r?   r#   r¿   rÖ   r×   rÚ   rØ   rè   rÙ   rß   r   r   r   r   r¾   °  s   $r¾   c               @   s   e Zd Zdd„ Zdd„ ZdS )rà   c             C   s   t |tƒst‚|| _d S )N)rC   r/   r)   r3   )r"   r3   r   r   r   r#   f  s    zContentAttrParser.__init__c             C   s  yê| j  d¡ | j  jd7  _| j  ¡  | j jdks8d S | j  jd7  _| j  ¡  | j jdkr¢| j j}| j  jd7  _| j j}| j  |¡rœ| j || j j… S d S nF| j j}y| j  t¡ | j || j j… S  tk
ræ   | j |d … S X W n tk
�r    d S X d S )Ns   charsetr
   rí   )rï   rî   )r3   rÒ   r!   r€   rÔ   rÎ   rÕ   rÆ   )r"   Ú	quoteMarkÚoldPositionr   r   r   rá   j  s.    

zContentAttrParser.parseN)r<   r=   r>   r#   rá   r   r   r   r   rà   e  s   rà   c             C   s`   t | tƒr.y|  d¡} W n tk
r,   dS X | dk	rXy
t | ¡S  tk
rT   dS X ndS dS )z{Return the python codec name corresponding to an encoding or None if the
    string doesn't correspond to a valid encoding.r   N)rC   r   ÚdecodeÚUnicodeDecodeErrorr	   ÚlookupÚAttributeError)r£   r   r   r   rW   Œ  s    

rW   )4Ú
__future__r   r   r   Úpip._vendor.sixr   r   Úpip._vendor.six.movesr   r   rµ   rˆ   Úpip._vendorr	   Ú	constantsr   r   r   r   r   r\   r   Úior   r   r©   rð   rÕ   ré   rñ   rê   Úinvalid_unicode_no_surrogaterR   rd   r)   r‰   Úevalrv   Úsetr   Úascii_punctuation_rer†   Úobjectr   rP   rJ   rK   r/   rÁ   r¾   rà   rW   r   r   r   r   Ú<module>   sX   
"








J g Ih 6'