
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
ÝPf  ã            )   @   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 �r(ej!eddF… e"dƒ d ƒZ#n
ej!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.d/d0d1d2d3d4g ƒZ%ej!d5ƒZ&i Z'G d6d7„ d7e(ƒZ)d8d9„ Z*G d:d;„ d;e(ƒZ+G d<d=„ d=e+ƒZ,G d>d?„ d?e-ƒZ.G d@dA„ dAe(ƒZ/G dBdC„ dCe(ƒZ0dDdE„ Z1d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 | ]}|j d ƒ‘qS )Úascii)Úencode)Ú.0Úitem© r   ú"/usr/lib/python3.6/_inputstream.pyú
<listcomp>   s    r   c             C   s   g | ]}|j d ƒ‘qS )r   )r   )r   r   r   r   r   r      s    c             C   s   g | ]}|j 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   sH   |}d}x0t | j| ƒ|k r8|t | j| ƒ8 }|d7 }q
W ||g| _d S )Nr   r
   )r$   r    r!   )r"   r%   ÚoffsetÚir   r   r   ÚseekL   s    zBufferedStream.seekc             C   sT   | j s| j|ƒS | jd t| j ƒkrF| jd t| j d ƒkrF| j|ƒS | j|ƒ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   Ú_bufferedBytes^   s    zBufferedStream._bufferedBytesc             C   s<   | j j|ƒ}| jj|ƒ | jd  d7  < t|ƒ| jd< |S )Nr   r
   )r   r.   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¨| j| }|t|ƒ| krb|}||| g| _ n"t|ƒ| }|t|ƒg| _ |d7 }|j|||| … ƒ ||8 }d}qW |r¾|j| j|ƒƒ dj|ƒS )Nr   r
   ó    )r!   r$   r    r1   r+   Újoin)r"   r-   ZremainingBytesÚrvZbufferIndexZbufferOffsetZbufferedDataZbytesToReadr   r   r   r,   h   s$    


zBufferedStream._readFromBufferN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r'   r*   r.   r0   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 | jdƒt	ƒ}n
t | t	ƒ}|r‚dd„ |D ƒ}|rvt
d| ƒ‚t| f|ŽS t| f|ŽS d S )NFr.   r   c             S   s   g | ]}|j d ƒr|‘qS )Z	_encoding)Úendswith)r   Úxr   r   r   r   ‘   s    z#HTMLInputStream.<locals>.<listcomp>z3Cannot set an encoding with a unicode input, set %r)Ú
isinstancer   ZHTTPResponser   ZresponseZaddbaseÚfpÚhasattrr.   r   Ú	TypeErrorÚHTMLUnicodeInputStreamÚHTMLBinaryInputStream)ÚsourceÚkwargsZ	isUnicodeZ	encodingsr   r   r   ÚHTMLInputStreamƒ   s    

rD   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 )r@   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| _| j	|ƒ| _
| jƒ  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ÚcharacterErrorsUCS2ZnewLinesÚlookupEncodingÚcharEncodingÚ
openStreamÚ
dataStreamÚreset)r"   rB   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   rN   Ä   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.

        r.   )r>   r   )r"   rB   r   r   r   r   rL   Ò   s    
z!HTMLUnicodeInputStream.openStreamc             C   sT   | j }|jdd|ƒ}| j| }|jdd|ƒ}|dkr@| j| }n||d  }||fS )NÚ
r   r
   r   )r&   ÚcountrS   ÚrfindrT   )r"   r(   r&   ZnLinesZpositionLineZlastLinePosZpositionColumnr   r   r   Ú	_positionà   s    
z HTMLUnicodeInputStream._positionc             C   s   | j | jƒ\}}|d |fS )z:Returns (line, col) of the current position in the stream.r
   )rY   rQ   )r"   ÚlineÚcolr   r   r   r!   ë   s    zHTMLUnicodeInputStream.positionc             C   s6   | j | jkr| jƒ 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
   )rQ   rP   Ú	readChunkr   r&   )r"   rQ   Úcharr   r   r   r]   ð   s    

