a
    &gh                     @  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 }|  }|sFqtd|rTq"|rpt|dkrpd}t||jd	d
 t d	k rd}t|| fddtd	D 7 }|r"t|dkr"qq"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 c/mounts/lovelace/software/anaconda3/envs/metaDMG/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   