f _%c@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)rrZprefixoutputconsumedr r r decodes  rc@s8eZdZdddZdddZddZd d Zd d Zd S)IncrementalEncoderrcCtj||d|_dSNi)rr__init__firstselfrr r r rzIncrementalEncoder.__init__FcCs6|jr$d|_tjt||jdSt||jdSr)rrrrr)rrfinalr r r r s zIncrementalEncoder.encodecCtj|d|_dSr)rrresetrrr r r r' zIncrementalEncoder.resetcCs|jSNrrr r r getstate+zIncrementalEncoder.getstatecCs ||_dSrrrZstater r r setstate.r!zIncrementalEncoder.setstateNr)F)__name__ __module__ __qualname__rr rr r#r r r r rs   rc@s6eZdZd ddZddZddZdd Zd d Zd S)IncrementalDecoderrcCrr)rBufferedIncrementalDecoderrrrr r r r2rzIncrementalDecoder.__init__cCsv|jrht|dkr*tj|r"dSd|_n>d|_|ddtjkrht|dd||\}}||dfSt|||S)Nr Zrr)rrrr startswithr )rrrrrrr r r _buffer_decode6s   z!IncrementalDecoder._buffer_decodecCrr)rr)rrrr r r rGrzIncrementalDecoder.resetcCstj|}|d|jfSr)rr)r rr"r r r r Ks zIncrementalDecoder.getstatecCstj|||d|_dSr)rr)r#rr"r r r r#PszIncrementalDecoder.setstateNr$)r%r&r'rr,rr r#r r r r r(1s  r(c@eZdZddZdddZdS) StreamWritercC,tj|z|`Wnty&Yn0dSr)rr.rr AttributeErrorrr r r rV   zStreamWriter.resetrcCstj|_t||Sr)rrr )rrrr r r r ]szStreamWriter.encodeNr$)r%r&r'rr r r r r r.Ur.c@r-) StreamReadercCr/r)rr3rrr0rr r r rbr1zStreamReader.resetrcCsnt|dkrtj|rZdS|ddtjkrZtj|_t|dd|\}}||dfStj|_t||S)Nr r*)rrrr+r r)rrrrrr r r ris   zStreamReader.decodeNr$)r%r&r'rrr r r r r3ar2r3c CstjdttttttdS)Nz utf-8-sig)Znamer rZincrementalencoderZincrementaldecoderZ streamreaderZ streamwriter)rZ CodecInfor rrr(r3r.r r r r getregentryysr4r$r$) Z__doc__rr rrr)r(r.r3r4r r r r Zs   $