
    ob                        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*                  rd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Z 	 	 	 ddZ!y)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           	      >   t        j                  |d|d      }|xs
 t               }|5  |j                  | g d      }|D ]  \  }}t	        |j
                  r|dz   n|      }	t        j                  s|	j                  |d      }	|j                  d      r.|j                  dd	d
      }
t        j                  |
      }|dd }nf|j                  xs t        j                         }|j                   |j"                  |j$                  |j&                  |j(                  |j*                  f}t        j,                  |	|      }	 |j.                  |j.                  j0                  dz  |_        |j
                  r)|xj2                  dz  c_        |j7                  |d       `	 | j9                  |      }|j;                  ||	        	 d
d
d
       y
# t4        $ r Y qw xY w# t<        $ r% |j7                  || j?                  |             Y w xY w# 1 sw Y   y
xY w)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
getsyspathwriter
   	readbytes)src_fsfiler   encodingwalker_zipgen_walkpathr(   zip_namer"   _mtimezip_timemtzip_infosys_paths                   -/usr/lib/python3/dist-packages/fs/compress.py	write_ziprN      s   2 ??4c{tTDvxF	 .3;;v2O;P" ,	3JD$ T[[tczdCH77#??8Y?!!&)  88FJ=1!!A; ]]7hoo&7GGRXXrvvrww		299U x:H##/-1-=-=-B-Bb-HH* {{&&$.&h,3%006H JJx2Y,	3.3 .3: (  ! DMM(F,<,<T,BCDQ.3 .3sT   DH*G-5H#G"4H	GHGH"*HHHHHc                    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j#                  |xs d      }t%        |t&        j(                  t&        j*                  f      rt        j,                  ||      }nt        j,                  ||      }t/        j.                         }	|xs
 t1               }|5  |j3                  | g d      }
|
D ]  \  }}t5        |      }t&        j6                  s|j9                  |d      }t        j:                  |      }|j=                  d	      r|j?                  d	d
|	      }n|j@                  xs |	}t%        |tB              rtE        |      }t%        |tF              rtI        |      }||_%        |D ]+  \  }}tM        ||d      tO        ||tM        ||d             - |j=                  d      rtM        |jP                  dd      |_)        |jT                  r(t        j                  |_+        |jY                  |       L|j?                  |jV                  t        j                        |_+        |jZ                  |_-        | j]                  |      5 }|jY                  ||       ddd        	 ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)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.

    ))uidrP   )gidrQ   )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FIFOTYPErA   REGTYPEsocketAREGTYPEsymlinkSYMTYPEunknownformat
isinstancer*   	text_typebinary_typeopenr/   r   r(   r   r+   r,   TarInfor-   r.   r1   r   r   floatintmtimegetattrsetattrr:   r   r)   typeaddfilesizeopenbin)r@   rA   r   rB   rC   type_maptar_attrr   _tarcurrent_timerE   rF   r(   tar_nametar_inforo   tarattrinfoattrbin_files                      rM   	write_tarr   k   s   0 	''7++7??W--goog..	H WH==*+D$89||Dt,||Dt499;LvxF	 $5;;v2O;P" "	5JD$t}H77#??8Y?x0H!!&)\B5%*)%0%'E
"HN%- N!440<HgwtXt/LMN !!(+ '(8(8&% H{{ 'X& (TYY H $		^^D) 5XLL845 5C"	5$5 $5F5 5G$5 $5s,   	C(M32CM3>M&M3&M0+M33M<)Nr   N)"__doc__
__future__r   r   r   typingr*   rY   r/   r&   r   enumsr   errorsr	   r
   rF   r   r   walkr   TYPE_CHECKINGr   r   r   r   r   baser   rn   ZipTimeZIP_DEFLATEDrN   r    r%   rM   <module>r      s    I H  
      3  # 	==Cc3S01G $$I3^ P5r%   