o
    a                  
   @   s   d Z ddlZddlZG dd dejZdedededed	ed
ededdfdeded	ed
ededdfded	ededed
ededdfdeded	ed
ededdfdZi Zdd Ze	e dS )zExtend the Python codecs module with a few encodings that are used in OpenType (name table)
but missing from Python.  See https://github.com/fonttools/fonttools/issues/236 for details.    Nc                   @   s8   e Zd Zdd Zdd ZdddZddd	Zd
d ZdS )ExtendCodecc                 C   sh   || _ || _|| _dd | D | _tdd | D | _tj	| j | j
| jd| _t|| j d S )Nc                 S   s   i | ]\}}||qS  r   ).0kvr   r   </usr/lib/python3/dist-packages/fontTools/encodings/codecs.py
<dictcomp>   s    z(ExtendCodec.__init__.<locals>.<dictcomp>c                 s   s    | ]}t |V  qd S N)len)r   r   r   r   r   	<genexpr>   s    z'ExtendCodec.__init__.<locals>.<genexpr>)nameencodedecode)r   base_encodingmappingitemsreversemaxvaluesmax_lencodecs	CodecInfor   r   inforegister_errorerror)selfr   r   r   r   r   r   __init__	   s   zExtendCodec.__init__c              
   C   s   t |}t|}| }|rTz||| j| jd}	||	7 }W ||fS  |yQ }
 z%|||d |
j | j| j7 }||
\}}||7 }||d  }W Y d }
~
nd }
~
ww |s||fS )N)errors)r   lookup_errorr
   r   r   start)r   ZmapperZoutput_typeexc_typeinputr   Zbase_error_handlerlengthoutparteZreplacementposr   r   r   _map   s$   
zExtendCodec._mapstrictc                 C      |  tjtt||S r	   )r'   r   r   bytesUnicodeEncodeErrorr   r!   r   r   r   r   r   $      zExtendCodec.encodec                 C   r)   r	   )r'   r   r   strUnicodeDecodeErrorr,   r   r   r   r   '   r-   zExtendCodec.decodec                 C   s   t |tr*t|jd |jd D ]}|j|j| }|| jv r(| j| |f  S qn,t |trVt|jd |j| j d D ]}|j|j| }|| j	v rU| j	| |f  S q=| j
|_|)N   )
isinstancer/   ranger   endobjectr   r+   r   r   r   encoding)r   r%   r3   sr   r   r   r   *   s   


 
zExtendCodec.errorN)r(   )__name__
__module____qualname__r   r'   r   r   r   r   r   r   r   r      s    	

r   	shift_jis|   ~   \         i"!  i&   )      ~               big5)rB   rC   rD   rE   rF   euc_kri   i   )rB            rE   rF   gb2312   )Zx_mac_japanese_ttxZx_mac_trad_chinese_ttxZx_mac_korean_ttxZx_mac_simp_chinese_ttxc              	   C   s   t | } | tv rH| tvrCt|  \}}| dd  dksJ | d d |g}|D ]}zt| W n	 ty9   Y q'w t| ||t| <  t|  jS d S )NZ_ttx)		encodingsnormalize_encoding_extended_encodings_cacher   lookupLookupErrorr   r   )r   r   r   Zbase_encodingsr   r   r   search_function]   s    
	
rU   )
__doc__r   rO   Codecr   chrrQ   rR   rU   registerr   r   r   r   <module>   sN    3	"