3 '%s' codec can't decode byte #x%02x: %s in "%s", position %dz8unacceptable character #x%04x: %s in "%s", position %d) isinstancerbytesr ordr rr )r r r r__str__!s zReaderError.__str__N)__name__ __module__ __qualname__rrr r r rrsc@sfeZdZddZdddZdddZdd d Zd d Zd dZe j dZ ddZ ddZ dddZdS)rcCsd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ t |t rnd|_|j||d|_nHt |trd|_||_|jn(||_t|dd|_d |_d|_|jdS) NrTzz rzF)rstreamstream_pointereofbufferpointer raw_buffer raw_decoder indexlinecolumnrstrcheck_printablerdetermine_encodinggetattr)r rr r rr;s2     zReader.__init__rc CsDy|j|j|Stk r>|j|d|j|j|SXdS)Nr)rr IndexErrorupdate)r r r r rpeekWs z Reader.peekrcCs4|j|t|jkr|j||j|j|j|S)N)rlenrr()r lengthr r rprefix^s z Reader.prefixcCs|j|dt|jkr&|j|dx|r|j|j}|jd7_|jd7_|dkst|dkr|j|jdkr|jd7_d|_n|dkr|jd7_|d8}q(WdS)Nru …

  ru)rr*rr(r r!r")r r+Zchr r rforwardcs zReader.forwardcCsF|jdkr(t|j|j|j|j|j|jSt|j|j|j|jddSdS)N)rrrr r!r"rr)r r r rget_markrs   zReader.get_markcCsx,|j r,|jdks"t|jdkr,|jqWt|jtr|jjtjrXtj |_ d|_ n,|jjtj rvtj |_ d|_ ntj|_ d|_ |jddS)Nz utf-16-lez utf-16-bezutf-8r)rrr* update_rawrr startswithcodecs BOM_UTF16_LEutf_16_le_decoderr BOM_UTF16_BEutf_16_be_decode utf_8_decoder()r r r rr%zs"  zReader.determine_encodingu[^ -~… -퟿-�]cCsP|jj|}|rL|j}|jt|j|j|j}t|j |t |dddS)NZunicodez"special characters are not allowed) NON_PRINTABLEsearchgroupr r*rrstartrrr)r datamatchrr r r rr$s  zReader.check_printablecCs6|jdkrdS|j|jd|_d|_xt|j|kr0|jsH|j|jdk ry|j|jd|j\}}Wqtk r}zP|j|j}|j dk r|j t|j|j}n|j}t |j |||j |jWYdd}~XqXn|j}t|}|j||j|7_|j|d|_|jr*|jd7_d|_Pq*WdS)Nrstrictr)rrrr*rr2rUnicodeDecodeErrorr=rrrrr r r$)r r+r>Z convertedexcrr r r rr(s6       z Reader.updatecCsL|jj|}|jdkr||_n|j|7_|jt|7_|sHd|_dS)NT)rreadrrr*r)r sizer>r r rr2s  zReader.update_rawN)r)r)r)rC)rrrrr)r,r/r0r%recompiler:r$r(r2r r r rr-s    ) __all__errorrrr4rFrobjectrr r r rs