o
�J�hE � @ s~ d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm Z e�
d�ZG dd� de�Zdd � Z
ddd
�ZdS )� N)�MutableMapping)�cached_property)� url_to_fszfsspec.mappingc @ s� e Zd ZdZd%dd�Zedd� �Zdd � Zd&dd�Zd
d� Z dd� Z
dd� Zdd� Zd'dd�Z
d'dd�Zdd� Zdd� Zdd� Zdd � Zd!d"� Zd#d$� ZdS )(�FSMapa� Wrap a FileSystem instance as a mutable wrapping.
The keys of the mapping become files under the given root, and the
values (which must be bytes) the contents of those files.
Parameters
----------
root: string
prefix for all the files
fs: FileSystem instance
check: bool (=True)
performs a touch at the location, to check for write access.
Examples
--------
>>> fs = FileSystem(**parameters) # doctest: +SKIP
>>> d = FSMap('my-data/path/', fs) # doctest: +SKIP
or, more likely
>>> d = fs.get_mapper('my-data/path/')
>>> d['loc1'] = b'Hello World' # doctest: +SKIP
>>> list(d.keys()) # doctest: +SKIP
['loc1']
>>> d['loc1'] # doctest: +SKIP
b'Hello World'
FNc C s� || _ |�|�| _|�t�|d��d d� | _|d u r tttf}|| _ || _
|| _|r7| j �|�s7| j �
|� |rY| j �|�sGtd|� d���| j �|d � | j �|d � d S d S )N�x�����zPath z9 does not exist. Create with the ``create=True`` keywordz/a)�fs�_strip_protocol�root� posixpath�join�_root_key_to_str�FileNotFoundError�IsADirectoryError�NotADirectoryError�missing_exceptions�check�create�exists�mkdir�
ValueError�touch�rm)�selfr
r r r r � r �LC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\fsspec\mapping.py�__init__) s, �
��zFSMap.__init__c C s ddl m} || j| jd�S )z@dirfs instance that can be used with the same keys as the mapper� )�
DirFileSystem)�pathr )Zimplementations.dirfsr r
r )r r r r r �dirfsB s zFSMap.dirfsc C s@ t �d| j� z| j�| jd� | j�| j� W dS Y dS )z0Remove all keys below root - empties out mappingzClear mapping at %sTN)�logger�infor
r r r �r r r r �clearI s zFSMap.clear�raisec
s� �fdd�|D �}� dkr� nd}z�j j||d��t�t�r%|d �i�W n �jy6 } zt|�d}~ww �fdd ���� D ��� �fd
d �t||�D �S )a� Fetch multiple items from the store
If the backend is async-able, this might proceed concurrently
Parameters
----------
keys: list(str)
They keys to be fetched
on_error : "raise", "omit", "return"
If raise, an underlying exception will be raised (converted to KeyError
if the type is in self.missing_exceptions); if omit, keys with exception
will simply not be included in the output; if "return", all keys are
included in the output, but the value will be bytes or an exception
instance.
Returns
-------
dict(key, bytes|exception)
c � g | ]}� � |��qS r ��_key_to_str��.0�kr# r r �
<listcomp>f � z"FSMap.getitems.<locals>.<listcomp>r% �return)�on_errorr Nc s( i | ]\}}|t |� j�rt� n|�qS r )�
isinstancer �KeyError�r* r+ �vr# r r �
<dictcomp>n s ��z"FSMap.getitems.<locals>.<dictcomp>c s0 i | ]\}}� d kst �| t�s|�| �qS )r. )r0 �
BaseException)r* �key�k2)r/ �outr r r4 r s
�)r �catr0 �bytesr r1 �items�zip)r �keysr/ Zkeys2Zoe�er )r/ r8 r r �getitemsR s"