
    ob
                         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
 ZddZd Zd Zy)z2Miscellaneous tools for operating on filesystems.
    )print_functionunicode_literalsN   )errors)DirectoryNotEmptyResourceNotFound)abspathdirnamenormpathrecursepath)IOListOptionalTextUnion)FSc                     t        t        |            }	 |dvr"| j                  |       t        |      }|dvr!yy# t        $ r Y yw xY 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paths     */usr/lib/python3/dist-packages/fs/tools.pyremove_emptyr      sR     8D>"D)#LL4=D )#  s   $= 	A	A	c                 ~    |dn|| j                   |j                  }t        fdd      D ]
  } ||        y)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                              xs d S N )_chunk_sizereads   r   <lambda>z copy_file_data.<locals>.<lambda>4   s    [!)T     )r    writeiter)src_filedst_file
chunk_sizer#   chunkr   r    s        @@r   copy_file_datar)   $   sE     ",!3+K==DNNE)4  	er"   c                 V   g }| j                         5  t        t        |      d      D ]6  }	 | j                  |      }|j                  r nt        j                  |       ddd       |ddd   dd S # t        $ r |j                  t        |             Y qw xY w# 1 sw Y   =xY w)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	   getinfois_dirr   DirectoryExpectedr   append)r   dir_pathintermediatesr   resources        r   get_intermediate_dirsr5   9   s      M	 	9 14@ 	9D9::d+ ??..x88	9	9 2s## $ 4$$WT]34		9 	9s-   BA6$B6#BBBBB(c                  &    t        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              3   \   K   | ]$  }|j                         j                  d d       & yw)thread_safeFN)getmetaget).0r   s     r   	<genexpr>z!is_thread_safe.<locals>.<genexpr>b   s#     L"rzz|u5Ls   *,)all)filesystemss    r   is_thread_safer?   W   s     LLLLr"   r   )__doc__
__future__r   r   typingr   r   r   r   r   r	   r
   r   r   TYPE_CHECKINGr   r   r   r   r   baser   r   r)   r5   r?   r   r"   r   <module>rE      sE    8   7 9 9	66$*$<Mr"   