
    :h                    D    d dl mZ d dlZd dlmZ d dlmZ  G d d      Zy)    )annotationsN)BytesIO)IOc                  @    e Zd ZdZdZdd	dZd
dZedd       ZddZ	y)GimpPaletteFilez'File handler for GIMP's palette format.RGBc                   |j                         j                  d      sd}t        |      g }d}	 |r|dk(  rn|dz  }|j                         }|snt        j                  d|      r8|rt        |      dkD  rd}t        |      |j                  d	
      t              d	k  rd}t        |      |fdt        d	      D        z  }|rt        |      dk(  rnt        |      | _
        y )Ns   GIMP Paletteznot a GIMP palette filer   i     s   \w+:|#d   zbad palette file   )maxsplitzbad palette entryc              3  :   K   | ]  }t        |           y wN)int).0ivs     Q/var/www/urcfiles/bundle/venv/lib/python3.12/site-packages/PIL/GimpPaletteFile.py	<genexpr>z(GimpPaletteFile._read.<locals>.<genexpr>8   s     48aAaD	8s   i   )readline
startswithSyntaxErrorrematchlensplit
ValueErrorrangebytespalette)selffplimitmsgr    r   sr   s          @r   _readzGimpPaletteFile._read   s    {{}''8+Cc""gFAA xx
A&Q#(!#&&#A1vz) o%45844GW,/ 2 W~    c                &    | j                  |       y r   )r&   )r!   r"   s     r   __init__zGimpPaletteFile.__init__>   s    

2r'   c                ^    | j                  |       }|j                  t        |      d       |S )NF)__new__r&   r   )clsdatar!   s      r   	frombyteszGimpPaletteFile.frombytesA   s'    {{3

74=%(r'   c                2    | j                   | j                  fS r   )r    rawmode)r!   s    r   
getpalettezGimpPaletteFile.getpaletteG   s    ||T\\))r'   N)T)r"   	IO[bytes]r#   boolreturnNone)r"   r2   r4   r5   )r-   r   r4   r   )r4   ztuple[bytes, str])
__name__
__module____qualname____doc__r0   r&   r)   classmethodr.   r1    r'   r   r   r      s.    1G &D  
*r'   r   )
__future__r   r   ior   typingr   r   r;   r'   r   <module>r?      s     # 	  1* 1*r'   