U
    i2e	                     @   s   d dl Z d dlZd dlmZmZ eeeeedf f Ze  fedddZ	ej
eeeef ddd	Zejedd
dZejedddZdS )    N)DictUnion	FilesSpec)specc                 C   s*   |   D ]\}}t|t||  qdS )aX  
    Build a set of files/directories, as described by the spec.

    Each key represents a pathname, and the value represents
    the content. Content may be a nested directory.

    >>> spec = {
    ...     'README.txt': "A README file",
    ...     "foo": {
    ...         "__init__.py": "",
    ...         "bar": {
    ...             "__init__.py": "",
    ...         },
    ...         "baz.py": "# Some code",
    ...     }
    ... }
    >>> target = getfixture('tmp_path')
    >>> build(spec, target)
    >>> target.joinpath('foo/baz.py').read_text(encoding='utf-8')
    '# Some code'
    N)itemscreatepathlibPath)r   prefixnamecontents r   C/tmp/pip-unpacked-wheel-bn52x7jx/importlib_resources/tests/_path.pybuild   s    r   )contentc                 C   s   |j dd t| |d d S )NT)exist_ok)r
   )mkdirr   r   pathr   r   r   r   '   s    r   c                 C   s   | |  d S )N)write_bytesr   r   r   r   _-   s    r   c                 C   s   |j | dd d S )Nzutf-8)encoding)
write_textr   r   r   r   r   2   s    )r   	functoolstypingr   r   strbytesr   r	   r   singledispatchr   registerr   r   r   r   r   <module>   s   