r2Wc!@`sddlmZmZmZddlmZddlmZddlZddl Z ddl m Z m Z m Z mZddl mZmZddlmZdd lmZydd lmZWnek reZnXydd lmZWn'ek rd efd YZnXege D]Zejd^q"Zege D]Zejd^qJZegeD]Zejd^qrZeeddgBZdZ ej!re j"e e#dZ$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"d3Z'iZ(d4efd5YZ)de+e+d6Z,d7efd8YZ-d9e-fd:YZ.d;e/fd<YZ0d=efd>YZ1d?efd@YZ2dAZ3dS(Bi(tabsolute_importtdivisiontunicode_literals(t text_type(t http_clientNi(tEOFtspaceCharacterst asciiLetterstasciiUppercase(t encodingstReparseException(tutils(tStringIO(tBytesIO(tBufferedIOBaseRcB`seZRS((t__name__t __module__(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRsuasciit>tt|j||krd|t|j|8}|d7}q'W||g|_dS(Nii(t_bufferedBytestAssertionErrorRRR(RRtoffsetti((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pytseekMscC`sp|js|j|S|jdt|jkr_|jdt|jdkr_|j|S|j|SdS(Niii(Rt _readStreamRRt_readFromBuffer(Rtbytes((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pytreadVs     cC`s&tg|jD]}t|^q S(N(tsumRR(Rtitem((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyR_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) parseMeta - Look for a element containing encoding information u􏿿iu"[\uD800-\uDFFF]"uJ"([\uD800-\uDBFF](?![\uDC00-\uDFFF])|(? 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) parseMeta - Look for a element containing encoding information ucertainiidu windows-1252iN( RKt rawStreamR9Rt codecNameRJt numBytesMetatnumBytesChardettdefaultEncodingR7tdetectEncodingRM(RR;R<R=R>((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRs   cC`s6tj|jd|jd|_tj|dS(Niureplace(tcodecst getreaderRJR~RLR9RM(R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRMs cC`sUt|dr|}n t|}y|j|jWnt|}nX|S(uvProduces a file object from source. source can be either a file object, local filename or a string. uread(R6R R!RR(RR;R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRKs  c C`s|j}d}|dkr9|r9|j}d}n|dkr8|r8d}yyddlm}Wn!tk rddlm}nXg}|}x[|js|jj |j }t |t st |sPn|j||j|qW|j|jd}|jjdWq8tk r4q8Xn|dkrVd}|j}nidd6} |j| kr| |j}n||fS(Nucertainu tentativei(tUniversalDetectoruencodingu windows-1252u iso-8859-1(t detectBOMR7tdetectEncodingMetatcharade.universaldetectorRt ImportErrortchardet.universaldetectortdoneR~R%RR3R$RR(tfeedtclosetresultR!Rtlower( RR=R>R<t confidenceRtbufferstdetectorRt encodingSub((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRsB             cC`s|jddkstt|}|d kr:d}n|dkrJdS||jdkrv|jddf|_nF|jjd|j|df|_td|jd|fdS( Niucertainuutf-16u utf-16-beu utf-16-leuutf-8iuEncoding changed from %s to %s(uutf-16u utf-16-beu utf-16-le(RJRRR7R~R!RMR (Rt newEncoding((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pytchangeEncodings     cC`sidtj6dtj6dtj6dtj6dtj6}|jjd}t|t s_t |j |d }d}|s|j |}d}|s|j |d }d}qn|jj |r|pd |S( uAttempts 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-8u utf-16-leu utf-16-beu utf-32-leu utf-32-beiiii( RtBOM_UTF8t BOM_UTF16_LEt BOM_UTF16_BEt BOM_UTF32_LEt BOM_UTF32_BER~R%R3R$RtgetR!(RtbomDicttstringR<R!((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyR s   cC`sk|jj|j}t|ts*tt|}|jjd|j}|dkrgd}n|S(u9Report the encoding declared by the meta element iuutf-16u utf-16-beu utf-16-leuutf-8(uutf-16u utf-16-beu utf-16-le( R~R%RR3R$RtEncodingParserR!t getEncoding(RRtparserR<((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyR)s    N( RRR2R7RcRRMRKRRRR(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyR:s(  -  t EncodingBytescB`seZdZdZdZdZdZdZdZdZ dZ e e e Z d Z e e Zed Zd Zd Zd ZRS(uString-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`s+t|tsttj||jS(N(R3R$Rt__new__R(Rtvalue((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyR<scC`s d|_dS(Ni(RZ(RR((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyR@scC`s|S(N((R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyt__iter__CscC`sS|jd}|_|t|kr/tn|dkrDtn|||d!S(Nii(RZRt StopIterationR8(Rtp((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyt__next__Fs    cC`s |jS(N(R(R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pytnextNscC`sY|j}|t|kr$tn|dkr9tn|d|_}|||d!S(Nii(RZRRR8(RR((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pytpreviousRs    cC`s+|jt|krtn||_dS(N(RZRR(RR((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyt setPosition[s cC`s<|jt|krtn|jdkr4|jSdSdS(Ni(RZRRR7(R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyt getPosition`s  cC`s||j|jd!S(Ni(R(R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pytgetCurrentBytejscC`sc|j}xJ|t|krU|||d!}||krH||_|S|d7}q W||_dS(uSkip past a list of charactersiN(RRRZR7(RRwRRx((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRnos    cC`sc|j}xJ|t|krU|||d!}||krH||_|S|d7}q W||_dS(Ni(RRRZR7(RRwRRx((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyt skipUntil{s    cC`sQ|j}|||t|!}|j|}|rM|jt|7_n|S(uLook 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(RRt startswith(RR$RR)R-((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyt matchBytess  cC`sh||jj|}|dkr^|jdkr=d|_n|j|t|d7_tStdS(uLook for the next sequence of bytes matching a given sequence. If a match is found advance the position to the last byte of the matchiiiN(RtfindRZRRcR(RR$t newPosition((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pytjumpTos  (RRR2RRRRRRRRtpropertyRRt currentBytetspaceCharactersBytesRnRRR(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyR8s           RcB`s_eZdZdZdZdZdZdZdZdZ dZ 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(RR)R7R<(RR)((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRscC`sd|jfd|jfd|jfd|jfd|jfd|jff}xv|jD]k}t}xR|D]J\}}|jj|rky|}PWqtk rt }PqXqkqkW|sXPqXqXW|j S(Ns(R)R(R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRscC`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)RRRcR5R7t getAttributeR<RtContentAttrParserRtparse(Rt hasPragmatpendingEncodingtattrttentativeEncodingtcodect contentParser((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRs:             cC`s |jtS(N(thandlePossibleTagR5(R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRscC`st|j|jtS(N(RR)RRc(R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRs cC`s|j}|jtkr9|r5|j|jntS|jt}|dkra|jn+|j}x|dk r|j}qpWtS(NR( R)RtasciiLettersBytesRRRcRtspacesAngleBracketsRR7(RtendTagR)RxR((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRs      cC`s|jjdS(NR(R)R(R((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRscC`s|j}|jttdgB}|dksIt|dksIt|d krYdSg}g}xtr |dkr|rPnz|tkr|j}Pn^|d krdj|dfS|t kr|j |j n|dkrdS|j |t |}qhW|dkr7|j dj|dfSt ||j}|d kr|}xtrt |}||krt |dj|dj|fS|t kr|j |j qb|j |qbWn^|dkrdj|dfS|t kr|j |j n|dkr-dS|j |x}trt |}|tkrwdj|dj|fS|t kr|j |j q=|dkrdS|j |q=WdS( u_Return a name,value pair for the next attribute in the stream, if one is found, or Nonet/iRt=R*t't"N(RN(RR(RR(R)RnRt frozensetR7RRRcR+tasciiUppercaseBytesR(RRRR(RR)RxtattrNamet attrValuet quoteChar((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRsh $                           ( RRR2RRRRRRRRR(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRs    $    RcB`seZdZdZRS(cC`s"t|tst||_dS(N(R3R$RR)(RR)((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRUscC`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(NRiRRR(RR( R)RRRnRR7RRR(Rt quoteMarkt oldPosition((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRYs.       (RRRR(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyRTs cC`spt|tr:y|jd}Wq:tk r6dSXn|rhtjd|j}tj |dSdSdS(u{Return the python codec name corresponding to an encoding or None if the string doesn't correspond to a valid encoding.uasciiuN( R3R$tdecodetUnicodeDecodeErrorR7tascii_punctuation_reRaRR R(R<t canonicalName((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pyR{s (4t __future__RRRtpip._vendor.sixRtpip._vendor.six.movesRRREt constantsRRRRR R R*R tioR R RRtobjectRR'tencodeRRRRtinvalid_unicode_no_surrogateRARFRGRftsetRmRRrRR7RcR@R9R:R$RRRR(((sD/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/inputstream.pytsT  "   (((  Jg'