o
    f%                     @   st   d Z ddlZdddZdddZG dd	 d	ejZG d
d dejZG dd dejZG dd dejZdd Z	dS )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.
    Nstrictc                 C   s   t jt | |d  t| fS Nr   )codecsBOM_UTF8utf_8_encodelen)inputerrors r
   */usr/lib/python3.10/encodings/utf_8_sig.pyencode   s   r   c                 C   sD   d}| d d t jkr| dd  } d}t | |d\}}||| fS )Nr      T)r   r   utf_8_decode)r   r	   prefixoutputconsumedr
   r
   r   decode   s   r   c                   @   s8   e Zd ZdddZdddZdd Zd	d
 Zdd ZdS )IncrementalEncoderr   c                 C      t j| | d| _d S N   )r   r   __init__firstselfr	   r
   r
   r   r         
zIncrementalEncoder.__init__Fc                 C   s6   | j rd| _ tjt|| jd  S t|| jd S r   )r   r   r   r   r	   )r   r   finalr
   r
   r   r      s   zIncrementalEncoder.encodec                 C      t j|  d| _d S r   )r   r   resetr   r   r
   r
   r   r   '      
zIncrementalEncoder.resetc                 C   s   | j S Nr   r   r
   r
   r   getstate+   s   zIncrementalEncoder.getstatec                 C   s
   || _ d S r!   r"   r   stater
   r
   r   setstate.   s   
zIncrementalEncoder.setstateNr   )F)__name__
__module____qualname__r   r   r   r#   r&   r
   r
   r
   r   r      s    

r   c                   @   s6   e Zd ZdddZdd Zdd Zdd	 Zd
d ZdS )IncrementalDecoderr   c                 C   r   r   )r   BufferedIncrementalDecoderr   r   r   r
   r
   r   r   2   r   zIncrementalDecoder.__init__c                 C   sv   | j r4t|dk rtj|rdS d| _ nd| _ |d d tjkr4t|dd  ||\}}||d fS t|||S )Nr    r   r   )r   r   r   r   
startswithr   )r   r   r	   r   r   r   r
   r
   r   _buffer_decode6   s   z!IncrementalDecoder._buffer_decodec                 C   r   r   )r   r,   r   r   r   r
   r
   r   r   G   r    zIncrementalDecoder.resetc                 C   s   t j| }|d | jfS r   )r   r,   r#   r   r$   r
   r
   r   r#   K   s   zIncrementalDecoder.getstatec                 C   s   t j| | |d | _d S r   )r   r,   r&   r   r$   r
   r
   r   r&   P   s   zIncrementalDecoder.setstateNr'   )r(   r)   r*   r   r0   r   r#   r&   r
   r
   r
   r   r+   1   s    
r+   c                   @      e Zd Zdd ZdddZdS )StreamWriterc                 C   ,   t j|  z| `W d S  ty   Y d S w r!   )r   r2   r   r   AttributeErrorr   r
   r
   r   r   V      
zStreamWriter.resetr   c                 C   s   t j| _t||S r!   )r   r   r   )r   r   r	   r
   r
   r   r   ]   s   
zStreamWriter.encodeNr'   )r(   r)   r*   r   r   r
   r
   r
   r   r2   U       r2   c                   @   r1   )StreamReaderc                 C   r3   r!   )r   r7   r   r   r4   r   r
   r
   r   r   b   r5   zStreamReader.resetr   c                 C   sp   t |dk rtj|rdS n|d d tjkr.tj| _t|dd  |\}}||d fS tj| _t||S )Nr   r-   )r   r   r   r/   r   r   )r   r   r	   r   r   r
   r
   r   r   i   s   zStreamReader.decodeNr'   )r(   r)   r*   r   r   r
   r
   r
   r   r7   a   r6   r7   c                	   C   s   t jdttttttdS )Nz	utf-8-sig)namer   r   incrementalencoderincrementaldecoderstreamreaderstreamwriter)r   	CodecInfor   r   r   r+   r7   r2   r
   r
   r
   r   getregentryy   s   r>   r'   )
__doc__r   r   r   r   r,   r+   r2   r7   r>   r
   r
   r
   r   <module>   s    	

$