a
    ç´«j  ã                   @  s>   d dl mZ d dlZd dlmZ d dlmZ G dd„ dƒZdS )é    )ÚannotationsN)ÚBytesIO)ÚIOc                   @  sZ   e Zd ZdZdZdddddœdd	„Zddd
œdd„Zedd dœdd„ƒZddœdd„Z	dS )ÚGimpPaletteFilez'File handler for GIMP's palette format.ÚRGBTz	IO[bytes]ÚboolÚNone)ÚfpÚlimitÚreturnc                   sÐ   |  ¡  d¡sd}t|ƒ‚g }d}|r0|dkr0qÂ|d7 }|  ¡ }|sFqÂt d|¡rTq"|rpt|ƒdkrpd}t|ƒ‚|jd	d
�‰ tˆ ƒd	k r”d}t|ƒ‚|‡ fdd„td	ƒD ƒ7 }|r"t|ƒdkr"qÂq"t	|ƒ| _
d S )Ns   GIMP Paletteznot a GIMP palette filer   i  é   s   \w+:|#éd   zbad palette fileé   )Úmaxsplitzbad palette entryc                 3  s   | ]}t ˆ | ƒV  qd S ©N)Úint)Ú.0Úi©Úv© úR/var/www/html/laksyashrimp/venv/lib/python3.9/site-packages/PIL/GimpPaletteFile.pyÚ	<genexpr>8   ó    z(GimpPaletteFile._read.<locals>.<genexpr>i   )ÚreadlineÚ
startswithÚSyntaxErrorÚreÚmatchÚlenÚsplitÚ
ValueErrorÚrangeÚbytesÚpalette)Úselfr	   r
   Úmsgr$   r   Úsr   r   r   Ú_read   s0    zGimpPaletteFile._read)r	   r   c                 C  s   |   |¡ d S r   )r(   )r%   r	   r   r   r   Ú__init__>   s    zGimpPaletteFile.__init__r#   )Údatar   c                 C  s   |   | ¡}| t|ƒd¡ |S )NF)Ú__new__r(   r   )Úclsr*   r%   r   r   r   Ú	frombytesA   s    
zGimpPaletteFile.frombytesztuple[bytes, str])r   c                 C  s   | j | jfS r   )r$   Úrawmode)r%   r   r   r   Ú
getpaletteG   s    zGimpPaletteFile.getpaletteN)T)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r.   r(   r)   Úclassmethodr-   r/   r   r   r   r   r      s   "r   )Ú
__future__r   r   Úior   Útypingr   r   r   r   r   r   Ú<module>   s   