o
    pf                     @   s   d Z ddlmZmZmZ ddlZddlZddlZddlZddl	Z	ddl
m
Z
 ddlmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ejrgddlmZmZmZmZmZ ddlmZ eeeeeeef Ze	jddfddZ 			dddZ!dS )zFunctions to compress the contents of a filesystem.

Currently zip and tar are supported, using the `zipfile` and
`tarfile` modules from the standard library.
    )absolute_importprint_functionunicode_literalsN)datetime   )ResourceType)MissingInfoNamespace	NoSysPath)relpath)datetime_to_epoch)Walker)BinaryIOOptionalTextTupleUnion)FSutf-8c                 C   s  t j|d|dd}|pt }| |j| g dd}|D ]\}}t|jr(|d n|}	tjs4|	|d}	|	drL|
dd	d
}
t|
}|dd }n|jpRt }|j|j|j|j|j|jf}t |	|}z|jd
urt|jjd> |_W n	 ty~   Y nw |jr| jdO  _||d qz| |}W n ty   ||| | Y qw |||	 qW d
   d
S 1 sw   Y  d
S )a  Write the contents of a filesystem to a zip file.

    Arguments:
        src_fs (~fs.base.FS): The source filesystem to compress.
        file (str or io.IOBase): Destination file, may be a file name
            or an open file object.
        compression (int): Compression to use (one of the constants
            defined in the `zipfile` module in the stdlib). Defaults
            to `zipfile.ZIP_DEFLATED`.
        encoding (str): The encoding to use for filenames. The default
            is ``"utf-8"``, use ``"CP437"`` if compatibility with WinZip
            is desired.
        walker (~fs.walk.Walker, optional): A `Walker` instance, or `None`
            to use default walker. You can use this to specify which files
            you want to compress.

    wT)modecompression
allowZip64detailsstataccess
namespaces/replacer   st_mtimeNr             ) zipfileZipFiler   infor
   is_dirsixPY3encodehas_namespacegettime	localtimemodifiedr   utcnowyearmonthdayhourminutesecondZipInfopermissionsr   external_attrr   writestr
getsyspathr	   	readbyteswrite)src_fsfiler   encodingwalker_zipgen_walkpathr&   zip_namer    _mtimezip_timemtzip_infosys_path rK   D/home/ertert/spirit/venv/lib/python3.10/site-packages/fs/compress.py	write_zip   sB   



"rM   c                 C   s  t jtjt jtjt jtjt jtj	t j
tjt jtjt jtjt jtji}g d}d|p+d}t|tjtjfr>tj||d}ntj||d}t }	|pMt }| |j| g dd}
|
D ]\}}t|}tjsm||d}t|}|d	r|d	d
|	}n|j p|	}t|t!rt"|}t|t#rt$|}||_%|D ]\}}t&||ddurt'||t&||d q|drt&|j(dd|_)|j*rtj|_+|,| q\||j+tj|_+|j-|_-| .|}|,|| W d   n1 sw   Y  q\W d   dS 1 sw   Y  dS )a  Write the contents of a filesystem to a tar file.

    Arguments:
        src_fs (~fs.base.FS): The source filesystem to compress.
        file (str or io.IOBase): Destination file, may be a file
            name or an open file object.
        compression (str, optional): Compression to use, or `None`
            for a plain Tar archive without compression.
        encoding(str): The encoding to use for filenames. The
            default is ``"utf-8"``.
        walker (~fs.walk.Walker, optional): A `Walker` instance, or
            `None` to use default walker. You can use this to specify
            which files you want to compress.

    ))uidrN   )gidrO   )unameuser)gnamegroupzw:{} )r   )fileobjr   r   r   r   r   r    Nr   r   i  )/r   block_special_filetarfileBLKTYPE	characterCHRTYPE	directoryDIRTYPEfifoFIFOTYPEr?   REGTYPEsocketAREGTYPEsymlinkSYMTYPEunknownformat
isinstancer(   	text_typebinary_typeopenr-   r   r&   r
   r)   r*   TarInfor+   r,   r/   r   r   floatintmtimegetattrsetattrr8   r   r'   typeaddfilesizeopenbin)r>   r?   r   r@   rA   type_maptar_attrr   _tarcurrent_timerC   rD   r&   tar_nametar_inform   tarattrinfoattrbin_filerK   rK   rL   	write_tark   s`   






$r}   )Nr   N)"__doc__
__future__r   r   r   typingr(   rW   r-   r$   r   enumsr   errorsr   r	   rD   r
   r   walkr   TYPE_CHECKINGr   r   r   r   r   baser   rl   ZipTimeZIP_DEFLATEDrM   r}   rK   rK   rK   rL   <module>   s2    
O