2{Yc!@`sddlmZmZmZddlmZddlZddlZddlm Z m Z m Z m Z ddlm Z mZddlmZddlmZydd lmZWnek reZnXydd lmZWn'ek rd efd YZnXege D]Zejd ^qZege D]Zejd ^q:Zege D]Zejd ^qbZeeddgBZejdZe dddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0g Z!ejd1Z"iZ#d2efd3YZ$de&e&d4Z'd5efd6YZ(d7e(fd8YZ)d9e*fd:YZ+d;efd<YZ,d=efd>YZ-d?Z.dS(@i(tabsolute_importtdivisiontunicode_literals(t text_typeNi(tEOFtspaceCharacterst asciiLetterstasciiUppercase(t encodingstReparseException(tutils(tStringIO(tBytesIO(tBufferedIOBaseR cB`seZRS((t__name__t __module__(((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyR suasciit>tt|j||krd|t|j|8}|d7}q'W||g|_dS(Nii(t_bufferedBytestAssertionErrorRRR(RRtoffsetti((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pytseekAscC`sp|js|j|S|jdt|jkr_|jdt|jdkr_|j|S|j|SdS(Niii(Rt _readStreamRRt_readFromBuffer(Rtbytes((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pytreadJs     cC`s&tg|jD]}t|^q S(N(tsumRR(Rtitem((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRSscC`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 [-]u0([-](?![-])|(?s"cC`st}xtj|D]}|r(qnt|j}|j}tj|||d!rtj|||d!}|t kr|j j dnt }q|dkr|dkr|t |dkr|j j dqt}|j j dqWdS(Niuinvalid-codepointiii(R[RbtfinditerR\tgrouptstartR tisSurrogatePairtsurrogatePairToCodepointtnon_bmp_invalid_codepointsRKR'R_R(RR(tskiptmatcht codepointRtchar_val((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRCs    c C`s}yt||f}Wntk rx&|D]}t|dks+tq+Wdjg|D]}dt|^qZ}|sd|}ntjd|}t||fRCR[RxRy(((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyR6s !     (   /R7cB`s\eZdZdeedZdZdZeedZdZ dZ dZ RS( uProvides 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. cC`s|j||_tj||jt|df|_d|_d|_d|_|jddkr|j |||_n|j dS(uInitialises 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) parseMeta - Look for a element containing encoding information ucertainiidu windows-1252iN( RFt rawStreamR6Rt codecNameREt numBytesMetatnumBytesChardettdefaultEncodingR4tdetectEncodingRH(RR8R9R:R;((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRxs   cC`s6tj|jd|jd|_tj|dS(Niureplace(tcodecst getreaderRERzRGR6RH(R((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRHs 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(R2R R RR(RR8R((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRFs  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 detectBOMR4tdetectEncodingMetatcharade.universaldetectorRt ImportErrortchardet.universaldetectortdoneRzR$R}R3R#RR'tfeedtclosetresultR R~tlower( RR:R;R9t confidenceRtbufferstdetectorRt encodingSub((sQ/opt/alt/python33/lib/python3.3/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(RERR{R4RzR RHR (Rt newEncoding((sQ/opt/alt/python33/lib/python3.3/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_BERzR$R3R#RtgetR (RtbomDicttstringR9R ((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRs   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( RzR$R|R3R#RtEncodingParserR t getEncoding(RRtparserR9((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRs    N( RRR1R4R_RRHRFRRRR(((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyR7ps(  -  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((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyR&scC`s d|_dS(Ni(RU(RR((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyR*scC`s|S(N((R((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyt__iter__-scC`sS|jd}|_|t|kr/tn|dkrDtn|||d!S(Nii(RURt StopIterationR5(Rtp((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyt__next__0s    cC`s |jS(N(R(R((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pytnext8scC`sY|j}|t|kr$tn|dkr9tn|d|_}|||d!S(Nii(RURRR5(RR((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pytprevious<s    cC`s+|jt|krtn||_dS(N(RURR(RR((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyt setPositionEs cC`s<|jt|krtn|jdkr4|jSdSdS(Ni(RURRR4(R((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyt getPositionJs  cC`s||j|jd!S(Ni(R(R((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pytgetCurrentByteTscC`sc|j}xJ|t|krU|||d!}||krH||_|S|d7}q W||_dS(uSkip past a list of charactersiN(RRRUR4(RRsRRt((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRjYs    cC`sc|j}xJ|t|krU|||d!}||krH||_|S|d7}q W||_dS(Ni(RRRUR4(RRsRRt((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyt skipUntiles    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,((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyt matchBytesps  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(RtfindRURR_R(RR#t newPosition((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pytjumpTo{s  (RRR1RRRRRRRRtpropertyRRt currentBytetspaceCharactersBytesRjRRR(((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyR"s           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(R4R9(RR(((sQ/opt/alt/python33/lib/python3.3/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((sQ/opt/alt/python33/lib/python3.3/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(RRR_R[R4t getAttributeR9R{tContentAttrParserRtparse(Rt hasPragmatpendingEncodingtattrttentativeEncodingtcodect contentParser((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRs:             cC`s |jtS(N(thandlePossibleTagR[(R((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRscC`st|j|jtS(N(RR(RR_(R((sQ/opt/alt/python33/lib/python3.3/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(RtasciiLettersBytesRRR_RtspacesAngleBracketsRR4(RtendTagR(RtR((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRs      cC`s|jjdS(NR(R(R(R((sQ/opt/alt/python33/lib/python3.3/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(RjRt frozensetR4RRR_R*tasciiUppercaseBytesR'RRRR(RR(RttattrNamet attrValuet quoteChar((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRsh $                           ( RRR1RRRRRRRRR(((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRs    $    RcB`seZdZdZRS(cC`s"t|tst||_dS(N(R3R#RR((RR(((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyR?scC`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(RRRjRR4RRR(Rt quoteMarkt oldPosition((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyRCs.       (RRRR(((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyR>s 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#tdecodetUnicodeDecodeErrorR4tascii_punctuation_reR]RRR(R9t canonicalName((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pyR{es (/t __future__RRRtpip._vendor.sixRRR@t constantsRRRRRR R)R tioR R RR tobjectRR&tencodeRRRRRARbtsetRiRRnRR4R_R=R6R7R#RRRR{(((sQ/opt/alt/python33/lib/python3.3/site-packages/pip/_vendor/html5lib/inputstream.pytsJ  "   (((Jg'