o
    Q `
                     @   s   d Z ddlm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
 dd
l	mZ ddl	mZ ddl	mZ ejrSd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
   Z	removedirr	   r   )fspath r   */usr/lib/python3/dist-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   Z_chunk_sizereadr   r   <lambda>8   s    z copy_file_data.<locals>.<lambda>)r   writeiter)Zsrc_fileZdst_fileZ
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   Zgetinfor   appendis_dirr   ZDirectoryExpected)r   Zdir_pathZintermediatesr   Zresourcer   r   r   get_intermediate_dirs=   s   


r&   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 )Zthread_safeFN)Zgetmetaget).0r   r   r   r   	<genexpr>f   s    z!is_thread_safe.<locals>.<genexpr>)all)Zfilesystemsr   r   r   is_thread_safe[   s   r+   r   )__doc__Z
__future__r   r   typingr   r   r   r   r   r   r	   r
   r   ZTYPE_CHECKINGr   r   r   r   r   baser   r   r    r&   r+   r   r   r   r   <module>   s$    
