o
    hQ                     @   sB   d dl Z d dlmZ d dlmZ eeee f ZG dd dZdS )    N)Iterable)Unionc                   @   s   e Zd ZdZddddededefdd	Zd
d Zdd Zdede	fddZ
eddedefddZeddedefddZdS )	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                C   s:   d| d| d| _ t||| _t||| _|| _d S )NzGlobGroup(include=z
, exclude=))_dbgr   
_glob_listr	   r   r   )selfr	   r   r   r   r   l/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/package/glob_group.py__init__*   s   
zGlobGroup.__init__c                 C      | j S Nr   r   r   r   r   __str__2      zGlobGroup.__str__c                 C   r   r   r   r   r   r   r   __repr__5   r   zGlobGroup.__repr__	candidatereturnc                    s:   | j    t fdd| jD ot fdd| jD S )Nc                 3   s    | ]}|  V  qd S r   	fullmatch.0pr   r   r   	<genexpr>:   s    z$GlobGroup.matches.<locals>.<genexpr>c                 3   s    | ]	}|   V  qd S r   r   r   r   r   r   r   :   s    
)r   anyr	   allr   )r   r   r   r   r   matches8   s   
$zGlobGroup.matcheselemsc                    s*   t | trt|  gS  fdd| D S )Nc                    s   g | ]}t | qS r   )r   _glob_to_re)r   er   r   r   
<listcomp>C   s    z(GlobGroup._glob_list.<locals>.<listcomp>)
isinstancestrr   r$   )r#   r   r   r&   r   r   >   s   
zGlobGroup._glob_listpatternc                    s4   fdd d  fdd| D }t|S )Nc                    s^   d| v r| dkrdt   d   d S tdt  d  d dd | d	D  S )
Nz**(z[^z]+)*z,** can only appear as an entire path segmentz]*c                 s   s    | ]}t |V  qd S r   )reescape)r   xr   r   r   r   P   s    

zAGlobGroup._glob_to_re.<locals>.component_to_re.<locals>.<genexpr>*)r,   r-   
ValueErrorjoinsplit)	componentr&   r   r   component_to_reI   s   
z.GlobGroup._glob_to_re.<locals>.component_to_re c                 3   s    | ]} |V  qd S r   r   )r   c)r4   r   r   r   T   s    z(GlobGroup._glob_to_re.<locals>.<genexpr>)r1   r2   r,   compile)r*   r   resultr   )r4   r   r   r$   E   s   
zGlobGroup._glob_to_reN)r   )__name__
__module____qualname____doc__GlobPatternr)   r   r   r   boolr"   staticmethodr   r$   r   r   r   r   r   
   s"     
r   )r,   collections.abcr   typingr   r)   r=   r   r   r   r   r   <module>   s
   