U
    9%e,'                     @   sn   d dl Z d dlmZ d dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ G dd dZG d	d
 d
eZdS )    N)md5LocalFileSystem)AbstractCopyTests)AbstractGetTests)AbstractPutTestsc                   @   s   e Zd ZdZejdd Zejdd Zejdd Zejdd	 Z	ejd
d Z
ejdd Zejdd Zejdd Zejdd Zejdd Zdd Zdd Zdd Zdd ZdS )BaseAbstractFixturesz
    Abstract base class containing fixtures that are used by but never need to
    be overridden in derived filesystem-specific classes to run the abstract
    tests on such filesystems.
    c                 c   s&   |  |||}|V  |j|dd dS )z
        Scenario on remote filesystem that is used for many cp/get/put tests.

        Cleans up at the end of each test it which it is used.
        T	recursiveN_bulk_operations_scenario_0rmselffsfs_joinfs_pathsource r   ]/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/fsspec/tests/abstract/__init__.pyfs_bulk_operations_scenario_0   s    z2BaseAbstractFixtures.fs_bulk_operations_scenario_0c                 c   s&   |  |||}|V  |j|dd dS )z
        Scenario on remote filesystem that is used for glob edge cases cp/get/put tests.

        Cleans up at the end of each test it which it is used.
        Tr	   N_glob_edge_cases_filesr   r   r   r   r   fs_glob_edge_cases_files   s    z-BaseAbstractFixtures.fs_glob_edge_cases_filesc                 c   s&   |  |||}|V  |j|dd dS )z
        Scenario on remote filesystem that is used to check cp/get/put on directory
        and file with the same name prefixes.

        Cleans up at the end of each test it which it is used.
        Tr	   N#_dir_and_file_with_same_name_prefixr   r   r   r   r   %fs_dir_and_file_with_same_name_prefix)   s    z:BaseAbstractFixtures.fs_dir_and_file_with_same_name_prefixc                 c   s&   |  |||}|V  |j|dd dS )z
        Scenario on remote filesystem that is used to check cp/get/put files order
        when source and destination are lists.

        Cleans up at the end of each test it which it is used.
        Tr	   N_10_files_with_hashed_namesr   r   r   r   r   fs_10_files_with_hashed_names5   s    z2BaseAbstractFixtures.fs_10_files_with_hashed_namesc                 c   s,   ||d}|V  | |r(|j|dd dS )z
        Return name of remote directory that does not yet exist to copy into.

        Cleans up at the end of each test it which it is used.
        targetTr	   Nexistsr   )r   r   r   r   r    r   r   r   	fs_targetA   s    

zBaseAbstractFixtures.fs_targetc                 c   s&   |  |||}|V  |j|dd dS )z
        Scenario on local filesystem that is used for many cp/get/put tests.

        Cleans up at the end of each test it which it is used.
        Tr	   Nr   r   local_fs
local_join
local_pathr   r   r   r    local_bulk_operations_scenario_0M   s    z5BaseAbstractFixtures.local_bulk_operations_scenario_0c                 c   s&   |  |||}|V  |j|dd dS )z
        Scenario on local filesystem that is used for glob edge cases cp/get/put tests.

        Cleans up at the end of each test it which it is used.
        Tr	   Nr   r$   r   r   r   local_glob_edge_cases_filesX   s    z0BaseAbstractFixtures.local_glob_edge_cases_filesc                 c   s&   |  |||}|V  |j|dd dS )z
        Scenario on local filesystem that is used to check cp/get/put on directory
        and file with the same name prefixes.

        Cleans up at the end of each test it which it is used.
        Tr	   Nr   r$   r   r   r   (local_dir_and_file_with_same_name_prefixc   s    
  z=BaseAbstractFixtures.local_dir_and_file_with_same_name_prefixc                 c   s&   |  |||}|V  |j|dd dS )z
        Scenario on local filesystem that is used to check cp/get/put files order
        when source and destination are lists.

        Cleans up at the end of each test it which it is used.
        Tr	   Nr   r$   r   r   r    local_10_files_with_hashed_namess   s    z5BaseAbstractFixtures.local_10_files_with_hashed_namesc                 c   s,   ||d}|V  | |r(|j|dd dS )z
        Return name of local directory that does not yet exist to copy into.

        Cleans up at the end of each test it which it is used.
        r    Tr	   Nr!   )r   r%   r&   r'   r    r   r   r   local_target   s    

z!BaseAbstractFixtures.local_targetc                 C   s   ||d}| ||d | ||d tdD ]X}||d| }||d}|| | ||d | ||d | ||d	 q2|S )
uL  
        Scenario that is used for glob edge cases cp/get/put tests.
        Creates the following directory and file structure:

        📁 source
        ├── 📄 file1
        ├── 📄 file2
        ├── 📁 subdir0
        │   ├── 📄 subfile1
        │   ├── 📄 subfile2
        │   └── 📁 nesteddir
        │       └── 📄 nestedfile
        └── 📁 subdir1
            ├── 📄 subfile1
            ├── 📄 subfile2
            └── 📁 nesteddir
                └── 📄 nestedfile
        r   file1file2   subdir	nesteddirsubfile1subfile2
