U
    h
                     @  s   U d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	m
Z
 d dlZd dlmZ e Zi Zded< daded< e d	d
ddZdd
ddZdddddZdd
ddZdS )    )annotationsN)AnyCallableOptionalSequence)Encodingzdict[str, Encoding]	ENCODINGSz1Optional[dict[str, Callable[[], dict[str, Any]]]]ENCODING_CONSTRUCTORSzSequence[str])returnc                  C  s6   g } t tjtjd }|D ]\}}}| | q| S )N.)pkgutiliter_modulestiktoken_ext__path____name__append)ZmodsZplugin_mods_mod_name r   5/tmp/pip-unpacked-wheel-taldhpgq/tiktoken/registry.py_available_plugin_modules   s
    r   Nonec                  C  s   t  td k	rW 5 Q R  d S i at D ]} t| }z
|j}W n4 tk
rr } ztd|  d|W 5 d }~X Y nX | D ],\}}|tkrtd| d|  |t|< q|q&W 5 Q R X d S )Nztiktoken plugin z& does not define ENCODING_CONSTRUCTORSzDuplicate encoding name z in tiktoken plugin )_lockr	   r   	importlibimport_moduleAttributeError
ValueErroritems)r   modconstructorseZenc_nameconstructorr   r   r   _find_constructors    s(    



r"   strr   )encoding_namer
   c              
   C  s   | t krt |  S t | t kr2t |  W  5 Q R  S td krLt  td k	sLt| tkrjtd|  dt  t|  }tf | }|t | < |W  5 Q R  S Q R X d S )NzUnknown encoding z. Plugins found: )r   r   r	   r"   AssertionErrorr   r   r   )r$   r!   encr   r   r   get_encoding7   s     r'   z	list[str]c                
   C  s>   t 0 td kr t  td k	s tttW  5 Q R  S Q R X d S )N)r   r	   r"   r%   listr   r   r   r   list_encoding_namesN   s
    r)   )
__future__r   	functoolsr   r   	threadingtypingr   r   r   r   r   Ztiktoken.corer   RLockr   r   __annotations__r	   	lru_cacher   r"   r'   r)   r   r   r   r   <module>   s     