U
    <ºc  ã                   @   s:   d dl Z d dlmZmZ eeee f ZG dd„ dƒZdS )é    N)ÚIterableÚUnionc                   @   sv   e Zd ZdZdddœeeedœdd„Zdd	„ Zd
d„ Zee	dœdd„Z
edeedœdd„ƒZedeedœ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   ú</tmp/pip-unpacked-wheel-gikjz4vx/torch/package/glob_group.pyÚ__init__'   s    zGlobGroup.__init__c                 C   s   | j S ©N©r   ©r   r   r   r   Ú__str__/   s    zGlobGroup.__str__c                 C   s   | j S r   r   r   r   r   r   Ú__repr__2   s    zGlobGroup.__repr__)Ú	candidateÚreturnc                    s:   | j ˆ  ‰ t‡ fdd„| jD ƒƒo8t‡ fdd„| jD ƒƒS )Nc                 3   s   | ]}|  ˆ ¡V  qd S r   ©Ú	fullmatch©Ú.0Úp©r   r   r   Ú	<genexpr>7   s     z$GlobGroup.matches.<locals>.<genexpr>c                 3   s   | ]}|  ˆ ¡ V  qd S r   r   r   r   r   r   r   7   s    )r   Úanyr	   Úallr   )r   r   r   r   r   Úmatches5   s    
$ÿzGlobGroup.matches©Úelemsr   c                    s.   t | tƒrt | ˆ ¡gS ‡ fdd„| D ƒS d S )Nc                    s   g | ]}t  |ˆ ¡‘qS r   )r   Ú_glob_to_re)r   Úe©r   r   r   Ú
<listcomp>@   s     z(GlobGroup._glob_list.<locals>.<listcomp>)Ú
isinstanceÚstrr   r#   r!   r   r%   r   r   ;   s    
zGlobGroup._glob_list)Úpatternr   c                    s4   ‡fdd„‰ d  ‡ fdd„|  ˆ¡D ƒ¡}t |¡S )Nc                    sd   d| kr4| dkr*dt  ˆ ¡ d ˆ  d S tdƒ‚n,t  ˆ ¡dˆ  d  dd„ |  d	¡D ƒ¡ S 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   M   s    zAGlobGroup._glob_to_re.<locals>.component_to_re.<locals>.<genexpr>Ú*)r+   r,   Ú
ValueErrorÚjoinÚsplit)Ú	componentr%   r   r   Úcomponent_to_reF   s    
ÿz.GlobGroup._glob_to_re.<locals>.component_to_reÚ c                 3   s   | ]}ˆ |ƒV  qd S r   r   )r   Úc)r3   r   r   r   Q   s     z(GlobGroup._glob_to_re.<locals>.<genexpr>)r0   r1   r+   Úcompile)r)   r   Úresultr   )r3   r   r   r#   B   s    zGlobGroup._glob_to_reN)r   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚGlobPatternr(   r   r   r   Úboolr    Ústaticmethodr   r#   r   r   r   r   r      s     ÿ  ÿr   )r+   Útypingr   r   r(   r<   r   r   r   r   r   Ú<module>   s   