B
    d              
   @   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   g/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-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|}| }x|ry ||| j| jd}	||	7 }P W q |k
r }
 zB|||d |
j | j| j7 }||
\}}||7 }||d  }W d d }
~
X Y qX qW ||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 )N)r(   r   r   bytesUnicodeEncodeError)r   r!   r   r   r   r   r   $   s    zExtendCodec.encodec             C   s   |  tjtt||S )N)r(   r   r   strUnicodeDecodeError)r   r!   r   r   r   r   r   '   s    zExtendCodec.decodec             C   s   t |trTxt|jd |jd D ],}|j|j| }|| jkr"| j| |fS q"W nXt |trxLt|jd |j| j d D ],}|j|j| }|| j	kr|| j	| |fS q|W | j
|_|d S )N   )
isinstancer-   ranger   endobjectr   r+   r   r   r   encoding)r   r%   r1   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)r@   rA   rB   rC   rD   euc_kri   i   )r@            rC   rD   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}xD|D ]<}yt| W n tk
rx   wPY nX t| ||t| < P qPW t|  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_function]   s    
	

rT   )
__doc__r   rM   Codecr   chrrO   rP   rT   registerr   r   r   r   <module>   sB   3