
    Vi_                        S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
JrJr  / SQrSrSrSr \  S	 r " S
 S\5      r\R2                  \R4                  -  \R6                  -  r\" \S5      (       a  \\R<                  -  r\" \S5      (       a  \\R>                  -  r\r \" \S5      (       a  \ \RB                  -  r  SSK"r"S r#S r%S r&\RN                  S:X  aH  SSK(r(SSK(J)r)  SSK*J+r+J,r,  \(RZ                  R\                  R^                  r0\)\)\)\+\,\,/\0l1        S r2S%S jr3OS r2S%S jr3\3r4S\2l          " S S\5      r5S&S jr6S'S jr7\7r8 \9   " S S \95      r:\;S!:X  a4  \%" S"5       r<\<R{                  S#5        \<R{                  S$5        SSS5        gg! \ a
    \r\\4r GNsf = f! \$ a    S r# Nf = f! \ a    \r9 Nrf = f! , (       d  f       g= f)(zVirtually every Python programmer has used Python for wrangling
disk contents, and ``fileutils`` collects solutions to some of the
most commonly-found gaps in the standard library.
    )print_functionN)copy2copystatError)mkdir_patomic_saveAtomicSaver	FilePermsiter_find_filescopytreei  i     c                      [         R                  " U 5        g! [         aM  nUR                  [        R                  :X  a)  [         R
                  R                  U 5      (       a   SnAge SnAff = f)a  Creates a directory and any parent directories that may need to
be created along the way, without raising errors for any existing
directories. This function mimics the behavior of the ``mkdir -p``
command available in Linux/BSD environments, but also works on
Windows.
N)osmakedirsOSErrorerrnoEEXISTpathisdir)r   excs     d/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/boltons/fileutils.pyr   r   ?   sR    
D
 	  99$t)<)<s    
A0AA+*A++A0c                       \ rS rSrSr " S S\5      rSS jr\S 5       r	\S 5       r
S r\" S	S
5      r \" SS5      r \" SS5      r S rSrg)r
   O   a  The :class:`FilePerms` type is used to represent standard POSIX
filesystem permissions:

  * Read
  * Write
  * Execute

Across three classes of user:

  * Owning (u)ser
  * Owner's (g)roup
  * Any (o)ther user

This class assists with computing new permissions, as well as
working with numeric octal ``777``-style and ``rwx``-style
permissions. Currently it only considers the bottom 9 permission
bits; it does not support sticky bits or more advanced permission
systems.

Args:
    user (str): A string in the 'rwx' format, omitting characters
        for which owning user's permissions are not provided.
    group (str): A string in the 'rwx' format, omitting characters
        for which owning group permissions are not provided.
    other (str): A string in the 'rwx' format, omitting characters
        for which owning other/world permissions are not provided.

There are many ways to use :class:`FilePerms`:

>>> FilePerms(user='rwx', group='xrw', other='wxr')  # note character order
FilePerms(user='rwx', group='rwx', other='rwx')
>>> int(FilePerms('r', 'r', ''))
288
>>> oct(288)[-3:]  # XXX Py3k
'440'

See also the :meth:`FilePerms.from_int` and
:meth:`FilePerms.from_path` classmethods for useful alternative
ways to construct :class:`FilePerms` objects.
c                   P    \ rS rSrSr\" S5      rSSSS.rS rSS	 jr	S
 r