zHTMLUnicodeInputStream.charNc             C   sê   |d kr| j }| j| jƒ\| _| _d| _d| _d| _| jj|ƒ}| j	rX| j	| }d | _	n|s`dS t
|ƒdkr®t|d ƒ}|dks˜d|  ko’dkn  r®|d | _	|d d… }| jr¾| j|ƒ |jdd	ƒ}|jd
d	ƒ}|| _t
|ƒ| _dS )NrO   r   Fr
   é   i Ø  iÿÛ  z
rV   úTr   r   r   )Ú_defaultChunkSizerY   rP   rS   rT   r&   rQ   rM   r.   rU   r$   ÚordrG   Úreplace)r"   rP   r2   Zlastvr   r   r   r\   ÿ   s0    
 


z HTMLUnicodeInputStream.readChunkc             C   s,   x&t ttj|ƒƒƒD ]}| jjdƒ qW d S )Nzinvalid-codepoint)Úranger$   Úinvalid_unicode_reÚfindallrR   r1   )r"   r2   Ú_r   r   r   rH   %  s    z*HTMLUnicodeInputStream.characterErrorsUCS4c             C   sº   d}x°t j|ƒD ]¢}|rqt|jƒ ƒ}|jƒ }tj|||d … ƒrttj|||d … ƒ}|tkrn| j	j
dƒ d}q|dkr¢|dkr¢|t|ƒd kr¢| j	j
dƒ qd}| j	j
dƒ qW d S )NFé   zinvalid-codepointTi Ø  iÿß  r
   )rd   Úfinditerra   ÚgroupÚstartr   ZisSurrogatePairZsurrogatePairToCodepointÚnon_bmp_invalid_codepointsrR   r1   r$   )r"   r2   ÚskipÚmatchZ	codepointr%   Zchar_valr   r   r   rI   )  s     z*HTMLUnicodeInputStream.characterErrorsUCS2Fc       	      C   sð   yt ||f }W nN tk
r^   djdd„ |D ƒƒ}|s@d| }tjd| ƒ }t ||f< Y nX g }x||j| j| jƒ}|dkrŽ| j| jkr¾P n0|j	ƒ }|| jkr¾|j
| j| j|… ƒ || _P |j
| j| jd… ƒ | jƒ sfP qfW dj|ƒ}|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.
        rO   c             S   s   g | ]}d t |ƒ ‘qS )z\x%02x)ra   )r   Úcr   r   r   r   N  s    z5HTMLUnicodeInputStream.charsUntil.<locals>.<listcomp>z^%sz[%s]+N)ÚcharsUntilRegExÚKeyErrorr4   ÚreÚcompilerm   r&   rQ   rP   Úendr1   r\   )	r"   Z
charactersZoppositeÚcharsZregexr5   Úmrs   Úrr   r   r   Ú
charsUntil@  s.     

z!HTMLUnicodeInputStream.charsUntilc             C   s@   |d k	r<| j dkr.|| j | _|  jd7  _n|  j d8  _ d S )Nr   r
   )rQ   r&   rP   )r"   r]   r   r   r   Úungeto  s    
zHTMLUnicodeInputStream.unget)N)F)r6   r7   r8   r9   r`   r#   rN   rL   rY   r!   r]   r\   rH   rI   rw   rx   r   r   r   r   r@   š   s    
&
/r@   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 )rA   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   s\   | j |ƒ| _tj| | jƒ d| _d| _|| _|| _|| _|| _	|| _
| j|ƒ| _| jƒ  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   N)rL   Ú	rawStreamr@   r#   ÚnumBytesMetaÚnumBytesChardetÚoverride_encodingÚtransport_encodingÚsame_origin_parent_encodingÚlikely_encodingÚdefault_encodingÚdetermineEncodingrK   rN   )r"   rB   r~   r   r€   r�   r‚   Z
useChardetr   r   r   r#   ˆ  s    zHTMLBinaryInputStream.__init__c             C   s&   | j d jj| jdƒ| _tj| ƒ d S )Nr   rb   )rK   Z
codec_infoÚstreamreaderr{   rM   r@   rN   )r"   r   r   r   rN   ²  s    zHTMLBinaryInputStream.resetc          	   C   sD   t |dƒr|}nt|ƒ}y|j|jƒ ƒ 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.

        r.   )r>   r   r*   r'   r   )r"   rB   r   r   r   r   rL   ¶  s    
