
    sg6                     D    d dl Z d dlmZmZ eeee   f   Z G d d      Zy)    N)IterableUnionc                       e Zd ZdZddddededefdZd	 Zd
 Zdede	fdZ
eddedefd       Zeddedefd       Zy)	GlobGroupa  A set of patterns that candidate strings will be matched against.

    A candidate is composed of a list of segments separated by ``separator``, e.g. "foo.bar.baz".

    A pattern contains one or more segments. Segments can be:
        - A literal string (e.g. "foo"), which matches exactly.
        - A string containing a wildcard (e.g. "torch*", or "foo*baz*"). The wildcard matches
          any string, including the empty string.
        - A double wildcard ("**"). This matches against zero or more complete segments.

    Examples:
        ``torch.**``: matches ``torch`` and all its submodules, e.g. ``torch.nn`` and ``torch.nn.functional``.
        ``torch.*``: matches ``torch.nn`` or ``torch.functional``, but not ``torch.nn.functional``.
        ``torch*.**``: matches ``torch``, ``torchvision``, and all their submodules.

    A candidates will match the ``GlobGroup`` if it matches any of the ``include`` patterns and
    none of the ``exclude`` patterns.

    Args:
        include (Union[str, Iterable[str]]): A string or list of strings,
            each representing a pattern to be matched against. A candidate
            will match if it matches *any* include pattern
        exclude (Union[str, Iterable[str]]): A string or list of strings,
            each representing a pattern to be matched against. A candidate
            will be excluded from matching if it matches *any* exclude pattern.
        separator (str): A string that delimits segments in candidates and
            patterns. By default this is "." which corresponds to how modules are
            named in Python. Another common value for this is "/", which is
            the Unix path separator.
     .)exclude	separatorincluder	   r
   c                    d| d| d| _         t        j                  ||      | _        t        j                  ||      | _        || _        y )NzGlobGroup(include=z
, exclude=))_dbgr   
_glob_listr   r	   r
   )selfr   r	   r
   s       K/var/www/html/venv/lib/python3.12/site-packages/torch/package/glob_group.py__init__zGlobGroup.__init__)   sI     )	G9AF	 ++GY? ++GY?"    c                     | j                   S Nr   r   s    r   __str__zGlobGroup.__str__1       yyr   c                     | j                   S r   r   r   s    r   __repr__zGlobGroup.__repr__4   r   r   	candidatereturnc                     | j                   z   t        fd| j                  D              xr t        fd| j                  D              S )Nc              3   @   K   | ]  }|j                          y wr   	fullmatch.0pr   s     r   	<genexpr>z$GlobGroup.matches.<locals>.<genexpr>9   s     @a1;;y)@s   c              3   B   K   | ]  }|j                           y wr   r    r"   s     r   r%   z$GlobGroup.matches.<locals>.<genexpr>9   s$      I
+,I&&I
s   )r
   anyr   allr	   )r   r   s    `r   matcheszGlobGroup.matches7   sH    NNY.	@4<<@@ 
S I
04I
 F
 	
r   elemsc                     t        | t              rt        j                  | |      gS | D cg c]  }t        j                  ||       c}S c c}w r   )
isinstancestrr   _glob_to_re)r*   r
   es      r   r   zGlobGroup._glob_list=   sC    eS!))%;<<AFGAI))!Y7GGGs   Apatternc                     fddj                  fd| j                        D              }t        j                  |      S )Nc                     d| v r1| dk(  r!dt        j                        z   dz   z   dz   S t        d      t        j                        dz   dz   j                  d | j	                  d      D              z   S )	Nz**(z[^z]+)*z,** can only appear as an entire path segmentz]*c              3   F   K   | ]  }t        j                  |        y wr   )reescape)r#   xs     r   r%   zAGlobGroup._glob_to_re.<locals>.component_to_re.<locals>.<genexpr>O   s      M%&BIIaLMs   !*)r5   r6   
ValueErrorjoinsplit)	componentr
   s    r   component_to_rez.GlobGroup._glob_to_re.<locals>.component_to_reH   s    y $9!55<yH6QQ$%STTyy+ti/?$/F.L.L M*3//#*>M /  r    c              3   .   K   | ]  } |        y wr   r   )r#   cr=   s     r   r%   z(GlobGroup._glob_to_re.<locals>.<genexpr>S   s     N+Ns   )r:   r;   r5   compile)r0   r
   resultr=   s    ` @r   r.   zGlobGroup._glob_to_reD   s6    		 NW]]95MNNzz&!!r   N)r   )__name__
__module____qualname____doc__GlobPatternr-   r   r   r   boolr)   staticmethodr   r.   r   r   r   r   r   	   s    @ ?ASV#"#0;#MP#
 
 
 H+ H# H H "S "S " "r   r   )r5   typingr   r   r-   rG   r   r   r   r   <module>rK      s,    	 " C#&'K" K"r   