File: //proc/self/root/usr/local/lib/python3.10/dist-packages/tiktoken/__pycache__/load.cpython-310.pyc
o
;��g� � @ sn d dl mZ d dlZd dlZd dlZddd�Zd dd
�Zd!d"dd�Z d#d$dd�Zd%dd�Z d!d&dd�Z
dS )'� )�annotationsN�blobpath�str�return�bytesc
C s� | � d�s<| � d�s<zdd l}W n ty! } ztd�|�d }~ww |�| d��}|�� W d � S 1 s7w Y dd l}|�| �}|�� |jS )Nzhttp://zhttps://r �Oblobfile is not installed. Please install it by running `pip install blobfile`.�rb) �
startswith�blobfile�ImportError�BlobFile�read�requests�get�raise_for_status�content)r r
�e�fr �resp� r �8/usr/local/lib/python3.10/dist-packages/tiktoken/load.py� read_file s$ ���� �
r �data�
expected_hash�boolc C s t �| ��� }||kS �N)�hashlib�sha256� hexdigest)r r �actual_hashr r r �
check_hash s r �
str | Nonec C s� d}dt jv r
t jd }ndt jv rt jd }ndd l}t j�|�� d�}d}|dkr/t| �S t�| � � ��
� }t j�||�}t j�|�rzt|d��}|�
� }W d � n1 sYw Y |d u sgt||�ri|S zt �|� W n tyy Y nw t| �} |r�t| |�s�td | � d
|� d���dd l}
z6t j|dd� |d
t|
�� � d }t|d��
}|�| � W d � n1 s�w Y t �||� W | S ty� |rԂ Y | S w )NT�TIKTOKEN_CACHE_DIR�DATA_GYM_CACHE_DIRr zdata-gym-cacheF� r z'Hash mismatch for data downloaded from z (expected z<). This may indicate a corrupted download. Please try again.)�exist_ok�.z.tmp�wb)�os�environ�tempfile�path�join�
gettempdirr r �sha1�encoder �exists�openr
r �remove�OSError�
ValueError�uuid�makedirsr �uuid4�write�rename)r r �user_specified_cache� cache_dirr* � cache_key�
cache_pathr r �contentsr5 �tmp_filenamer r r �read_file_cached sV
�������r@ �vocab_bpe_file�encoder_json_file�vocab_bpe_hash�encoder_json_hash�dict[bytes, int]c s> dd� t d�D �}dd� |D �� d}t d�D ]}||vr-|�|� |� td| �<