o
    Êôj—   ã                   @   s~   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 e 
d¡ZG dd„ deƒZdd	„ Z	
				ddd„ZdS )é    N)ÚMutableMapping)Úcached_property)Ú	url_to_fszfsspec.mappingc                   @   sœ   e Zd ZdZd%dd„Zedd„ ƒZdd	„ Zd&dd„Zdd„ Z	dd„ Z
dd„ Zdd„ Zd'dd„Zd'dd„Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ ZdS )(Ú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 tttf}|| _	|| _
|| _|r7| j  |¡s7| j  |¡ |rY| j  |¡sGtd|› d�ƒ‚| j  |d ¡ | j  |d ¡ d S d S )NÚxéÿÿÿÿzPath 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   úa/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/fsspec/mapping.pyÚ__init__)   s,   ý
ÿùzFSMap.__init__c                 C   s   ddl m} || j| jd�S )z@dirfs instance that can be used with the same keys as the mapperé   )ÚDirFileSystem)Úpathr   )Zimplementations.dirfsr   r   r   )r   r   r   r   r   ÚdirfsB   s   zFSMap.dirfsc                 C   s@   t  d| j¡ z| j | jd¡ | j | j¡ W dS    Y dS )z0Remove all keys below root - empties out mappingzClear mapping at %sTN)ÚloggerÚinfor
   r   r   r   ©r   r   r   r   ÚclearI   s   zFSMap.clearÚraisec              
      sž   ‡fdd„|D ƒ}ˆ dkrˆ nd}zˆj j||d�‰tˆtƒr%|d ˆi‰W n ˆjy6 } zt|‚d}~ww ‡fdd	„ˆ ¡ D ƒ‰‡ ‡fd
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 | ]}ˆ   |¡‘qS r   ©Ú_key_to_str©Ú.0Úkr#   r   r   Ú
<listcomp>f   ó    z"FSMap.getitems.<locals>.<listcomp>r%   Úreturn)Úon_errorr   Nc                    s(   i | ]\}}|t |ˆ jƒrtƒ n|“qS r   )Ú
isinstancer   ÚKeyError©r*   r+   Úvr#   r   r   Ú
<dictcomp>n   s    ÿÿz"FSMap.getitems.<locals>.<dictcomp>c                    sH   i | ] \}}ˆ d kst ˆ| tƒs|ˆ dkrˆ| nˆ |t|ƒ¡“qS )r.   r%   )r0   ÚBaseExceptionÚgetr1   )r*   ÚkeyÚk2)r/   Úoutr   r   r4   r   s
     þ)r   Úcatr0   Úbytesr   r1   ÚitemsÚzip)r   Úkeysr/   Zkeys2ZoeÚer   )r/   r9   r   r   ÚgetitemsR   s"   
€€ÿ
þþzFSMap.getitemsc                    s&   ‡ fdd„|  ¡ D ƒ}ˆ j |¡ dS )zƒSet the values of multiple items in the store

        Parameters
        ----------
        values_dict: dict(str, bytes)
        c                    s    i | ]\}}ˆ   |¡t|ƒ“qS r   )r(   Úmaybe_convertr2   r#   r   r   r4      s     z"FSMap.setitems.<locals>.<dictcomp>N)r<   r   Úpipe)r   Zvalues_dictÚvaluesr   r#   r   Úsetitemsx   s   zFSMap.setitemsc                    s   ˆ j  ‡ fdd„|D ƒ¡ dS )z#Remove multiple keys from the storec                    r&   r   r'   r)   r#   r   r   r,   „   r-   z"FSMap.delitems.<locals>.<listcomp>N)r   r   )r   r>   r   r#   r   Údelitems‚   s   zFSMap.delitemsc                 C   sD   t |tƒst dt¡ t |tƒrt|ƒ}t|ƒ}| j› |› � d¡S )zGenerate full path for the keyzAfrom fsspec 2023.5 onward FSMap non-str keys will raise TypeErrorú/)	r0   ÚstrÚwarningsÚwarnÚDeprecationWarningÚlistÚtupler   Úrstrip)r   r7   r   r   r   r(   †   s   
þ
zFSMap._key_to_strc                 C   s   |t | jƒd…  d¡S )zStrip path of to leave key nameNrF   )Úlenr
   Úlstrip)r   Úsr   r   r   Ú_str_to_key“   s   zFSMap._str_to_keyc              
   C   sZ   |   |¡}z	| j |¡}W |S  | jy, } z|dur#|W  Y d}~S t|ƒ|‚d}~ww )zRetrieve dataN)r(   r   r:   r   r1   )r   r7   Údefaultr+   ÚresultÚexcr   r   r   Ú__getitem__—   s   
ü
€ýzFSMap.__getitem__c                 C   s.   |   ||¡}z| |= W |S  ty   Y |S w )zPop data)rU   r1   )r   r7   rR   rS   r   r   r   Úpop¢   s   þþz	FSMap.popc                 C   s8   |   |¡}| jj| j |¡dd� | j |t|ƒ¡ dS )zStore value in keyT)Úexist_okN)r(   r   ÚmkdirsÚ_parentÚ	pipe_filerA   )r   r7   Úvaluer   r   r   Ú__setitem__«   s   
zFSMap.__setitem__c                    s   ‡ fdd„ˆ j  ˆ j¡D ƒS )Nc                 3   s   � | ]}ˆ   |¡V  qd S ©N)rQ   )r*   r   r#   r   r   Ú	<genexpr>²   s   € z!FSMap.__iter__.<locals>.<genexpr>)r   Úfindr
   r#   r   r#   r   Ú__iter__±   s   zFSMap.__iter__c                 C   s   t | j | j¡ƒS r]   )rN   r   r_   r
   r#   r   r   r   Ú__len__´   s   zFSMap.__len__c              
   C   s8   z| j  |  |¡¡ W dS  ty } zt|‚d}~ww )z
Remove keyN)r   r   r(   Ú	Exceptionr1   )r   r7   rT   r   r   r   Ú__delitem__·   s   €ÿzFSMap.__delitem__c                 C   s   |   |¡}| j |¡S )zDoes key exist in mapping?)r(   r   Úisfile)r   r7   r   r   r   r   Ú__contains__¾   s   
zFSMap.__contains__c                 C   s   t | j| jdd| jffS )NF)r   r
   r   r   r#   r   r   r   Ú
__reduce__Ã   s   zFSMap.__reduce__)FFN)r%   r]   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r$   r@   rD   rE   r(   rQ   rU   rV   r\   r`   ra   rc   re   rf   r   r   r   r   r      s&    


	&


	r   c                 C   sF   t | tjƒst| dƒr!t| dƒr| jjdv r|  d¡} tt| ƒƒ} | S )NÚ	__array__ÚdtypeÚMmÚint64)r0   ÚarrayÚhasattrrl   ÚkindÚviewr;   Ú
memoryview)r[   r   r   r   rA   Ç   s
   
rA   Ú Fc           	      K   s6   t | fi |¤Ž\}}|dur|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   )r   r   )	Úurlr   r   r   Zalternate_rootÚkwargsr   Úurlpathr
   r   r   r   Ú
get_mapperÒ   s   'rx   )rt   FFNN)ro   Úloggingr   rH   Úcollections.abcr   Ú	functoolsr   Úfsspec.corer   Ú	getLoggerr!   r   rA   rx   r   r   r   r   Ú<module>   s"    
 ;û