
    )Vhd4                        d dl Z d dlZd dlZd dl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gZd Zd Zej"                  Z	 d Z G d	 d
      Z G d d      Z G d deeej,                        Z G d de      ZddZ G d d      Zy)    N   )text_encoding)
TranslatorPathc                 B    t        j                  t        |       dd      S )a2  
    Given a path with elements separated by
    posixpath.sep, generate all parents of that path.

    >>> list(_parents('b/d'))
    ['b']
    >>> list(_parents('/b/d/'))
    ['/b']
    >>> list(_parents('b/d/f/'))
    ['b/d', 'b']
    >>> list(_parents('b'))
    []
    >>> list(_parents(''))
    []
    r   N)	itertoolsislice	_ancestry)paths    P/home/dcms/DCMS/lib/python3.12/site-packages/setuptools/_vendor/zipp/__init__.py_parentsr      s      IdOQ55    c              #      K   | j                  t        j                        } | rH| t        j                  k7  r4|  t        j                  |       \  } }| r| t        j                  k7  r2yyyyw)aR  
    Given a path with elements separated by
    posixpath.sep, generate all elements of that path

    >>> list(_ancestry('b/d'))
    ['b/d', 'b']
    >>> list(_ancestry('/b/d/'))
    ['/b/d', '/b']
    >>> list(_ancestry('b/d/f/'))
    ['b/d/f', 'b/d', 'b']
    >>> list(_ancestry('b'))
    ['b']
    >>> list(_ancestry(''))
    []
    N)rstrip	posixpathsepsplit)r   tails     r   r
   r
   %   sV       ;;y}}%D
49==(
__T*
d 49==($($s   A&A-)A-c                 T    t        j                  t        |      j                  |       S )zZ
    Return items in minuend not in subtrahend, retaining order
    with O(1) lookup.
    )r   filterfalseset__contains__)minuend
subtrahends     r   _differencer   ?   s!    
   Z!=!=wGGr   c                   2     e Zd ZdZ fdZd Z fdZ xZS )InitializedStatez?
    Mix-in to save the initialization state for pickling.
    c                 @    || _         || _        t        |   |i | y N)_InitializedState__args_InitializedState__kwargssuper__init__)selfargskwargs	__class__s      r   r#   zInitializedState.__init__L   s#    $)&)r   c                 2    | j                   | j                  fS r   )r    r!   r$   s    r   __getstate__zInitializedState.__getstate__Q   s    {{DMM))r   c                 .    |\  }}t        |   |i | y r   )r"   r#   )r$   stater%   r&   r'   s       r   __setstate__zInitializedState.__setstate__T   s    f$)&)r   )__name__
__module____qualname____doc__r#   r*   r-   __classcell__r'   s   @r   r   r   G   s    *
** *r   r   c                   2     e Zd ZdZ fdZed        Z xZS )SanitizedNamesz7
    ZipFile mix-in to ensure names are sanitized.
    c                 Z    t        t        | j                  t        |                      S r   )listmap	_sanitizer"   namelistr$   r'   s    r   r:   zSanitizedNames.namelist^   s!    C(8(:;<<r   c                    d }t        j                  dd| t         j                        }|j                  dd      }|j	                  d      }dj                  t        ||            }|st        d      |d| j                  d      z  z   S )aa  
        Ensure a relative path with posix separators and no dot names.

        Modeled after
        https://github.com/python/cpython/blob/bcc1be39cb1d04ad9fc0bd1b9193d3972835a57c/Lib/zipfile/__init__.py#L1799-L1813
        but provides consistent cross-platform behavior.

        >>> san = SanitizedNames._sanitize
        >>> san('/foo/bar')
        'foo/bar'
        >>> san('//foo.txt')
        'foo.txt'
        >>> san('foo/.././bar.txt')
        'foo/bar.txt'
        >>> san('foo../.bar.txt')
        'foo../.bar.txt'
        >>> san('\\foo\\bar.txt')
        'foo/bar.txt'
        >>> san('D:\\foo.txt')
        'D/foo.txt'
        >>> san('\\\\server\\share\\file.txt')
        'server/share/file.txt'
        >>> san('\\\\?\\GLOBALROOT\\Volume3')
        '?/GLOBALROOT/Volume3'
        >>> san('\\\\.\\PhysicalDrive1\\root')
        'PhysicalDrive1/root'

        Retain any trailing slash.
        >>> san('abc/')
        'abc/'

        Raises a ValueError if the result is empty.
        >>> san('../..')
        Traceback (most recent call last):
        ...
        ValueError: Empty filename
        c                     | xr | dvS )N>   ... )parts    r   allowedz)SanitizedNames._sanitize.<locals>.allowed   s    3D33r   z	^([A-Z]):z\1)flags\/zEmpty filename)	resub
