� <��g� ���ddlZddlZddlZddlZddlmZddlmZddlm Z ej d��Z Gd�de��Z d�Z d d �ZdS) �N)�MutableMapping)�cached_property)� url_to_fszfsspec.mappingc��eZdZdZdd�Zed���Zd�Zdd�Zd �Z d �Z d �Z d �Z dd �Z dd�Zd�Zd�Zd�Zd�Zd�Zd�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�J�||_|�|��|_|�tj|d����dd�|_|�t ttf}||_ ||_ ||_ |r4|j� |��s|j� |��|ri|j� |��std|�d����|j�|dz��|j�|dz��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 r rrrs �^/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fsspec/mapping.py�__init__zFSMap.__init__)s2������&�&�t�,�,�� � "� 2� 2�9�>�$��3L�3L� M� M�c�r�c� R��� � %�!�!�"�"� � #5����� ��� � � $��7�>�>�$�'�'� $��� � �d�#�#�#� � $��7�>�>�$�'�'� � �9�D�9�9�9���� �G�M�M�$��+� &� &� &� �G�J�J�t�d�{� #� #� #� #� #� $� $�c�<�ddlm}||j|j���S)z@dirfs instance that can be used with the same keys as the mapper�)� DirFileSystem)�pathr )�implementations.dirfsr"rr )rr"s r�dirfsz FSMap.dirfsBs0�� 9�8�8�8�8�8��}�$�"7�D�G�D�D�D�Drc���t�d|j�� |j�|jd��|j�|j��dS#YdSxYw)z0Remove all keys below root - empties out mappingzClear mapping at %sTN)�logger�infor r rr�rs r�clearz FSMap.clearIsb��� � �)�4�9�5�5�5� � �G�J�J�t�y�$� '� '� '� �G�M�M�$�)� $� $� $� $� $�� � �D�D���s �?A#�#A(�raisec�`�����fd�|D��}�dkr�nd} �j�||����t�t��r |d�i�n#�j$r }t |�d}~wwxYw�fd�����D�����fd�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|]}��|����S��� _key_to_str��.0�krs �r� <listcomp>z"FSMap.getitems.<locals>.<listcomp>fs'���3�3�3���!�!�!�$�$�3�3�3rr+�return)�on_errorrNc�b��i|]+\}}|t|�j��rt��n|��,Sr.)� isinstancer�KeyError�r2r3�vrs �r� <dictcomp>z"FSMap.getitems.<locals>.<dictcomp>nsI��� � � ���1� �j��D�,C�D�D�K�� � � �!� � � rc ���i|]X\}}�dkst�|t���&|�dkr�|n"��|t|������YS)r5r+)r8� BaseException�getr9)r2�key�k2r6�outs ��rr<z"FSMap.getitems.<locals>.<dictcomp>rsm��� � � ���R��8�#�#�:�c�"�g�}�+M�+M�#� �H��/�/��R���S�W�W�R��"���5N�5N�#�#�#r)r �catr8�bytesrr9�items�zip)r�keysr6�keys2�oe�erBs` ` @r�getitemszFSMap.getitemsRs�����(4�3�3�3�d�3�3�3��!�W�,�,�X�X�(�� "��'�+�+�e�b�+�1�1�C��#�u�%�%� &��Q�x��o�����&� "� "� "��� !����� "���� � � � �� � � � � � � �� � � � � ��t�U�+�+� � � � s�;A� A0�#A+�+A0c�|���fd�|���D��}�j�|��dS)z�Set the values of multiple items in the store Parameters ---------- values_dict: dict(str, bytes) c�\��i|](\}}��|��t|����)Sr.)r0� maybe_convertr:s �rr<z"FSMap.setitems.<locals>.<dictcomp>s5���X�X�X�D�A�q�$�"�"�1�%�%�}�Q�'7�'7�X�X�XrN)rEr �pipe)r� values_dict�valuess` r�setitemszFSMap.setitemsxsE���Y�X�X�X�K�DU�DU�DW�DW�X�X�X�� �� � �V�����rc�T���j��fd�|D����dS)z#Remove multiple keys from the storec�:��g|]}��|����Sr.r/r1s �rr4z"FSMap.delitems.<locals>.<listcomp>�s'���6�6�6�A�D�$�$�Q�'�'�6�6�6rN)r r)rrGs` r�delitemszFSMap.delitems�s2��� �� � �6�6�6�6��6�6�6�7�7�7�7�7rc��t|t��sMtjdt��t|t ��rt |��}t|��}|j�|���d��S)zGenerate full path for the keyzAfrom fsspec 2023.5 onward FSMap non-str keys will raise TypeError�/) r8�str�warnings�warn�DeprecationWarning�list�tupler�rstrip)rr@s rr0zFSMap._key_to_str�sz���#�s�#�#� � �M�S�"� � � ��#�t�$�$� !��C�j�j���c�(�(�C��'�.��.�.�5�5�c�:�:�:rc�`�|t|j��d��d��S)zStrip path of to leave key nameNrW)�lenr �lstrip)r�ss r� _str_to_keyzFSMap._str_to_key�s)����T�Y���!�!�"�)�)�#�.�.�.rc��|�|��} |j�|��}n+#|j$r}|�|cYd}~St |��|�d}~wwxYw|S)z Retrieve dataN)r0r rCrr9)rr@�defaultr3�result�excs r� __getitem__zFSMap.__getitem__�sy�� � � �S� !� !�� )��W�[�[��^�^�F�F���&� )� )� )��"���������3�-�-�S� (����� )����� s�2� A�A�A�A�Ac�\�|�||��} ||=n#t$rYnwxYw|S)zPop data)rhr9)rr@rerfs r�popz FSMap.pop�sJ���!�!�#�w�/�/�� ��S� � ��� � � � �D� ����� s �� )�)c���|�|��}|j�|j�|��d���|j�|t |����dS)zStore value in keyT)�exist_okN)r0r �mkdirs�_parent� pipe_filerN)rr@�values r� __setitem__zFSMap.__setitem__�sa�����s�#�#�� ����t�w���s�+�+�d��;�;�;� ����#�}�U�3�3�4�4�4�4�4rc�Z���fd��j��j��D��S)Nc3�B�K�|]}��|��V��dS�N)rc)r2r rs �r� <genexpr>z!FSMap.__iter__.<locals>.<genexpr>�s1�����E�E��� � ��#�#�E�E�E�E�E�Er)r �findr r)s`r�__iter__zFSMap.__iter__�s-���E�E�E�E�T�W�\�\�$�)�-D�-D�E�E�E�Erc�Z�t|j�|j����Srt)r`r rvr r)s r�__len__z FSMap.__len__�s ���4�7�<�<�� �*�*�+�+�+rc�� |j�|�|����dS#t$r }t|�d}~wwxYw)z Remove keyN)r rr0� Exceptionr9)rr@rgs r� __delitem__zFSMap.__delitem__�sV�� $� �G�J�J�t�'�'��,�,� -� -� -� -� -��� $� $� $��� #����� $���s�-1� A�A�Ac�`�|�|��}|j�|��S)zDoes key exist in mapping?)r0r �isfile)rr@r#s r� __contains__zFSMap.__contains__�s)������$�$���w�~�~�d�#�#�#rc�<�t|j|jdd|jffS)NF)rr r rr)s r� __reduce__zFSMap.__reduce__�s���t�y�$�'�5�%��9P�Q�Q�Qr)FFN)r+rt)�__name__� __module__� __qualname__�__doc__rrr%r*rKrRrUr0rcrhrjrqrwryr|rr�r.rrrr s:��������6$�$�$�$�2�E�E��_�E� ���$ �$ �$ �$ �L���8�8�8� ;� ;� ;�/�/�/� � � � �����5�5�5� F�F�F�,�,�,�$�$�$�$�$�$� R�R�R�R�Rrrc���t|tj��st|d��rOt|d��r#|jjdvr|�d��}t t|����}|S)N� __array__�dtype�Mm�int64)r8�array�hasattrr��kind�viewrD� memoryview)rps rrNrN�su���%���%�%�)��� �)D�)D�)� �5�'� "� "� (�u�{�'7�4�'?�'?��J�J�w�'�'�E��j��'�'�(�(�� �Lr�Fc �V�t|fi|��\}}|�|n|}t|||||���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) �urlrrr�alternate_root�kwargsr �urlpathr s r� get_mapperr��sF��N�C�*�*�6�*�*�K�B��+�7�>�>�W�D� ��r�5�&�=O� P� P� P�Pr)r�FFNN)r��loggingrrY�collections.abcr� functoolsr� fsspec.corer� getLoggerr'rrNr�r.rr�<module>r�s��� � � � �������������*�*�*�*�*�*�%�%�%�%�%�%�!�!�!�!�!�!� �� �+� ,� ,��wR�wR�wR�wR�wR�N�wR�wR�wR�t��� � � ��� )Q�)Q�)Q�)Q�)Q�)Qr
Memory