o �J�hE �@s~ddlZddlZddlZddlZddlmZddlmZddlm Z e� d�Z Gdd�de�Z dd �Z  dd d �ZdS)�N)�MutableMapping)�cached_property)� url_to_fszfsspec.mappingc@s�eZdZdZd%dd�Zedd��Zdd �Zd&d d �Zd d�Z dd�Z dd�Z dd�Z d'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' FNcCs�||_|�|�|_|�t�|d��dd�|_|dur tttf}||_ ||_ ||_ |r7|j� |�s7|j� |�|rY|j� |�sGtd|�d���|j�|d�|j�|d�dSdS)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 rrrr�r�LC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\fsspec\mapping.py�__init__)s, �    ��zFSMap.__init__cCsddlm}||j|jd�S)z@dirfs instance that can be used with the same keys as the mapper�)� DirFileSystem)�pathr)Zimplementations.dirfsrr r)rrrrr�dirfsBs z FSMap.dirfscCs@t�d|j�z|j�|jd�|j�|j�WdSYdS)z0Remove all keys below root - empties out mappingzClear mapping at %sTN)�logger�infor rrr�rrrr�clearIs z FSMap.clear�raisec s��fdd�|D�}�dkr�nd}z�jj||d��t�t�r%|d�i�Wn�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|]}��|��qSr�� _key_to_str��.0�kr#rr� <listcomp>f�z"FSMap.getitems.<locals>.<listcomp>r%�return)�on_errorrNcs(i|]\}}|t|�j�rt�n|�qSr)� isinstancer�KeyError�r*r+�vr#rr� <dictcomp>ns��z"FSMap.getitems.<locals>.<dictcomp>cs0i|]\}}�dkst�|t�s|�|�qS)r.)r0� BaseException)r*�key�k2)r/�outrrr4rs �)r�catr0�bytesrr1�items�zip)r�keysr/Zkeys2Zoe�er)r/r8rr�getitemsRs"  ��� � �zFSMap.getitemscs&�fdd�|��D�}�j�|�dS)z�Set the values of multiple items in the store Parameters ---------- values_dict: dict(str, bytes) cs i|] \}}��|�t|��qSr)r(� maybe_convertr2r#rrr4s z"FSMap.setitems.<locals>.<dictcomp>N)r;r�pipe)r� values_dict�valuesrr#r�setitemsxszFSMap.setitemscs�j��fdd�|D��dS)z#Remove multiple keys from the storecr&rr'r)r#rrr,�r-z"FSMap.delitems.<locals>.<listcomp>N)rr)rr=rr#r�delitems�szFSMap.delitemscCsDt|t�st�dt�t|t�rt|�}t|�}|j�|���d�S)zGenerate full path for the keyzAfrom fsspec 2023.5 onward FSMap non-str keys will raise TypeError�/) r0�str�warnings�warn�DeprecationWarning�list�tupler �rstrip�rr6rrrr(�s � zFSMap._key_to_strcCs|t|j�d��d�S)zStrip path of to leave key nameNrF)�lenr �lstrip)r�srrr� _str_to_key�szFSMap._str_to_keycCsF|�|�}z |j�|�}W|S|jy"|dur|YSt|��w)z Retrieve dataN)r(rr9rr1)rr6�defaultr+�resultrrr� __getitem__�s ��zFSMap.__getitem__cCs.|�||�}z||=W|StyY|Sw)zPop data)rUr1)rr6rSrTrrr�pop�s  ��z FSMap.popcCs8|�|�}|jj|j�|�dd�|j�|t|��dS)zStore value in keyT)�exist_okN)r(r�mkdirs�_parent� pipe_filer@)rr6�valuerrr� __setitem__�s zFSMap.__setitem__cs�fdd��j��j�D�S)Nc3s�|]}��|�VqdS�N)rR)r*rr#rr� <genexpr>�s�z!FSMap.__iter__.<locals>.<genexpr>)r�findr r#rr#r�__iter__�szFSMap.__iter__cCst|j�|j��Sr])rOrr_r r#rrr�__len__�sz FSMap.__len__cCs$z |j�|�|��WdSt�)z Remove keyN)rrr(r1rNrrr� __delitem__�szFSMap.__delitem__cCs|�|�}|j�|�S)zDoes key exist in mapping?)r(r�isfile)rr6rrrr� __contains__�s  zFSMap.__contains__cCst|j|jdd|jffS)NF)rr rrr#rrr� __reduce__�szFSMap.__reduce__)FFN)r%r])�__name__� __module__� __qualname__�__doc__rrr r$r?rDrEr(rRrUrVr\r`rarbrdrerrrrr s&   &     rcCsFt|tj�s t|d�r!t|d�r|jjdvr|�d�}tt|��}|S)NZ __array__�dtypeZMmZint64)r0�array�hasattrrj�kind�viewr:� memoryview)r[rrrr@�s   r@�Fc Ks6t|fi|��\}}|dur|n|}t|||||d�S)a�Create key-value interface for given URL and options The URL will be of the form "protocol://location" and point to the root of the mapper required. All keys will be file-names below this location, and their values the contents of each key. Also accepts compound URLs like zip::s3://bucket/file.zip , see ``fsspec.open``. Parameters ---------- url: str Root URL of mapping check: bool Whether to attempt to read from the location before instantiation, to check that the mapping does exist create: bool Whether to make the directory corresponding to the root before instantiating missing_exceptions: None or tuple If given, these exception types will be regarded as missing keys and return KeyError when trying to read data. By default, you get (FileNotFoundError, IsADirectoryError, NotADirectoryError) alternate_root: None or str In cases of complex URLs, the parser may fail to pick the correct part for the mapper root, so this arg can override Returns ------- ``FSMap`` instance, the dict-like key-value store. N)r)rr) �urlrrrZalternate_root�kwargsr�urlpathr rrr� get_mapper�s'rt)rpFFNN)rk�loggingr rH�collections.abcr� functoolsr� fsspec.corer� getLoggerr!rr@rtrrrr�<module>s"    ; �
Memory