IGNORECASEreplacer   joinfilter
ValueErrorendswith)namerB   barecleanpartsjoineds         r   r9   zSanitizedNames._sanitizea   s}    P	4
 vvk5$bmmDT3'C &%01-..dmmC0000r   )r.   r/   r0   r1   r:   staticmethodr9   r2   r3   s   @r   r5   r5   Y   s!    = 21 21r   r5   c                        e Zd ZdZed        Z fdZd Zd Z fdZ	e
d        Ze
dej                  d	ej                  fd
       Z xZS )CompleteDirsa8  
    A ZipFile subclass that ensures that implied directories
    are always included in the namelist.

    >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt']))
    ['foo/', 'foo/bar/']
    >>> list(CompleteDirs._implied_dirs(['foo/bar.txt', 'foo/bar/baz.txt', 'foo/bar/']))
    ['foo/']
    c                     t         j                  j                  t        t        |             }d |D        }t        t        ||             S )Nc              3   B   K   | ]  }|t         j                  z     y wr   )r   r   ).0ps     r   	<genexpr>z-CompleteDirs._implied_dirs.<locals>.<genexpr>   s     61y}}$6s   )r   chainfrom_iterabler8   r   _deduper   )namesparentsas_dirss      r   _implied_dirszCompleteDirs._implied_dirs   s9    ////He0DE6g6{7E233r   c                 Z    t         |          }|t        | j                  |            z   S r   )r"   r:   r7   ra   )r$   r^   r'   s     r   r:   zCompleteDirs.namelist   s+     "tD..u5666r   c                 4    t        | j                               S r   )r   r:   r)   s    r   	_name_setzCompleteDirs._name_set   s    4==?##r   c                 L    | j                         }|dz   }||vxr ||v }|r|S |S )zx
        If the name represents a directory, return that name
        as a directory (with the trailing slash).
        rE   )rd   )r$   rN   r^   dirname	dir_matchs        r   resolve_dirzCompleteDirs.resolve_dir   s:    
  *%:'U*:	#w--r   c                     	 t         |   |      S # t        $ r= |j                  d      r|| j	                         vr t        j                  |      cY S w xY w)z6
        Supplement getinfo for implied dirs.
        rE   filename)r"   getinfoKeyErrorrM   rd   zipfileZipInfo)r$   rN   r'   s     r   rl   zCompleteDirs.getinfo   sR    	27?4(( 	2==%T^^5E)E??D11	2s    AAAc                     t        |t              r|S t        |t        j                        s | |      S d|j                  vrt        } | |_        |S )zl
        Given a source (filename or zipfile), return an
        appropriate CompleteDirs subclass.
        r)
isinstancerU   rn   ZipFilemoder'   )clssources     r   makezCompleteDirs.make   sK     fl+M&'//2v; fkk!Cr   zfreturnc                 r    | j                  |j                               D ]  }|j                  |d        |S )z
        Given a writable zip file zf, inject directory entries for
        any directories implied by the presence of children.
        r   )ra   r:   writestr)ru   rx   rN   s      r   injectzCompleteDirs.inject   s7     %%bkkm4 	#DKKc"	#	r   )r.   r/   r0   r1   rS   ra   r:   rd   rh   rl   classmethodrw   rn   rs   r|   r2   r3   s   @r   rU   rU      sn     4 4
7$.	2  $  GOO  r   rU   c                   ,     e Zd ZdZ fdZ fdZ xZS )
FastLookupzV
    ZipFile subclass to ensure implicit
    dirs exist and are resolved rapidly.
    c                     t        j                  t              5  | j                  cd d d        S # 1 sw Y   nxY wt        |          | _        | j                  S r   )
contextlibsuppressAttributeError_FastLookup__namesr"   r:   r;   s    r   r:   zFastLookup.namelist   sF      0 	 <<	  	  	 w')||   1:c                     t        j                  t              5  | j                  cd d d        S # 1 sw Y   nxY wt        |          | _        | j                  S r   )r   r   r   _FastLookup__lookupr"   rd   r;   s    r   rd   zFastLookup._name_set   sF      0 	!==	! 	! 	!)+}}r   )r.   r/   r0   r1   r:   rd   r2   r3   s   @r   r   r      s    
 r   r   c                 d    t         j                  j                  dk(  }d|z   }t        | |      ||fS )Npypy   )sysimplementationrN   r   )encodingr%   r&   is_pypystack_levels        r   _extract_text_encodingr      s5      %%/Gg+K;/v==r   c                       e Zd ZdZdZd dZd Zd Zd!dddZd	 Z	e
d
        Ze