S rSrg)FilePerms._FilePermPropertyy   rwx         )rwxc                     Xl         X l        g N	attributeoffset)selfr'   r(   s      r   __init__$FilePerms._FilePermProperty.__init__~   s    &N K    Nc                 6    Uc  U $ [        XR                  5      $ r%   )getattrr'   )r)   fp_objtype_s      r   __get__#FilePerms._FilePermProperty.__get__   s    ~6>>22r,   c                   ^  [        UT R                  5      nX2:X  a  g  [        [        U5      5      T R                  -
  nU(       a!  [        SU< SU< ST R                  < 35      eU 4S jnSR                  [        [        U5      USS95      n[        UT R                  U5        T R                  X5        g ! [
         a    [        SU-  5      ef = f)	Nzexpected string, not %rzgot invalid chars z in permission specification z*, expected empty string or one or more of c                 "   > TR                   U    $ r%   )	_perm_val)cr)   s    r   <lambda>5FilePerms._FilePermProperty.__set__.<locals>.<lambda>   s    !2r,    T)keyreverse)r.   r'   setstr	_perm_set	TypeError
ValueError_perm_charsjoinsortedsetattr_update_integer)r)   r/   valuecurinvalid_charssort_key	new_values   `      r   __set__#FilePerms._FilePermProperty.__set__   s    &$..1C|C #CJ$.. @   %25$:J:J"L M M
 3Hs5z+3T!C DIFDNNI6  3  C 9E ABBCs   !B: :Cc                     SnSnU H+  nSUR                  U5      -  nX6U R                  S-  -  -  nM-     U=R                  U-  sl        g )Nr   xwrr      )indexr(   _integer)r)   r/   rF   moder:   symbolbits          r   rE   +FilePerms._FilePermProperty._update_integer   sN    DC399V,,q12   OOt#Or,   r&   r%   )__name__
__module____qualname____firstlineno__rA   	frozensetr>   r5   r*   r1   rK   rE   __static_attributes__ r,   r   _FilePermPropertyr   y   s1    e$	!!,		!	3
	4(	$r,   r]   c                 `    Su  U l         U l        U l        SU l        Xl        X l        X0l        g )Nr9   r9   r9   r   )_user_group_otherrQ   usergroupother)r)   rc   rd   re   s       r   r*   FilePerms.__init__   s*    /9,
DK	

r,   c                     U[         -  nSn/ nU(       a(  UR                  X![        -     5        US-  nU(       a  M(  UR                  5         U " U6 $ )zCreate a :class:`FilePerms` object from an integer.

>>> FilePerms.from_int(0o644)  # note the leading zero-oh for octal
FilePerms(user='rw', group='r', other='r')
)r9   r#   r"   xwr!   rxrwr   rO   )
FULL_PERMSappend_SINGLE_FULL_PERMr;   )clsir:   partss       r   from_intFilePerms.from_int   sT     	
Z:LL!2234!GA a 	E{r,   c                     [         R                  " U5      nU R                  [        R                  " UR                  5      5      $ )a/  Make a new :class:`FilePerms` object based on the permissions
assigned to the file or directory at *path*.

Args:
    path (str): Filesystem path of the target file.

Here's an example that holds true on most systems:

>>> import tempfile
>>> 'r' in FilePerms.from_path(tempfile.gettempdir()).user
True
)r   statrq   S_IMODEst_mode)rn   r   stat_ress      r   	from_pathFilePerms.from_path   s/     774=||DLL)9)9:;;r,   c                     U R                   $ r%   )rQ   r)   s    r   __int__FilePerms.__int__   s    }}r,   r`   r   ra   r    rb   r   c                     U R                   R                  nU< SU R                  < SU R                  < SU R                  < S3$ )Nz(user=z, group=z, other=))	__class__rV   rc   rd   re   )r)   cns     r   __repr__FilePerms.__repr__   s0    ^^$$tyy$**djj: 	;r,   )ra   rQ   rb   r`   rd   re   rc   Nr_   )rV   rW   rX   rY   __doc__objectr]   r*   classmethodrq   rx   r|   rc   rd   re   r   r[   r\   r,   r   r
   r
   O   s{    'R($F ($T   < <  Wa(D5h*E6h*E6;r,   r
   O_NOINHERIT
O_NOFOLLOWO_BINARYc                      [         R                   " U [         R                  S5      nU[         R                  -  n[         R                   " U [         R                  U5        g! [         a     gf = f)zDoes a best-effort :func:`fcntl.fcntl` call to set a fd to be
automatically closed by any future child processes.

Implementation from the :mod:`tempfile` module.
r   N)fcntlF_GETFD
FD_CLOEXECF_SETFDIOError)fdflagss     r   set_cloexecr      s_    	2KKEMM15E
 U%%%EKKEMM51  	
 		s   &A" "
A/.A/c                     g)z5Dummy set_cloexec for platforms without fcntl supportNr\   )r   s    r   r   r      s    r,   c                     [        U 40 UD6$ )av  A convenient interface to the :class:`AtomicSaver` type. Example:

>>> try:
...     with atomic_save("file.txt", text_mode=True) as fo:
...         _ = fo.write('bye')
...         1/0  # will error
...         fo.write('bye')
... except ZeroDivisionError:
...     pass  # at least our file.txt didn't get overwritten

See the :class:`AtomicSaver` documentation for details.
)r	   )	dest_pathkwargss     r   r   r      s     y+F++r,   c                     [        U [        5      (       a  U $ [        R                  " 5       =(       d    [        R                  " 5       nU R                  U5      $ r%   )
isinstanceunicodesysgetfilesystemencodinggetdefaultencodingdecode)r   encodings     r   path_to_unicoder     s?    $  ((*Fc.D.D.FH;;x  r,   nt)	c_wchar_p)DWORDLPVOIDc                 D    [         R                  " X5        g ! [         a)  nUR                  [        R                  :X  a   S nAO	e S nAff = f[        U 5      n [        U5      n[        [        U5      [        U 5      S SS S 5      nU(       d  [        SU< SU < 35      eg )Nr   zfailed to replace z with )	r   renameWindowsErrorr   r   r   _ReplaceFiler   r   )srcdstweress       r   replacer      s    		 IIc 	xx5<<'		 c"c"9S>9S>D$0CEFFs    
AAAAc                 V    U(       a  [        X5        g[        R                  " X5        gz<Rename *src* to *dst*, replacing *dst* if *overwrite is TrueN)r   r   r   r   r   	overwrites      r   atomic_renamer   5  s#    C 	 IIcr,   c                 .    [         R                  " X5      $ r%   )r   r   )r   r   s     r   r   r   >  s    yy""r,   c                     U(       a  [         R                  " X5        g[         R                  " X5        [         R                  " U 5        gr   )r   r   linkunlinkr   s      r   r   r   B  s2    IIc 	 GGCIIcNr,   a   Similar to :func:`os.replace` in Python 3.3+,
this function will atomically create or replace the file at path
*dst* with the file at path *src*.

On Windows, this function uses the ReplaceFile API for maximum
possible atomicity on a range of filesystems.
c                   :    \ rS rSrSr\rS rS rS r	S r
S rSrg	)
r	   iW  a|	  ``AtomicSaver`` is a configurable `context manager`_ that provides
a writable :class:`file` which will be moved into place as long as
no exceptions are raised within the context manager's block. These
"part files" are created in the same directory as the destination
path to ensure atomic move operations (i.e., no cross-filesystem
moves occur).

Args:
    dest_path (str): The path where the completed file will be
        written.
    overwrite (bool): Whether to overwrite the destination file if
        it exists at completion time. Defaults to ``True``.
    file_perms (int): Integer representation of file permissions
        for the newly-created file. Defaults are, when the
        destination path already exists, to copy the permissions
        from the previous file, or if the file did not exist, to
        respect the user's configured `umask`_, usually resulting
        in octal 0644 or 0664.
    text_mode (bool): Whether to open the destination file in text
        mode (i.e., ``'w'`` not ``'wb'``). Defaults to ``False`` (``wb``).
    part_file (str): Name of the temporary *part_file*. Defaults
        to *dest_path* + ``.part``. Note that this argument is
        just the filename, and not the full path of the part
        file. To guarantee atomic saves, part files are always
        created in the same directory as the destination path.
    overwrite_part (bool): Whether to overwrite the *part_file*,
        should it exist at setup time. Defaults to ``False``,
        which results in an :exc:`OSError` being raised on
        pre-existing part files. Be careful of setting this to
        ``True`` in situations when multiple threads or processes
        could be writing to the same part file.
    rm_part_on_exc (bool): Remove *part_file* on exception cases.
        Defaults to ``True``, but ``False`` can be useful for
        recovery in some cases. Note that resumption is not
        automatic and by default an :exc:`OSError` is raised if
        the *part_file* exists.

Practically, the AtomicSaver serves a few purposes:

  * Avoiding overwriting an existing, valid file with a partially
    written one.
  * Providing a reasonable guarantee that a part file only has one
    writer at a time.
  * Optional recovery of partial data in failure cases.

.. _context manager: https://docs.python.org/2/reference/compound_stmts.html#with
.. _umask: https://en.wikipedia.org/wiki/Umask

c                    Xl         UR                  SS5      U l        UR                  SS 5      U l        UR                  SS5      U l        UR                  SS 5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  S	S
5      U l        U(       a  [        SUR                  5       < 35      e[        R                  R                  U R                   5      U l         [        R                  R                  U R                   5      U l        U R
                  (       d  US-   U l        O9[        R                  R#                  U R                  U R
                  5      U l        U R                  (       a  SOSU l        U R                  (       a  [&        O[(        U l        S U l        g )Nr   T
file_permsoverwrite_partF	part_filerm_part_on_exc	text_mode	bufferingzunexpected kwargs: z.partzw+zw+b)r   popr   r   r   part_filenamer   r   r   r?   keysr   r   abspathdirnamedest_dir	part_pathrB   rR   _TEXT_OPENFLAGS_BIN_OPENFLAGS
open_flagsr   )r)   r   r   s      r   r*   AtomicSaver.__init__  s+   "K6 **\48$jj)95A#ZZT:$jj)94@K7K4v{{}FGG87!!&0DNWW\\$--9K9KLDN NND	-1^^/r,   c                 p   SnU R                   nUcA   [        R                  " U R                  5      n[        R                  " UR
                  5      n[        R                  " U R                  U R                  U5      n[        U5        [        R                  " X@R                  U R                  5      U l        U(       a#   [        R"                  " U R                  U5        g g ! [        [        4 a    U R                  nSn Nf = f! [        [        4 a    U R                   R%                  5         e f = f)NTF)r   r   rt   r   ru   rv   r   r   _default_file_permsopenr   r   r   fdopenrR   r   r   chmodclose)r)   do_chmodr   rw   r   s        r   _open_part_fileAtomicSaver._open_part_file  s    __
!774>>2!\\(*:*:;
 WWT^^T__jAB2yy$..A 4 	# W% !!55
 ! W% $$&s   A C% !D	 %DD	,D5c                    [         R                  R                  U R                  5      (       a6  U R                  (       d%  [        [        R                  SU R                  5      eU R                  (       aN  [         R                  R                  U R                  5      (       a   [         R                  " U R                  5        U R                  5         g)a  Called on context manager entry (the :keyword:`with` statement),
the ``setup()`` method creates the temporary file in the same
directory as the destination file.

``setup()`` tests for a writable directory with rename permissions
early, as the part file may not be written to immediately (not
using :func:`os.access` because of the potential issues of
effective vs. real privileges).

If the caller is not using the :class:`AtomicSaver` as a
context manager, this method should be called explicitly
before writing.
z*Overwrite disabled and file already existsN)r   r   lexistsr   r   r   r   r   r   r   r   r   r{   s    r   setupAtomicSaver.setup  s     77??4>>**>>ellJ"nn. . 277??4>>#B#BIIdnn%r,   c                 :    U R                  5         U R                  $ r%   )r   r   r{   s    r   	__enter__AtomicSaver.__enter__  s    

~~r,   c                    U R                   R                  5         U(       a4  U R                  (       a"   [        R                  " U R
                  5        g g  [        U R
                  U R                  U R                  S9  g ! [         a     g f = f! [         aE    U R                  (       a2   [        R                  " U R
                  5        e ! [         a     e f = fe f = f)N)r   )r   r   r   r   r   r   	Exceptionr   r   r   r   r)   exc_typeexc_valexc_tbs       r   __exit__AtomicSaver.__exit__  s    ""IIdnn- 		$..$..$(NN4 	 !   	""IIdnn-  ! 	sA    B )B 
BBC - CC 
CC CC )r   r   r   r   rR   r   r   r   r   r   r   r   r   N)rV   rW   rX   rY   r   RW_PERMSr   r*   r   r   r   r   r[   r\   r,   r   r	   r	   W  s)    0b #.60r,   r	   c           
   #     #    [        U[        5      (       a  U/n[        R                  " SR	                  U Vs/ s H  n[
        R                  " U5      PM     sn5      5      nU(       d  / nO[        U[        5      (       a  U/n[        R                  " SR	                  U Vs/ s H  n[
        R                  " U5      PM     sn5      5      n[        R                  " U 5       H  u  pxn	U(       ac  U H]  n
UR                  U
5      (       d  M  U(       a  UR                  U
5      (       a  M:  [        R                  R	                  Xz5      nUv   M_     U	 H]  n
UR                  U
5      (       d  M  U(       a  UR                  U
5      (       a  M:  [        R                  R	                  Xz5      nUv   M_     M     gs  snf s  snf 7f)a  Returns a generator that yields file paths under a *directory*,
matching *patterns* using `glob`_ syntax (e.g., ``*.txt``). Also
supports *ignored* patterns.

Args:
    directory (str): Path that serves as the root of the
        search. Yielded paths will include this as a prefix.
    patterns (str or list): A single pattern or list of
        glob-formatted patterns to find under *directory*.
    ignored (str or list): A single pattern or list of
        glob-formatted patterns to ignore.
    include_dirs (bool): Whether to include directories that match
       patterns, as well. Defaults to ``False``.

For example, finding Python files in the current directory:

>>> _CUR_DIR = os.path.dirname(os.path.abspath(__file__))
>>> filenames = sorted(iter_find_files(_CUR_DIR, '*.py'))
>>> os.path.basename(filenames[-1])
'urlutils.py'

Or, Python files while ignoring emacs lockfiles:

>>> filenames = iter_find_files(_CUR_DIR, '*.py', ignored='.#*')

.. _glob: https://en.wikipedia.org/wiki/Glob_%28programming%29

|N)r   
basestringrecompilerB   fnmatch	translater   walkmatchr   )	directorypatternsignoredinclude_dirsppats_reign_rerootdirsfilesbasenamefilenames               r   r   r     sO    : (J'':jj"JA7#4#4Q#7"JKLG	GZ	(	()ZZ!H1'"3"3A"6!HIJFWWY/E ==**6<<#9#9 !ww||D;H"N ! H}}X&&v||H5577<<7  0 - #K "Is,   8G	 F?AG	& GAG	AG	4AG	c           	         [         R                  " U 5      nUb	  U" X5      nO
[        5       n[        U5        / nU H  nXu;   a  M
  [         R                  R                  X5      n[         R                  R                  X5      n	 U(       aR  [         R                  R                  U5      (       a.  [         R                  " U5      n
[         R                  " X5        M  [         R                  R                  U5      (       a  [        XX#5        M  [        X5        M      [%        X5        U(       a  [        U5      eg! [         a*  nUR                  UR                  S   5         SnAGM1  SnAf[         a(  nUR!                  X[#        U5      45         SnAGMa  SnAff = f! [&         aG  n[(        b  [+        U[(        5      (       a   SnANUR!                  X[#        U5      45         SnANSnAff = f)a  The ``copy_tree`` function is an exact copy of the built-in
:func:`shutil.copytree`, with one key difference: it will not
raise an exception if part of the tree already exists. It achieves
this by using :func:`mkdir_p`.

As of Python 3.8, you may pass :func:`shutil.copytree` the
`dirs_exist_ok=True` flag to achieve the same effect.

Args:
    src (str): Path of the source directory to copy.
    dst (str): Destination path. Existing directories accepted.
    symlinks (bool): If ``True``, copy symlinks rather than their
        contents.
    ignore (callable): A callable that takes a path and directory
        listing, returning the files within the listing to be ignored.

For more details, check out :func:`shutil.copytree` and
:func:`shutil.copy2`.

Nr   )r   listdirr<   r   r   rB   islinkreadlinksymlinkr   r   r   r   extendargsEnvironmentErrorrl   r=   r   r   r   r   )r   r   symlinksignorenamesignored_nameserrorsnamesrcnamedstnamelinktoewhys                r   	copy_treer  (  so   * JJsOEs*CLF '',,s)'',,s)	8BGGNN733W-

6+w''8< g' (0 Fm   	%MM!&&)$$ 	8MM7SX677	8  0#
3(E(EMM3SX.//0sO   AD>0D>D> F% >
F"E--F":FF"%
G6/G1G11G6c                       \ rS rSrSS jrS rS rS rS rSS jr	SS	 jr
SS
 jrS rS rS rS rS rS rS rS rSrg)	DummyFileio  Nc                 p    Xl         X l        SU l        S U l        SU l        S U l        S U l        SU l        g )NFr   )r  rR   closedr  isattyr   newlines	softspace)r)   r   rR   r   s       r   r*   DummyFile.__init__r  s6    		r,   c                     SU l         g )NT)r  r{   s    r   r   DummyFile.close|  s	    r,   c                     g)Nr   r\   r{   s    r   filenoDummyFile.fileno  s    r,   c                 <    U R                   (       a  [        S5      eg NI/O operation on a closed filer  r@   r{   s    r   flushDummyFile.flush      ;;=>>r,   c                     [        5       er%   StopIterationr{   s    r   nextDummyFile.next  
    or,   c                 <    U R                   (       a  [        S5      egNr  r9   r  r)   sizes     r   readDummyFile.read      ;;=>>r,   c                 <    U R                   (       a  [        S5      egr'  r  r(  s     r   readlineDummyFile.readline  r,  r,   c                 >    U R                   (       a  [        S5      e/ $ r  r  r(  s     r   	readlinesDummyFile.readlines  s    ;;=>>	r,   c                 <    U R                   (       a  [        S5      eg r  r  r{   s    r   seekDummyFile.seek  r  r,   c                 <    U R                   (       a  [        S5      eg)Nr  r   r  r{   s    r   tellDummyFile.tell  s    ;;=>>r,   c                 <    U R                   (       a  [        S5      eg r  r  r{   s    r   truncateDummyFile.truncate  r  r,   c                 <    U R                   (       a  [        S5      eg r  r  )r)   strings     r   writeDummyFile.write  r  r,   c                 <    U R                   (       a  [        S5      eg r  r  )r)   list_of_stringss     r   
writelinesDummyFile.writelines  r  r,   c                     [        5       er%   r!  r{   s    r   __next__DummyFile.__next__  r%  r,   c                 <    U R                   (       a  [        S5      eg r  r  r{   s    r   r   DummyFile.__enter__  r  r,   c                     g r%   r\   r   s       r   r   DummyFile.__exit__  s    r,   )r  r   r  r  rR   r  r  r  )r!   N)r   )rV   rW   rX   rY   r*   r   r  r  r#  r*  r.  r1  r4  r7  r:  r>  rB  rE  r   r   r[   r\   r,   r   r  r  o  sR    









r,   r  __main__z/tmp/final.txtrofl
)F)NF)FN)>r   
__future__r   r   r   r   rt   r   r   shutilr   r   r   __all__rk   r   rm   r   	NameErrorr=   r   bytesr   r   r
   O_RDWRO_CREATO_EXCLr   hasattrr   r   r   r   r   r   ImportErrorr   r   r  ctypesr   ctypes.wintypesr   r   windllkernel32ReplaceFiler   argtypesr   r   _atomic_renamer	   r   r  r   filer  rV   fr>  r\   r,   r   <module>ra     s  B
 & 	 	 
    ) )* 
  J; J;^ ))bjj(2994
2}r~~%O
2|r}}$O 
2zbkk!N", ! 77d? -==))55L&	9"FF4L*# V& Vr5p:z L L^ z	%	&!		 
'	& I  GuJ`  @  Dj 
'	&sA   F F/ F> /#GF,+F,/	F;:F;>G	G	
G