z HTMLBinaryInputStream.openStreamc             C   s�  | j ƒ 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 | jƒ df}|d d k	rt|S t| jƒdf}|d d k	r¤|d jjdƒ r¤|S t| jƒdf}|d d k	rÂ|S |�rdyddl	m
} W n tk
rì   Y nxX g }|ƒ }x6|j�s.| jj| jƒ}|�sP |j|ƒ |j|ƒ qúW |jƒ  t|jd ƒ}| jjdƒ |d k	�rd|dfS t| jƒdf}|d d k	�r„|S tdƒdfS )NrE   r   Z	tentativezutf-16)ÚUniversalDetectorÚencodingzwindows-1252)Ú	detectBOMrJ   r~   r   ÚdetectEncodingMetar€   ÚnameÚ
startswithr�   Zchardet.universaldetectorr…   ÚImportErrorÚdoner{   r.   r}   r1   ZfeedÚcloseÚresultr*   r‚   )r"   ZchardetrK   r…   ZbuffersZdetectorr    r†   r   r   r   rƒ   É  sP    


z'HTMLBinaryInputStream.determineEncodingc             C   s€   t |ƒ}|d krd S |jdkr(t dƒ}nT|| jd krH| jd df| _n4| jjdƒ |df| _| jƒ  td| jd |f ƒ‚d S )Núutf-16beúutf-16lezutf-8r   rE   zEncoding changed from %s to %s)r�   r�   )rJ   r‰   rK   r{   r*   rN   r   )r"   Z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jdƒ}|j|dd… ƒ}d}|sp|j|ƒ}d}|sp|j|dd	… ƒ}d	}|rˆ| jj	|ƒ t
|ƒS | j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é   rg   r   )ÚcodecsÚBOM_UTF8ÚBOM_UTF16_LEÚBOM_UTF16_BEÚBOM_UTF32_LEÚBOM_UTF32_BEr{   r.   Úgetr*   rJ   )r"   ZbomDictÚstringr†   r*   r   r   r   r‡     s"    
zHTMLBinaryInputStream.detectBOMc             C   sH   | j j| jƒ}t|ƒ}| j jdƒ |jƒ }|dk	rD|jdkrDtdƒ}|S )z9Report the encoding declared by the meta element
        r   Núutf-16beúutf-16lezutf-8)rœ   r�   )r{   r.   r|   ÚEncodingParserr*   ÚgetEncodingr‰   rJ   )r"   r    Úparserr†   r   r   r   rˆ   9  s    z(HTMLBinaryInputStream.detectEncodingMeta)NNNNry   T)T)r6   r7   r8   r9   r#   rN   rL   rƒ   r‘   r‡   rˆ   r   r   r   r   rA   €  s     
(
>"rA   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 j| |jƒ ƒS )N)r-   Ú__new__Úlower)r"   Úvaluer   r   r   r¢   L  s    zEncodingBytes.__new__c             C   s
   d| _ d S )Nr
   r   )rY   )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   )rY   r$   ÚStopIterationr?   )r"   Úpr   r   r   Ú__next__W  s    zEncodingBytes.__next__c             C   s   | j ƒ 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
   )rY   r$   r¦   r?   )r"   r§   r   r   r   Úpreviousc  s    zEncodingBytes.previousc             C   s   | j t| ƒkrt‚|| _ d S )N)rY   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   )rY   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$   rY   )r"   rt   r§   rn   r   r   r   rl   €  s    zEncodingBytes.skipc             C   sL   | j }x:|t| ƒk r@| ||d … }||kr6|| _|S |d7 }qW || _d S )Nr
   )r!   r$   rY   )r"   rt   r§   rn   r   r   r   Ú	skipUntilŒ  s    zEncodingBytes.skipUntilc             C   s>   | j }| ||t|ƒ … }|j|ƒ}|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§   r2   r5   r   r   r   Ú
matchBytes—  s    
zEncodingBytes.matchBytesc             C   sR   | | j d… j|ƒ}|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   Tr   r   )r!   ÚfindrY   r$   r¦   )r"   r-   ZnewPositionr   r   r   ÚjumpTo¢  s    
zEncodingBytes.jumpToN)r6   r7   r8   r9   r¢   r#   r¥   r¨   r©   rª   r«   r¬   Úpropertyr!   r­   ÚcurrentByteÚspaceCharactersBytesrl   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¡   r2   r†   )r"   r2   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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ÚhandlePossibleStartTagr2   r¯   r¦   r†   )r"   ZmethodDispatchrf   ZkeepParsingÚkeyÚmethodr   r   r   rŸ   ¸  s&    zEncodingParser.getEncodingc             C   s   | j jdƒS )zSkip over commentss   -->)r2   r±   )r"   r   r   r   rµ   Ï  s    zEncodingParser.handleCommentc             C   sä   | j jtkrdS d}d }xÆ| jƒ }|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 ƒƒ}|jƒ }|d k	rt|ƒ}|d k	r|rØ|| _dS |}qW d S )	NTFr   s
   http-equivr
   s   content-types   charsets   content)	r2   r³   r´   ÚgetAttributer†   rJ   ÚContentAttrParserr¡   Úparse)r"   Z	hasPragmaZpendingEncodingÚattrZtentativeEncodingÚcodecZcontentParserr   r   r   r¶   Ó  s:    zEncodingParser.handleMetac             C   s
   | j dƒS )NF)ÚhandlePossibleTag)r"   r   r   r   r¹   ÷  s    z%EncodingParser.handlePossibleStartTagc             C   s   t | jƒ | jdƒS )NT)r©   r2   rÁ   )r"   r   r   r   r·   ú  s    
