� ��abc!@`s�ddlmZmZmZddlmZmZddlmZm Z ddl Z ddl Z ddl m Z ddlmZmZmZmZddlmZdd lmZdd lmZydd lmZWnek r�eZnXegeD]Zejd �^q��ZegeD]Zejd �^q"�ZegeD]Zejd �^qJ�Zeed dg�BZ dZ!ej"r�e j#e!d e$d�d�Z%ne j#e!�Z%e&dddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2g �Z'e j#d3�Z(iZ)d4e*fd5��YZ+d6�Z,d7e*fd8��YZ-d9e-fd:��YZ.d;e/fd<��YZ0d=e*fd>��YZ1d?e*fd@��YZ2dA�Z3dS(Bi(tabsolute_importtdivisiontunicode_literals(t text_typet binary_type(t http_clientturllibN(t webencodingsi(tEOFtspaceCharacterst asciiLetterstasciiUppercase(tReparseException(t_utils(tStringIO(tBytesIOuasciit>tt|j|�|krL|t|j|�8}|d7}qW||g|_dS(Nii(RRR(RRtoffsetti((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pytseekLs cC`sp|js|j|�S|jdt|j�kr_|jdt|jd�kr_|j|�S|j|�SdS(Niii����(Rt _readStreamRRt_readFromBuffer(Rtbytes((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pytreadUs     cC`s&tg|jD]}t|�^q �S(N(tsumRR(Rtitem((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyt_bufferedBytes^scC`sL|jj|�}|jj|�|jdcd7 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) u�iiuutf-8ucertainN( R tsupports_lone_surrogatestNonetreportCharacterErrorsRtcharacterErrorsUCS4tcharacterErrorsUCS2tnewLinestlookupEncodingt charEncodingt openStreamt dataStreamtreset(RR>((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�s    cC`sCd|_d|_d|_g|_d|_d|_d|_dS(Nui(Rt chunkSizet chunkOffsetterrorst prevNumLinest prevNumColsREt_bufferedCharacter(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRN�s      cC`s(t|d�r|}n t|�}|S(uvProduces a file object from source. source can be either a file object, local filename or a string. uread(R9R(RR>R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRL�s  cC`st|j}|jdd|�}|j|}|jdd|�}|dkr\|j|}n||d}||fS(Nu ii����i(RtcountRRtrfindRS(RRRtnLinest positionLinet lastLinePostpositionColumn((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyt _position�s   cC`s&|j|j�\}}|d|fS(u:Returns (line, col) of the current position in the stream.i(R[RP(Rtlinetcol((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�scC`sL|j|jkr%|j�s%tSn|j}|j|}|d|_|S(uo Read one character from the stream or queue if available. Return EOF when EOF is reached. i(RPROt readChunkRR(RRPtchar((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR_�s    cC`sO|dkr|j}n|j|j�\|_|_d|_d|_d|_|jj |�}|j r�|j |}d|_ n |s�t St |�dkr�t |d�}|dks�d|ko�dknr�|d|_ |d }q�n|jr|j|�n|jdd �}|jd d �}||_t |�|_tS( Nuiii����i i�i��u u u (REt_defaultChunkSizeR[RORRRSRRPRMR"RTR8RtordRFtreplacetTrue(RROR'tlastv((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR^�s0        (   cC`s:x3tttj|���D]}|jjd�qWdS(Nuinvalid-codepoint(trangeRtinvalid_unicode_retfindallRQR&(RR't_((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRG%s"cC`st}x�tj|�D]�}|r(qnt|j��}|j�}tj|||d!�r�tj|||d!�}|t kr�|j j d�nt }q|dkr�|dkr�|t |�dkr�|j j d�qt}|j j d�qWdS(Niuinvalid-codepointi�i��i(R8RftfinditerRatgrouptstartR tisSurrogatePairtsurrogatePairToCodepointtnon_bmp_invalid_codepointsRQR&RcR(RR'tskiptmatcht codepointRtchar_val((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRH)s    c C`sTyt||f}Wnqtk r�djg|D]}dt|�^q1�}|scd|}ntjd|�}t||f 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) iidN(RLt rawStreamR<Rt numBytesMetatnumBytesChardettoverride_encodingttransport_encodingtsame_origin_parent_encodingtlikely_encodingtdefault_encodingtdetermineEncodingRKRN(RR>R�R�R�R�R�t useChardet((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�s       cC`s3|jdjj|jd�|_tj|�dS(Niureplace(RKt codec_infot streamreaderR�RMR<RN(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRN�s"cC`sUt|d�r|}n t|�}y|j|j��Wnt|�}nX|S(uvProduces a file object from source. source can be either a file object, local filename or a string. uread(R9RRRR(RR>R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRL�s  cC`s |j�df}|ddk r&|St|j�df}|ddk rO|St|j�df}|ddk rx|S|j�df}|ddk r�|St|j�df}|ddk r�|djjd� r�|St|j �df}|ddk r|S|r�yddl m }Wnt k r4q�Xg}|�}xF|j s�|jj|j�}|soPn|j|�|j|�qGW|j�t|jd�}|jjd�|dk r�|dfSnt|j�df}|ddk r�|Std�dfS(Nucertainiu tentativeuutf-16(tUniversalDetectoruencodingu windows-1252(t detectBOMRERJR�R�tdetectEncodingMetaR�tnamet startswithR�tchardet.universaldetectorR�t ImportErrortdoneR�R"R�R&tfeedtclosetresultRR�(RtchardetRKR�tbufferstdetectorRtencoding((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR��sP'       cC`s�t|�}|dkrdS|jdkr:td�}nr||jdkrf|jddf|_nF|jjd�|df|_|j�td|jd|f��dS(Nuutf-16beuutf-16leuutf-8iucertainuEncoding changed from %s to %s(uutf-16beuutf-16le(RJRER�RKR�RRNR (Rt newEncoding((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pytchangeEncodings    cC`s�idtj6dtj6dtj6dtj6dtj6}|jjd�}|j|d �}d}|s�|j|�}d}|s�|j|d �}d}q�n|r�|jj |�t |�S|jj d �d Sd S( u�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 Noneuutf-8uutf-16leuutf-16beuutf-32leuutf-32beiiiiN( tcodecstBOM_UTF8t BOM_UTF16_LEt BOM_UTF16_BEt BOM_UTF32_LEt BOM_UTF32_BER�R"tgetRRJRE(RtbomDicttstringR�R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�s$   cC`sk|jj|j�}t|�}|jjd�|j�}|dk rg|jdkrgtd�}n|S(u9Report the encoding declared by the meta element iuutf-16beuutf-16leuutf-8N(uutf-16beuutf-16le( R�R"R�tEncodingParserRt getEncodingRER�RJ(RRtparserR�((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�9s  N( R0R1R2RERcRRNRLR�R�R�R�(((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR=�s(   >  "t EncodingBytescB`s�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z e e e �Z d �Z e e �Zed �Zd �Zd �Zd �ZRS(u�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 raisedcC`stj||j��S(N(R!t__new__tlower(Rtvalue((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�LscC`s d|_dS(Ni����(R[(RR�((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRPscC`s|S(N((R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyt__iter__TscC`sS|jd}|_|t|�kr/t�n|dkrDt�n|||d!S(Nii(R[Rt StopIterationR;(Rtp((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyt__next__Ws    cC`s |j�S(N(R�(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pytnext_scC`sY|j}|t|�kr$t�n|dkr9t�n|d|_}|||d!S(Nii(R[RR�R;(RR�((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pytpreviouscs    cC`s+|jt|�krt�n||_dS(N(R[RR�(RR((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyt setPositionls cC`s<|jt|�krt�n|jdkr4|jSdSdS(Ni(R[RR�RE(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyt getPositionqs  cC`s||j|jd!S(Ni(R(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pytgetCurrentByte{scC`sc|j}xJ|t|�krU|||d!}||krH||_|S|d7}q W||_dS(uSkip past a list of charactersiN(RRR[RE(RRzR�R{((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRo�s    cC`sc|j}xJ|t|�krU|||d!}||krH||_|S|d7}q W||_dS(Ni(RRR[RE(RRzR�R{((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyt skipUntil�s    cC`sQ|j}|||t|�!}|j|�}|rM|jt|�7_n|S(u�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(RRR�(RR!R�R'R+((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyt matchBytes�s  cC`sh||jj|�}|dkr^|jdkr=d|_n|j|t|�d7_tSt�dS(u�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 matchi����iiN(RtfindR[RRcR�(RR!t newPosition((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pytjumpTo�s  (R0R1R2R�RR�R�R�R�R�R�tpropertyRR�t currentBytetspaceCharactersBytesRoR�R�R�(((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�Hs           R�cB`s_eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z d �Z RS( u?Mini parser for detecting character encoding from meta elementscC`st|�|_d|_dS(u3string - the data to work on for encoding detectionN(R�R'RER�(RR'((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�scC`s�d|jfd|jfd|jfd|jfd|jfd|jff}xv|jD]k}t}xR|D]J\}}|jj|�rky|�}PWq�tk r�t }Pq�XqkqkW|sXPqXqXW|j S(Ns(R'R�(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR��scC`sK|jjtkrtSt}d}x"trF|j�}|dkrGtS|ddkr�|ddk}|rC|dk rC||_tSq%|ddkr�|d}t|�}|dk rC||_tSq%|ddkr%t t |d��}|j �}|dk rCt|�}|dk r@|r4||_tS|}q@qCq%q%WdS(Nis http-equivis content-typetcharsettcontent( R'R�R�RcR8REt getAttributeR�RJtContentAttrParserR�tparse(Rt hasPragmatpendingEncodingtattrttentativeEncodingtcodect contentParser((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR��s:             cC`s |jt�S(N(thandlePossibleTagR8(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR��scC`st|j�|jt�S(N(R�R'R�Rc(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR��s cC`s�|j}|jtkr9|r5|j�|j�ntS|jt�}|dkra|j�n+|j�}x|dk r�|j�}qpWtS(NR( R'R�tasciiLettersBytesR�R�RcR�tspacesAngleBracketsR�RE(RtendTagR'R{R�((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR��s      cC`s|jjd�S(NR(R'R�(R((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�scC`s�|j}|jttdg�B�}|dkr5dSg}g}x�tr�|dkr`|r`Pnz|tkr||j�}Pn^|d kr�dj|�dfS|tkr�|j|j ��n|dkr�dS|j|�t |�}qDW|dkr|j �dj|�dfSt |�|j�}|d kr�|}x�tr�t |�}||kr�t |�dj|�dj|�fS|tkr�|j|j ��q>|j|�q>Wn^|dkr�dj|�dfS|tkr�|j|j ��n|dkr dS|j|�x}tr�t |�}|t krSdj|�dj|�fS|tkru|j|j ��q|dkr�dS|j|�qWdS( u_Return a name,value pair for the next attribute in the stream, if one is found, or Nonet/Rt=R(t't"N(RN(R�R(R�R�( R'RoR�t frozensetRERcR)tasciiUppercaseBytesR&R�R�R�R�(RR'R{tattrNamet attrValuet quoteChar((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�sf                            ( R0R1R2RR�R�R�R�R�R�R�R�(((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR��s    $    R�cB`seZd�Zd�ZRS(cC`s ||_dS(N(R'(RR'((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRfscC`s:y!|jjd�|jjd7_|jj�|jjdksHdS|jjd7_|jj�|jjdkr�|jj}|jjd7_|jj}|jj|�r�|j||jj!SdSnP|jj}y(|jjt�|j||jj!SWntk r|j|SXWntk r5dSXdS(NR�iR�R�R�(R�R�( R'R�RRoR�RER�R�R�(Rt quoteMarkt oldPosition((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�js.       (R0R1RR�(((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyR�es cC`swt|t�r:y|jd�}Wq:tk r6dSXn|dk roytj|�SWqstk rkdSXndSdS(u{Return the python codec name corresponding to an encoding or None if the string doesn't correspond to a valid encoding.uasciiN(R3RtdecodetUnicodeDecodeErrorRERtlookuptAttributeError(R�((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pyRJ�s   (4t __future__RRRtpip._vendor.sixRRtpip._vendor.six.movesRRR�Rut pip._vendorRt constantsRR R R R R(R tioRRR�R�R$tencodeR�R�R�R�tinvalid_unicode_no_surrogateRDRvtevalRftsetRntascii_punctuation_reRstobjectRRCR<R=R!R�R�R�RJ(((sE/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/_inputstream.pytsP  "  (((  J ��h�'