d        Ze
d        Ze
d        Ze
d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZeZ e
d        Z!y)"r   u'  
    A :class:`importlib.resources.abc.Traversable` interface for zip files.

    Implements many of the features users enjoy from
    :class:`pathlib.Path`.

    Consider a zip file with this structure::

        .
        ├── a.txt
        └── b
            ├── c.txt
            └── d
                └── e.txt

    >>> data = io.BytesIO()
    >>> zf = zipfile.ZipFile(data, 'w')
    >>> zf.writestr('a.txt', 'content of a')
    >>> zf.writestr('b/c.txt', 'content of c')
    >>> zf.writestr('b/d/e.txt', 'content of e')
    >>> zf.filename = 'mem/abcde.zip'

    Path accepts the zipfile object itself or a filename

    >>> path = Path(zf)

    From there, several path operations are available.

    Directory iteration (including the zip file itself):

    >>> a, b = path.iterdir()
    >>> a
    Path('mem/abcde.zip', 'a.txt')
    >>> b
    Path('mem/abcde.zip', 'b/')

    name property:

    >>> b.name
    'b'

    join with divide operator:

    >>> c = b / 'c.txt'
    >>> c
    Path('mem/abcde.zip', 'b/c.txt')
    >>> c.name
    'c.txt'

    Read text:

    >>> c.read_text(encoding='utf-8')
    'content of c'

    existence:

    >>> c.exists()
    True
    >>> (b / 'missing.txt').exists()
    False

    Coercion to string:

    >>> import os
    >>> str(c).replace(os.sep, posixpath.sep)
    'mem/abcde.zip/b/c.txt'

    At the root, ``name``, ``filename``, and ``parent``
    resolve to the zipfile.

    >>> str(path)
    'mem/abcde.zip/'
    >>> path.name
    'abcde.zip'
    >>> path.filename == pathlib.Path('mem/abcde.zip')
    True
    >>> str(path.parent)
    'mem'

    If the zipfile has no filename, such ﻿attributes are not
    valid and accessing them will raise an Exception.

    >>> zf.filename = None
    >>> path.name
    Traceback (most recent call last):
    ...
    TypeError: ...

    >>> path.filename
    Traceback (most recent call last):
    ...
    TypeError: ...

    >>> path.parent
    Traceback (most recent call last):
    ...
    TypeError: ...

    # workaround python/cpython#106763
    >>> pass
    z>{self.__class__.__name__}({self.root.filename!r}, {self.at!r})c                 F    t         j                  |      | _        || _        y)aX  
        Construct a Path from a ZipFile or filename.

        Note: When the source is an existing ZipFile object,
        its type (__class__) will be mutated to a
        specialized type. If the caller wishes to retain the
        original type, the caller should either create a
        separate ZipFile object or pass a filename.
        N)r   rw   rootat)r$   r   r   s      r   r#   zPath.__init__e  s     OOD)	r   c                     | j                   |j                   urt        S | j                  | j                  f|j                  |j                  fk(  S )zU
        >>> Path(zipfile.ZipFile(io.BytesIO(), 'w')) == 'foo'
        False
        )r'   NotImplementedr   r   )r$   others     r   __eq__zPath.__eq__r  s?    
 >>0!!		477#

EHH'===r   c                 D    t        | j                  | j                  f      S r   )hashr   r   r)   s    r   __hash__zPath.__hash__{  s    TYY())r   Npwdc                N   | j                         rt        |       |d   }| j                         s|dk(  rt        |       | j                  j                  | j                  ||      }d|v r|s|rt        d      |S t        |i |\  }}}t        j                  ||g|i |S )z
        Open this entry as text or binary following the semantics
        of ``pathlib.Path.open()`` by passing arguments through
        to io.TextIOWrapper().
        r   rq   r   bz*encoding args invalid for binary operation)is_dirIsADirectoryErrorexistsFileNotFoundErrorr   openr   rL   r   ioTextIOWrapper)r$   rt   r   r%   r&   zip_modestreamr   s           r   r   z	Path.open~  s     ;;=#D))7{{}S#D))s;$;v !MNNM!7!H!H$B4B6BBr   c                 p    t        j                  | j                  xs | j                  j                        S r   )pathlibPurePosixPathr   r   rk   r)   s    r   _basez