z#EncodingParser.handlePossibleEndTagc             C   sf   | j }|jtkr(|r$|jƒ  | jƒ  dS |jtƒ}|dkrD|jƒ  n| jƒ }x|d k	r`| jƒ }qNW dS )NTr   )r2   r³   ÚasciiLettersBytesrª   r¸   r®   ÚspacesAngleBracketsr¼   )r"   ZendTagr2   rn   r¿   r   r   r   rÁ   þ  s    



z EncodingParser.handlePossibleTagc             C   s   | j jdƒS )Nr   )r2   r±   )r"   r   r   r   r¸     s    zEncodingParser.handleOtherc             C   sè  | j }|jttdgƒB ƒ}|dkr&dS g }g }xt|dkr@|r@P nX|tkrT|jƒ }P nD|d	krjdj|ƒdfS |tkr‚|j|jƒ ƒ n|dkrŽdS |j|ƒ t|ƒ}q0W |dkrÂ|j	ƒ  dj|ƒdfS t|ƒ |jƒ }|d
k�r:|}x¢t|ƒ}||k�rt|ƒ dj|ƒdj|ƒfS |tk�r*|j|jƒ ƒ qâ|j|ƒ qâW nJ|dk�rRdj|ƒdfS |tk�rl|j|jƒ ƒ n|dk�rzdS |j|ƒ x^t|ƒ}|t
k�r¬dj|ƒdj|ƒfS |tk�rÆ|j|jƒ ƒ n|dk�rÔdS |j|ƒ �q†W dS )z_Return a name,value pair for the next attribute in the stream,
        if one is found, or Noneó   /r   Nó   =r3   ó   'ó   ")r   N)rÄ   r   )rÆ   rÇ   )r2   rl   r´   Ú	frozensetr4   ÚasciiUppercaseBytesr1   r£   r©   rª   rÃ   )r"   r2   rn   ZattrNameZ	attrValueZ	quoteCharr   r   r   r¼     sf    










zEncodingParser.getAttributeN)r6   r7   r8   r9   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
   || _ d S )N)r2   )r"   r2   r   r   r   r#   f  s    zContentAttrParser.__init__c             C   s  yê| j jdƒ | j  jd7  _| j jƒ  | j jdks8d S | j  jd7  _| j jƒ  | j jdkr¢| j j}| j  jd7  _| j j}| j j|ƒrœ| j || j j… S d S nF| j j}y| j 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Æ   )rÇ   rÆ   )r2   r±   r!   rl   r³   r®   r´   r¦   )r"   Z	quoteMarkZoldPositionr   r   r   r¾   j  s.    

zContentAttrParser.parseN)r6   r7   r8   r#   r¾   r   r   r   r   r½   e  s   r½   c             C   s`   t | tƒr.y| jdƒ} W n tk
r,   dS X | dk	rXy
tj| ƒ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)r<   r   ÚdecodeÚUnicodeDecodeErrorr	   ÚlookupÚAttributeError)r†   r   r   r   rJ   Œ  s    

rJ   r   )2Z
__future__r   r   r   Zpip._vendor.sixr   r   Zpip._vendor.six.movesr   r   r”   rq   Zpip._vendorr	   Z	constantsr   r   r   r   r   rO   r   Úior   r   r‹   rÈ   r´   rÂ   rÉ   rÃ   Zinvalid_unicode_no_surrogaterF   rr   Úevalrd   Úsetrk   Zascii_punctuation_rero   Úobjectr   rD   r@   rA   r-   r¡   rž   r½   rJ   r   r   r   r   Ú<module>   sV   









J g Ih 6'