U
    Dvfq                  
   @   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   >/tmp/pip-unpacked-wheel-qlge9rch/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|}| }|rz"||| j| jd}	||	7 }W qW q |k
r }
 zB|||d |
j | j| j7 }||
\}}||7 }||d  }W 5 d }
~
X Y qX q||fS )N)errors)r   lookup_errorr
   r   r   start)r   Zmapperoutput_typeexc_typeinputr   Zbase_error_handlerlengthoutpartereplacementposr   r   r   _map   s    
 zExtendCodec._mapstrictc                 C   s   |  tjtt||S r	   )r)   r   r   bytesUnicodeEncodeErrorr   r"   r   r   r   r   r   &   s    zExtendCodec.encodec                 C   s   |  tjtt||S r	   )r)   r   r   strUnicodeDecodeErrorr-   r   r   r   r   )   s    zExtendCodec.decodec                 C   s   t |trTt|jd |jd D ]0}|j|j| }|| jkr | j| |f  S q nXt |trt|jd |j| j d D ]0}|j|j| }|| j	krz| j	| |f  S qz| j
|_|d S )N   )
isinstancer/   ranger   endobjectr   r,   r   r   r   encoding)r   r&   r3   sr   r   r   r   ,   s    


 
zExtendCodec.errorN)r*   )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kr| tkrt|  \}}| dd  dks:t| d d |g}|D ]@}zt| W n tk
rx   Y qNY nX t| ||t| <  qqNt|  j	S d S )NZ_ttx)
	encodingsnormalize_encoding_extended_encodings_cacheAssertionErrorr   lookupLookupErrorr   r   )r   r   r   Zbase_encodingsr   r   r   search_functionl   s    
	

rV   )
__doc__r   rO   Codecr   chrrQ   rR   rV   registerr   r   r   r   <module>   sT   5.