Path._base  s&    $$TWW%B		0B0BCCr   c                 6    | j                         j                  S r   )r   rN   r)   s    r   rN   z	Path.name      zz|   r   c                 6    | j                         j                  S r   )r   suffixr)   s    r   r   zPath.suffix  s    zz|"""r   c                 6    | j                         j                  S r   )r   suffixesr)   s    r   r   zPath.suffixes  s    zz|$$$r   c                 6    | j                         j                  S r   )r   stemr)   s    r   r   z	Path.stem  r   r   c                     t        j                  | j                  j                        j	                  | j
                        S r   )r   r   r   rk   joinpathr   r)   s    r   rk   zPath.filename  s*    ||DII../88AAr   c                     t        |i |\  }}} | j                  d|g|i |5 }|j                         cd d d        S # 1 sw Y   y xY w)Nrq   )r   r   read)r$   r%   r&   r   strms        r   	read_textzPath.read_text  sR    !7!H!H$TYYsH6t6v6 	$99;	 	 	s   AA
c                 p    | j                  d      5 }|j                         cd d d        S # 1 sw Y   y xY w)Nrb)r   r   )r$   r   s     r   
read_byteszPath.read_bytes  s-    YYt_ 	99;	 	 	s   ,5c                     t        j                  |j                  j                  d            | j                  j                  d      k(  S NrE   )r   rf   r   r   )r$   r   s     r   	_is_childzPath._is_child  s2      !459LLLr   c                 :    | j                  | j                  |      S r   )r'   r   )r$   r   s     r   _nextz
Path._next  s    ~~dii,,r   c                 V    | j                    xs | j                   j                  d      S r   )r   rM   r)   s    r   r   zPath.is_dir  s"    77{3dgg..s33r   c                 H    | j                         xr | j                          S r   )r   r   r)   s    r   is_filezPath.is_file  s    {{}2T[[]!22r   c                 N    | j                   | j                  j                         v S r   )r   r   rd   r)   s    r   r   zPath.exists  s    ww$))--///r   c                     | j                         st        d      t        | j                  | j                  j                               }t        | j                  |      S )NzCan't listdir a file)r   rL   r8   r   r   r:   rK   r   )r$   subss     r   iterdirzPath.iterdir  sE    {{}3444::tyy1134dnnd++r   c                 ^    t        j                  | j                        j                  |      S r   )r   r   r   match)r$   path_patterns     r   r   z
Path.match  s"    $$TWW-33LAAr   c                     | j                   j                  | j                        }|j                  dz	  }t	        j
                  |      S )z8
        Return whether this path is a symlink.
           )r   rl   r   external_attrstatS_ISLNK)r$   infort   s      r   
is_symlinkzPath.is_symlink  s;     yy  )!!R'||D!!r   c                 T   |st        d|      t        j                  | j                        }t	        d      }t        j
                  ||j                  |      z         j                  }d | j                  j                  D        }t        | j                  t        ||            S )NzUnacceptable pattern: rE   )sepsc              3   4   K   | ]  }|j                     y wr   rj   )rX   datas     r   rZ   zPath.glob.<locals>.<genexpr>  s     >4>s   )rL   rF   escaper   r   compile	translate	fullmatchr   filelistr8   r   rK   )r$   patternprefixtrmatchesr^   s         r   globz	Path.glob  s    5g[ABB477#S!**Vbll7&;;<FF>499+=+=>4::vgu566r   c                 *    | j                  d|       S )Nz**/)r   )r$   r   s     r   rglobz
Path.rglob  s    yy3wi))r   c                 l    t        j                  t        |       t         |j                  |             S r   )r   relpathstrr   )r$   r   extras      r   relative_tozPath.relative_to  s)      TC0F,GHHr   c                 j    t        j                  | j                  j                  | j                        S r   )r   rJ   r   rk   r   r)   s    r   __str__zPath.__str__  s!    ~~dii00$''::r   c                 :    | j                   j                  |       S )Nr)   )_Path__reprformatr)   s    r   __repr__zPath.__repr__  s    {{!!t!,,r   c                     t        j                  | j                  g| }| j                  | j                  j                  |            S r   )r   rJ   r   r   r   rh   )r$   r   nexts      r   r   zPath.joinpath  s7    ~~dgg..zz$))//566r   c                     | j                   s| j                  j                  S t        j                  | j                   j                  d            }|r|dz  }| j                  |      S r   )r   rk   parentr   rf   r   r   )r$   	parent_ats     r   r   zPath.parent  sR    ww=='''%%dggnnS&9:	Izz)$$r   ) )rq   )"r.   r/   r0   r1   r   r#   r   r   r   r   propertyrN   r   r   r   rk   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __truediv__r   r@   r   r   r   r      s   dL NF>*C C(D ! ! # # % % ! ! B B
M-430,B"7*I;-7 K% %r   r   )r   r   rn   r   r   r   rF   r   r   compat.py310r   r   r   __all__r   r
   dictfromkeysr]   r   r   r5   rs   rU   r   r   r   r@   r   r   <module>r      s    	      	  
 '  (6&+, -- /H* *$;1 ;1|H#^W__ HV &>y% y%r   