o
    pf
                     @   s   d Z ddlmZmZ ddlZddlmZ ddlmZmZ ddl	m
Z
mZmZmZ ejr?ddlmZmZmZmZmZ dd	lmZ d
d ZdddZdd Zdd ZdS )z2Miscellaneous tools for operating on filesystems.
    )print_functionunicode_literalsN   )errors)DirectoryNotEmptyResourceNotFound)abspathdirnamenormpathrecursepath)IOListOptionalTextUnion)FSc                 C   sP   t t|}z|dvr| | t|}|dvsW dS W dS  ty'   Y dS w )zRemove all empty parents.

    Arguments:
        fs (FS): A filesystem instance.
        path (str): Path to a directory on the filesystem.

    ) /N)r   r
   	removedirr	   r   )fspath r   A/home/ertert/spirit/venv/lib/python3.10/site-packages/fs/tools.pyremove_empty   s   	
r   c                    sB   |du rdn| | j |j}t fdddD ]}|| qdS )a  Copy data from one file object to another.

    Arguments:
        src_file (io.IOBase): File open for reading.
        dst_file (io.IOBase): File open for writing.
        chunk_size (int): Number of bytes to copy at
            a time (or `None` to use sensible default).

    Ni   c                      s    pd S Nr   r   _chunk_sizereadr   r   <lambda>4   s    z copy_file_data.<locals>.<lambda>)r   writeiter)src_filedst_file
chunk_sizer   chunkr   r   r   copy_file_data$   s   
r%   c              
   C   s   g }|   4 tt|ddD ]#}z| |}W n ty(   |t| Y qw |jr. nt|W d   n1 s=w   Y  |ddd dd S )ak  Get a list of non-existing intermediate directories.

    Arguments:
        fs (FS): A filesystem instance.
        dir_path (str): A path to a new directory on the filesystem.

    Returns:
        list: A list of non-existing paths.

    Raises:
        ~fs.errors.DirectoryExpected: If a path component
            references a file and not a directory.

    T)reverseN)	lockr   r   getinfor   appendis_dirr   DirectoryExpected)r   dir_pathintermediatesr   resourcer   r   r   get_intermediate_dirs9   s   


r0   c                  G   s   t dd | D S )zCheck if all filesystems are thread-safe.

    Arguments:
        filesystems (FS): Filesystems instances to check.

    Returns:
        bool: if all filesystems are thread safe.

    c                 s   s     | ]}|  d dV  qdS )thread_safeFN)getmetaget).0r   r   r   r   	<genexpr>b   s    z!is_thread_safe.<locals>.<genexpr>)all)filesystemsr   r   r   is_thread_safeW   s   r8   r   )__doc__
__future__r   r   typingr   r   r   r   r   r   r	   r
   r   TYPE_CHECKINGr   r   r   r   r   baser   r   r%   r0   r8   r   r   r   r   <module>   s    