nestedfile)touchrangemakedirs)r   some_fs	some_join	some_pathr   Z
subdir_idxr0   r1   r   r   r   r      s    


z+BaseAbstractFixtures._glob_edge_cases_filesc                 C   s|   ||d}||d}||d}| | |||d |||d |||d |||d |||d |S )	u  
        Scenario that is used for many cp/get/put tests. Creates the following
        directory and file structure:

        📁 source
        ├── 📄 file1
        ├── 📄 file2
        └── 📁 subdir
            ├── 📄 subfile1
            ├── 📄 subfile2
            └── 📁 nesteddir
                └── 📄 nestedfile
        r   r0   r1   r-   r.   r2   r3   r4   r7   r5   )r   r8   r9   r:   r   r0   r1   r   r   r   r      s    



z0BaseAbstractFixtures._bulk_operations_scenario_0c                 C   sJ   ||d}||d}||d}||d}| | || || |S )u&  
        Scenario that is used to check cp/get/put on directory and file with
        the same name prefixes. Creates the following directory and file structure:

        📁 source
        ├── 📄 subdir.txt
        └── 📁 subdir
            └── 📄 subfile.txt
        r   r0   z
subdir.txtzsubfile.txtr;   )r   r8   r9   r:   r   r0   fileZsubfiler   r   r   r      s    







z8BaseAbstractFixtures._dir_and_file_with_same_name_prefixc                 C   sX   ||d}t dD ]@}tt|d }||| d}|j|| dd q|S )u   
        Scenario that is used to check cp/get/put files order when source and
        destination are lists. Creates the following directory and file structure:

        📁 source
        └── 📄 {hashed([0-9])}.txt
        r   
   zutf-8z.txt)pathvalue)r6   r   strencode	hexdigestpipe)r   r8   r9   r:   r   iZhashed_ir>   r   r   r   r      s    
z0BaseAbstractFixtures._10_files_with_hashed_namesN)__name__
__module____qualname____doc__pytestfixturer   r   r   r   r#   r(   r)   r*   r+   r,   r   r   r   r   r   r   r   r   r      s2   













!r   c                   @   s   e Zd ZdZejdd Zejdd Zejdd Zejdd	d
d Z	ejdd Z
ejdd Zejdd Zejdd ZdS )AbstractFixturesa}  
    Abstract base class containing fixtures that may be overridden in derived
    filesystem-specific classes to run the abstract tests on such filesystems.

    For any particular filesystem some of these fixtures must be overridden,
    such as ``fs`` and ``fs_path``, and others may be overridden if the
    default functions here are not appropriate, such as ``fs_join``.
    c                 C   s   t dd S Nz3This function must be overridden in derived classesNotImplementedErrorr   r   r   r   r      s    zAbstractFixtures.fsc                 C   s   t jjS )z
        Return a function that joins its arguments together into a path.

        Most fsspec implementations join paths in a platform-dependent way,
        but some will override this to always use a forward slash.
        osr>   joinrO   r   r   r   r      s    zAbstractFixtures.fs_joinc                 C   s   t dd S rL   rM   rO   r   r   r   r      s    zAbstractFixtures.fs_pathclass)scopec                 C   s
   t ddS )NT)Z
auto_mkdirr   rO   r   r   r   r%     s    zAbstractFixtures.local_fsc                 C   s   t jjS )zs
        Return a function that joins its arguments together into a path, on
        the local filesystem.
        rP   rO   r   r   r   r&   
  s    zAbstractFixtures.local_joinc                 C   s   |S Nr   )r   Ztmpdirr   r   r   r'     s    zAbstractFixtures.local_pathc                 C   s   dS )zP
        Return whether this implementation supports empty directories.
        Tr   rO   r   r   r   supports_empty_directories  s    z+AbstractFixtures.supports_empty_directoriesc                 C   s   dd S )Nc                 S   s   | S rU   r   )xr   r   r   <lambda>      z3AbstractFixtures.fs_sanitize_path.<locals>.<lambda>r   rO   r   r   r   fs_sanitize_path  s    z!AbstractFixtures.fs_sanitize_pathN)rE   rF   rG   rH   rI   rJ   r   r   r   r%   r&   r'   rV   rZ   r   r   r   r   rK      s"   	

	





rK   )rQ   hashlibr   rI   Zfsspec.implementations.localr   Zfsspec.tests.abstract.copyr   Zfsspec.tests.abstract.getr   Zfsspec.tests.abstract.putr   r   rK   r   r   r   r   <module>   s    ]