3 \%@stdZddlZdddZdddZGdd d ejZGd d d ejZGd d d ejZGdddejZddZ dS)a Python 'utf-8-sig' Codec This work similar to UTF-8 with the following changes: * On encoding/writing a UTF-8 encoded BOM will be prepended/written as the first three bytes. * On decoding/reading if the first three bytes are a UTF-8 encoded BOM, these bytes will be skipped. NstrictcCstjtj||dt|fS)Nr)codecsBOM_UTF8 utf_8_encodelen)inputerrorsr +/usr/lib64/python3.6/encodings/utf_8_sig.pyencodesr cCsDd}|ddtjkr&|dd}d}tj||d\}}|||fS)NrT)rr utf_8_decode)rrprefixoutputconsumedr r r decodes  rc@s8eZdZdddZdddZddZd d Zd d Zd S)IncrementalEncoderrcCstjj||d|_dS)N)rr__init__first)selfrr r r rszIncrementalEncoder.__init__FcCs:|jr$d|_tjtj||jdStj||jdSdS)Nr)rrrrr)rrfinalr r r r s zIncrementalEncoder.encodecCstjj|d|_dS)Nr)rrresetr)rr r r r's zIncrementalEncoder.resetcCs|jS)N)r)rr r r getstate+szIncrementalEncoder.getstatecCs ||_dS)N)r)rstater r r setstate.szIncrementalEncoder.setstateN)r)F)__name__ __module__ __qualname__rr rrrr r r r rs   rc@s6eZdZd ddZddZddZdd Zd d Zd S)IncrementalDecoderrcCstjj||d|_dS)Nr)rBufferedIncrementalDecoderrr)rrr r r r2szIncrementalDecoder.__init__cCsv|jrht|dkr*tjj|r"dSd|_n>d|_|ddtjkrhtj|dd||\}}||dfStj|||S)Nr r)r!r)rrrr startswithr )rrrrrrr r r _buffer_decode6s   z!IncrementalDecoder._buffer_decodecCstjj|d|_dS)Nr)rr rr)rr r r rGs zIncrementalDecoder.resetcCstjj|}|d|jfS)Nr)rr rr)rrr r r rKs zIncrementalDecoder.getstatecCstjj|||d|_dS)Nr)rr rr)rrr r r rPszIncrementalDecoder.setstateN)r)rrrrr#rrrr r r r r1s  rc@seZdZddZdddZdS) StreamWriterc Cs.tjj|y|`Wntk r(YnXdS)N)rr$rr AttributeError)rr r r rVs  zStreamWriter.resetrcCstj|_t||S)N)rrr )rrrr r r r ]szStreamWriter.encodeN)r)rrrrr r r r r r$Usr$c@seZdZddZdddZdS) StreamReaderc Cs.tjj|y|`Wntk r(YnXdS)N)rr&rrr%)rr r r rbs  zStreamReader.resetrcCspt|dkrtjj|r\dSn>|ddtjkr\tj|_tj|dd|\}}||dfStj|_tj||S)Nr r!r)r!r)rrrr"r r)rrrrrr r r ris   zStreamReader.decodeN)r)rrrrrr r r r r&asr&c CstjdttttttdS)Nz utf-8-sig)namer rincrementalencoderincrementaldecoder streamreader streamwriter)r CodecInfor rrrr&r$r r r r getregentryysr-)r)r) __doc__rr rrr rr$r&r-r r r r  s  $