f _%@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. NstrictcCstjt||dt|fSNr)codecsBOM_UTF8 utf_8_encodelen)inputerrorsr ,/usr/lib64/python3.10/encodings/utf_8_sig.pyencodesr cCsDd}|ddtjkr&|dd}d}t||d\}}|||fS)NrT)rr utf_8_decode)rr prefixoutputconsumedr r r decodes  rc@s8eZdZdddZdddZddZd d Zd d Zd S)IncrementalEncoderrcCstj||d|_dSN)rr__init__firstselfr r r r rszIncrementalEncoder.__init__FcCs6|jr$d|_tjt||jdSt||jdSr)rrrrr )rrfinalr r r r s zIncrementalEncoder.encodecCstj|d|_dSr)rrresetrrr r r r's zIncrementalEncoder.resetcCs|jSNrrr r r getstate+szIncrementalEncoder.getstatecCs ||_dSrrrstater r r setstate.szIncrementalEncoder.setstateN)r)F)__name__ __module__ __qualname__rr rrr"r r r r rs   rc@s6eZdZd ddZddZddZdd Zd d Zd S)IncrementalDecoderrcCstj||d|_dSr)rBufferedIncrementalDecoderrrrr r r r2szIncrementalDecoder.__init__cCsv|jrht|dkr*tj|r"dSd|_n>d|_|ddtjkrht|dd||\}}||dfSt|||S)Nr rr)rrrr startswithr)rrr rrrr r r _buffer_decode6s   z!IncrementalDecoder._buffer_decodecCstj|d|_dSr)rr'rrrr r r rGs zIncrementalDecoder.resetcCstj|}|d|jfSr)rr'rrr r r r rKs zIncrementalDecoder.getstatecCstj|||d|_dSr)rr'r"rr r r r r"PszIncrementalDecoder.setstateN)r)r#r$r%rr+rrr"r r r r r&1s  r&c@seZdZddZdddZdS) StreamWritercCs,tj|z|`Wnty&Yn0dSr)rr,rr AttributeErrorrr r r rVs   zStreamWriter.resetrcCstj|_t||Sr)rrr )rrr r r r r ]szStreamWriter.encodeN)r)r#r$r%rr r r r r r,Usr,c@seZdZddZdddZdS) StreamReadercCs,tj|z|`Wnty&Yn0dSr)rr.rrr-rr r r rbs   zStreamReader.resetrcCsnt|dkrtj|rZdS|ddtjkrZtj|_t|dd|\}}||dfStj|_t||S)Nr r()rrrr*rr)rrr rrr r r ris   zStreamReader.decodeN)r)r#r$r%rrr r r r r.asr.c CstjdttttttdS)Nz utf-8-sig)namer rincrementalencoderincrementaldecoder streamreader streamwriter)r CodecInfor rrr&r.r,r r r r getregentryysr5)r)r) __doc__rr rrr'r&r,r.r5r r r r s   $