
    wBf              
          d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ d
dlmZ d
dlmZmZ d
dlmZ d
dlmZ d
dlmZ d
dlmZ  d
dl!m"Z"m#Z#m$Z$m%Z% d
dl&m'Z'm(Z(m)Z) d
dl*m+Z+m,Z, ddl-m.Z. ddl/m0Z0m1Z1 	 ddl2m2Z2  ee5      Z6 G d de7      Z8 G d de8      Z9d Z:d Z;d Z<i Z=d  Z> G d! d"e      Z? G d# d$      Z@ G d% d&e@e?      ZA G d' d(eA      ZB G d) d*e@e?      ZC G d+ d,eC      ZD G d- d.e?      ZE G d/ d0e?      ZF G d1 d2eC      ZG G d3 d4eD      ZHeGeDe1eCe0eFeFeHeHd5	ZIy# e3$ r	 d
dl4m2Z2 Y w xY w)6zImplements the query language for conda packages (a.k.a, MatchSpec).

The MatchSpec is the conda package specification (e.g. `conda==23.3`, `python<3.7`,
`cryptography * *_0`) and is used to communicate the desired packages to install.
    N)ABCMetaabstractmethodabstractproperty)Mapping)reduce)chain)	getLogger)
attrgetter)basename   )memoizedproperty)CONDA_PACKAGE_EXTENSION_V1CONDA_PACKAGE_EXTENSION_V2)context)
isiterable)dashlist)groupby_to_dict)expandis_package_filestrip_pkg_extensionurl_to_path)is_urlpath_to_urlunquote)InvalidMatchSpecInvalidSpec   )Channel)BuildNumberMatchVersionSpec)
frozendictc                         e Zd Zd fd	Z xZS )MatchSpecTypec                    	 |rct        |t              r|s|S t        |t              r}t        |j                        }|j	                  d|j
                         |j	                  d|j                         |j                  |d<    |j                  di | t        | (  di |S t        |t              rJt        |      }|r.t        |fi |}t        |      ddhz
  r|j                  dd        t        | (  di |S t        |t              rt        |fi |}t        | (  di |S t!        |d      r |j#                         }|rt        |fi |S |S t%        d| d|       t        | (  di |S # t$        $ rK}d}|r|| z  }|r,|dd	j'                  d
 |j)                         D              z   z  }t+        ||      |d }~ww xY w)Noptionaltarget_original_spec_strto_match_speczInvalid MatchSpec:
  spec_arg=z

  kwargs=  , c              3   0   K   | ]  \  }}| d |   yw)=N ).0kvs      7lib/python3.12/site-packages/conda/models/match_spec.py	<genexpr>z)MatchSpecType.__call__.<locals>.<genexpr>Q   s     &Mda!AaSz&Ms   )detailsr.   )
isinstance	MatchSpecdict_match_components
setdefaultr%   r&   original_spec_strupdatesuper__call__str_parse_spec_strsetpopr   hasattrr(   r   joinitemsr   )	clsspec_argkwargs
new_kwargsparsedspecemsg	__class__s	           r2   r=   zMatchSpecType.__call__(   s   )	:h	26#O)4!%h&@&@!AJ))*h6G6GH))(HOOD7?7Q7QJ34%J%%// 7+9j99#.,X6F!%f!7!7v;*h)?? #JJ';TB 7+5f55'2!(5f5F 7+5f55X7#113D(888#%9(;vhW  w'1&11 	:C($sTYY&Mflln&MMMM"329	:s=   E8 BE8 'AE8 *E8 ,)E8 E8 E8 8	GAGGN)__name__
__module____qualname__r=   __classcell__rM   s   @r2   r#   r#   '   s    *: *:    r#   c                      e Zd ZdZdZ ee      Zi Zd%dZe	d        Z
d Zd Zd&dZed	        Z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ed        Z d Z!d Z"e#d        Z$ed        Z%ed        Z&ed        Z'ed         Z(ed!        Z)e	d'd"       Z*e	d#        Z+d'd$Z,y)(r6   a  The query language for conda packages.

    Any of the fields that comprise a :class:`PackageRecord` can be used to compose a
    :class:`MatchSpec`.

    :class:`MatchSpec` can be composed with keyword arguments, where keys are any of the
    attributes of :class:`PackageRecord`.  Values for keyword arguments are the exact values the
    attribute should match against.  Many fields can also be matched against non-exact values--by
    including wildcard `*` and `>`/`<` ranges--where supported.  Any non-specified field is
    the equivalent of a full wildcard match.

    :class:`MatchSpec` can also be composed using a single positional argument, with optional
    keyword arguments.  Keyword arguments also override any conflicting information provided in
    the positional argument.  The positional argument can be either an existing :class:`MatchSpec`
    instance or a string.  Conda has historically had several string representations for equivalent
    :class:`MatchSpec`s.  This :class:`MatchSpec` should accept any existing valid spec string, and
    correctly compose a :class:`MatchSpec` instance.

    A series of rules are now followed for creating the canonical string representation of a
    :class:`MatchSpec` instance.  The canonical string representation can generically be
    represented by

        (channel(/subdir):(namespace):)name(version(build))[key1=value1,key2=value2]

    where `()` indicate optional fields.  The rules for constructing a canonical string
    representation are:

    1. `name` (i.e. "package name") is required, but its value can be '*'.  Its position is always
       outside the key-value brackets.
    2. If `version` is an exact version, it goes outside the key-value brackets and is prepended
       by `==`. If `version` is a "fuzzy" value (e.g. `1.11.*`), it goes outside the key-value
       brackets with the `.*` left off and is prepended by `=`.  Otherwise `version` is included
       inside key-value brackets.
    3. If `version` is an exact version, and `build` is an exact value, `build` goes outside
       key-value brackets prepended by a `=`.  Otherwise, `build` goes inside key-value brackets.
       `build_string` is an alias for `build`.
    4. The `namespace` position is being held for a future conda feature.
    5. If `channel` is included and is an exact value, a `::` separator is ued between `channel`
       and `name`.  `channel` can either be a canonical channel name or a channel url.  In the
       canonical string representation, the canonical channel name will always be used.
    6. If `channel` is an exact value and `subdir` is an exact value, `subdir` is appended to
       `channel` with a `/` separator.  Otherwise, `subdir` is included in the key-value brackets.
    7. Key-value brackets can be delimited by comma, space, or comma+space.  Value can optionally
       be wrapped in single or double quotes, but must be wrapped if `value` contains a comma,
       space, or equal sign.  The canonical format uses comma delimiters and single quotes.
    8. When constructing a :class:`MatchSpec` instance from a string, any key-value pair given
       inside the key-value brackets overrides any matching parameter given outside the brackets.

    When :class:`MatchSpec` attribute values are simple strings, the are interpreted using the
    following conventions:

      - If the string begins with `^` and ends with `$`, it is converted to a regex.
      - If the string contains an asterisk (`*`), it is transformed from a glob to a regex.
      - Otherwise, an exact match to the string is sought.


    Examples:
        >>> str(MatchSpec(name='foo', build='py2*', channel='conda-forge'))
        'conda-forge::foo[build=py2*]'
        >>> str(MatchSpec('foo 1.0 py27_0'))
        'foo==1.0=py27_0'
        >>> str(MatchSpec('foo=1.0=py27_0'))
        'foo==1.0=py27_0'
        >>> str(MatchSpec('conda-forge::foo[version=1.0.*]'))
        'conda-forge::foo=1.0'
        >>> str(MatchSpec('conda-forge/linux-64::foo>=1.0'))
        "conda-forge/linux-64::foo[version='>=1.0']"
        >>> str(MatchSpec('*/linux-64::foo>=1.0'))
        "foo[subdir=linux-64,version='>=1.0']"

    To fully-specify a package with a full, exact spec, the fields
      - channel
      - subdir
      - name
      - version
      - build
    must be given as exact values.  In the future, the namespace field will be added to this list.
    Alternatively, an exact spec is given by '*[md5=12345678901234567890123456789012]'
    or '*[sha256=f453db4ffe2271ec492a2913af4e61d4a6c118201f07de757df0eff769b65d2e]'.
    )channelsubdirnameversionbuildbuild_numbertrack_featuresfeaturesurlmd5sha256licenselicense_familyfnNc                 |    || _         || _        |j                  dd       | _         | j                  di || _        y )Nr'   r.   )	_optional_targetrA   r'   _build_componentsr8   )selfr%   r&   rG   s       r2   __init__zMatchSpec.__init__   s<    !"(**-A4"H!7!7!7!A&!ArT   c                    i }|t        t               d  t        k(  r|d t        t                }n-|t        t               d  t        k(  r|d t        t                }d|v rV|j                  dd      \  }}d|v r8|j	                  dd      \  }}|t
        j                  vr|}d }||d<   |r||d<   n||d<   |j	                  dd      \  }}}|j                  |||d        | d	i |S )
Nz::r   /rV   rW   -r   rX   rY   rZ   r.   )lenr   r   splitrsplitr   known_subdirsr;   )	rE   dist_strpartschannel_subdir_strchannel_strrW   rX   rY   rZ   s	            r2   from_dist_strzMatchSpec.from_dist_str   s   S34467;UU B3'A#B"BCHs56689=WW B3'A#B"BCH8+3>>$+B(((&8&?&?Q&G#V!6!66"4K!F#.i &,E(O#5i 'sA6gu"	
 |U|rT   c                 X    | j                   j                  |      }|xr |j                  S rN   )r8   getexact_valuerh   
field_namer1   s      r2   get_exact_valuezMatchSpec.get_exact_value   s'    ""&&z2"Q]]"rT   c                 X    | j                   j                  |      }|xr |j                  S rN   )r8   rx   	raw_valuerz   s      r2   get_raw_valuezMatchSpec.get_raw_value   s'    ""&&z2 Q[[ rT   c                 0    | j                  |      }||S |S rN   )r   )rh   r{   defaultr1   s       r2   rx   zMatchSpec.get   s!    z*)w**rT   c                 t    t        | j                        dk(  xr d| j                  v xr | j                  dk7  S )Nr   rX   *)rn   r8   rX   rh   s    r2   is_name_only_speczMatchSpec.is_name_only_spec   s@     &&'1, !$000!		S 	
rT   c                 "    | j                         S rN   __str__r   s    r2   rr   zMatchSpec.dist_str       ||~rT   c                     | j                   S rN   )re   r   s    r2   r%   zMatchSpec.optional   s    ~~rT   c                     | j                   S rN   )rf   r   s    r2   r&   zMatchSpec.target   s    ||rT   c                     | j                   S rN   )r'   r   s    r2   r:   zMatchSpec.original_spec_str   s    &&&rT   c                     t        |t              rddlm} |j	                  |      }| j
                  j                         D ]  \  }}| j                  |||      r y y)z
        Accepts a `PackageRecord` or a dict, and matches can pull from any field
        in that record.  Returns True for a match, and False for no match.
        r   )PackageRecordFT)r5   r7   recordsr   from_objectsr8   rD   _match_individual)rh   recr   r{   r1   s        r2   matchzMatchSpec.match  s]    
 c4 .,,S1C!3399; 	MJ))#z1=	 rT   c                 f    t        ||      }	 |j                  |      S # t        $ r ||k(  cY S w xY wrN   )getattrr   AttributeError)rh   recordr{   match_componentvals        r2   r   zMatchSpec._match_individual  s>    fj)	*"((-- 	*"c))	*s    00c                 \    t        | j                        dk(  xr | j                  d      d uS )Nr   rX   )rn   r8   r|   r   s    r2   
_is_simplezMatchSpec._is_simple  s2    &&'1, 9$$V,D8	
rT   c                 2    t        | j                        dk(  S )Nr   )rn   r8   r   s    r2   
_is_singlezMatchSpec._is_single  s    4))*a//rT   c                       j                  d      }|r|S t         fddD              }t        d |D              s dj                  | t        z   S y )Nrc   c              3   @   K   | ]  }j                  |        y wrN   r|   )r/   xrh   s     r2   r3   z4MatchSpec._to_filename_do_not_use.<locals>.<genexpr>&  s     ST))!,Ss   rm   c              3   $   K   | ]  }|d u  
 y wrN   r.   )r/   r   s     r2   r3   z4MatchSpec._to_filename_do_not_use.<locals>.<genexpr>'  s     +19+   z{}-{}-{})r|   tupleanyformatr   )rh   fn_fieldvalss   `  r2   _to_filename_do_not_usez!MatchSpec._to_filename_do_not_use   sX     ''-OS6RSS+d++%J%%t,0JJJrT   c                    | j                   j                   d|  dg}| j                  r|j                  d| j                  z         | j                  r|j                  d       |j                  d       dj                  |      S )Nz(""z, target="%s"z, optional=True)r)   )rM   rO   r&   appendr%   rC   )rh   builders     r2   __repr__zMatchSpec.__repr__,  sm    nn--.ba89;;NN?T[[89==NN,-swwwrT   c                    	
 g }g }| j                   j                  d      }|r'|j                  r|j                  t	        |             n+|r)|j
                  s|j                  dt	        |      z         | j                   j                  d      }|r7|r!|j                  r|j                  d|z         n|j                  d|z         | j                   j                  dd      }|j                  |rdnd	|z         | j                   j                  d
      | j                   j                  d      	d}rt	              t        fddD              r|j                  dz         nd d dv r)	r|j                  dz         n|j                         n{dd  dk(  r|j                  dd d z          n[d   dk(  r|j                  dd d z          n;j                  d      r|j                         d}n|j                  dz          d}	rxt	        	      	t        	fddD              r|j                  d	z         nDd	v r|j                  d	z         n+|r|j                  d	z          n|j                  d	z         h d}d| j                   v rd| j                   v r|j                  d       | j                  D ]x  }||vs|| j                   v s|dk(  r|rt	        | j                   |         
t        
fddD              r|j                  | d 
 d!       c|j                  | d
        z |r#|j                  d"d#j                  |      z         d$j                  |      S )%NrV   z
channel=%srW   z/%sz	subdir=%srX   r   z::%s%srY   rZ   Fc              3   &   K   | ]  }|v  
 y wrN   r.   )r/   srY   s     r2   r3   z$MatchSpec.__str__.<locals>.<genexpr>N  s     2A1<2   z><$^|,zversion='%s'r   )z!=z~=.*r-   ==Tc              3   &   K   | ]  }|v  
 y wrN   r.   )r/   r   rZ   s     r2   r3   z$MatchSpec.__str__.<locals>.<genexpr>b  s     0!1:0r   z
build='%s'zbuild=%s>   rX   rZ   rW   rV   rY   r^   rc   c              3   &   K   | ]  }|v  
 y wrN   r.   )r/   r   values     r2   r3   z$MatchSpec.__str__.<locals>.<genexpr>t  s     1aqEz1r   z, =z=''[%s],r)   )r8   rx   ry   r   r>   matches_allr   
startswithaddFIELD_NAMESrC   )rh   r   bracketschannel_matchersubdir_matchername_matcherversion_exact_skipkeyrZ   r   rY   s            @@@r2   r   zMatchSpec.__str__5  s"   0044Y?::NN3/0_%@%@OOL3+??@//33H=?#>#>u~56n <=--11&#>'t|CD((,,Y7&&**73'lG222 89!,OONW$<=NN7+%sWSb\12#sWSb\12##D)w' $tg~. $JE0x00u 45
U 23sU{+
U 23AD***tt7M7M/MIIdO## 		6C%C4+A+A$A%<OD223781511OOse2eWA$67OOse1UG$45		6 NN6CHHX$667wwwrT   c                 "    | j                         S rN   r   r   s    r2   __json__zMatchSpec.__json__~  r   rT   c                     g }| j                  d      }|sJ |j                  |       | j                  d      }| j                  d      }|r|sJ |||gz  }n|r|j                  |       dj                  |      S )NrX   rZ   rY   r*   )r|   r   r   rC   )rh   r   rX   rZ   rY   s        r2   conda_build_formzMatchSpec.conda_build_form  s    ##F+tt""7+$$Y/N7''GNN7#xx  rT   c                 V    t        |t              r| j                  |j                  k(  S y)NF)r5   r6   	_hash_keyrh   others     r2   __eq__zMatchSpec.__eq__  s"    eY'>>U__44rT   c                 ,    t        | j                        S rN   )hashr   r   s    r2   __hash__zMatchSpec.__hash__  s    DNN##rT   c                 H    | j                   | j                  | j                  fS rN   )r8   r%   r&   r   s    r2   r   zMatchSpec._hash_key  s    %%t}}dkkAArT   c                     || j                   v S rN   r8   )rh   fields     r2   __contains__zMatchSpec.__contains__  s    ....rT   c                     t        |      t        j                  z
  }|rt        | j                  d|z        t        j
                  t        fd|j                         D              S )NzCannot match on field(s): %sc              3   6   K   | ]  \  }} ||        y wrN   r.   )r/   r   r   _make_components      r2   r3   z.MatchSpec._build_components.<locals>.<genexpr>  s     W*#u/#u5Ws   )r@   r6   FIELD_NAMES_SETr   r'   r   r!   rD   )rh   rG   
not_fieldsr   s      @r2   rg   zMatchSpec._build_components  s\    [9#<#<<
"'')G*)T  $33WWWWrT   c                     t        |d      r|}| |fS t        j                  }| |f}|j                  |      }|r| |fS | t        v rt	        |    |      }nt        t        |            }||| |f<   | |fS )Nr   )rB   r6   _MATCHER_CACHErx   _implementorsExactStrMatchr>   )r{   r   matcherr   	cache_keycached_matchers         r2   r   zMatchSpec._make_component  s    5'"Gw&&"11'	'++I6~--&#J/6G#CJ/G.5
E*+7""rT   c                 ,    | j                  d      xs dS )NrX   r   r   r   s    r2   rX   zMatchSpec.name  s    ##F+2s2rT   c                      t         fddD              }|t         j                        k  ry j                  d      rd j                  v ryd j                  v ryy)	Nc              3   :   K   | ]  }|j                   v   y wrN   r   )r/   frh   s     r2   r3   z'MatchSpec.strictness.<locals>.<genexpr>  s     RT+++Rs   rm      rX   rZ   rY   r   r   )sumrn   r8   r|   )rh   r   s   ` r2   
strictnesszMatchSpec.strictness  s^     R5QRRs4))**%%f-D<R<R1R$000rT   c                 "    | j                         S rN   )r   r   s    r2   rJ   zMatchSpec.spec  s    $$&&rT   c                 8    | j                   j                  d      S )NrY   )r8   rx   r   s    r2   rY   zMatchSpec.version  s     %%)))44rT   c                 p    | j                  d      xs | j                  d      }|rt        |      }|sJ |S )Nrc   r^   )r   r   )rh   r   s     r2   rc   zMatchSpec.fn  s:      &C$*<*<U*C3-C
s
rT   c                 @    t        t         fd|D              t              }t        t	        d      |      }|j                  dg       |j                  d g       z   }g }t        t        j                  d |j                         D                    }|D ]  }t        t	        d      |      }|j                  d d        t        |      dkD  rt        dt        |      z        |j                  t        |      dkD  rt        fd	|      n|d
           g ||S )Nc              3   4   K   | ]  }|s |        y wrN   r.   )r/   r   rE   s     r2   r3   z"MatchSpec.merge.<locals>.<genexpr>  s     "Da!3q6"Ds   )r   rX   r   c              3   R   K   | ]  }t        d  |      j                          ! yw)c                     | j                   S rN   )r%   )r   s    r2   <lambda>z+MatchSpec.merge.<locals>.<genexpr>.<lambda>  s
    !** rT   N)groupbyvalues)r/   groups     r2   r3   z"MatchSpec.merge.<locals>.<genexpr>  s)        ,e4;;= s   %'r&   r   zIncompatible MatchSpec merge:%sc                 (    | j                  |      S rN   )_merge)r   yunions     r2   r   z!MatchSpec.merge.<locals>.<lambda>  s    AHHQ$6 rT   r   )sortedr   r>   r   r
   rA   r   from_iterabler   rn   
ValueErrorr   r   r   )	rE   match_specsr   name_groupsunmergeablemerged_specsmergeable_groupsr   target_groupss	   ` `      r2   mergezMatchSpec.merge  s   U"D;"DD#Nj0+>!ooc2.r1JJ   (//1  
 & 		E#Jx$8%@MdD)=!A% !BXe_!TUUu:> 6>1X		 -,,,rT   c                 (    | j                  |d      S )NT)r   )r  )rE   r   s     r2   r   zMatchSpec.union  s    yyDy11rT   c                 p   | j                   |j                   k7  s| j                  |j                  k7  rt        d|  d|       i }t        | j                        t        |j                        z  }|D ]x  }| j                  j                  |      }|j                  j                  |      }||>||||<   F||||<   N|r	 |j                  |      }n|j                  |      }|||<   z  | j                  d| j                   | j                  d|S # t        t        t        f$ r
 | d| }Y Mw xY w)Nz!Incompatible MatchSpec merge:  - 
  - |)r%   r&   r.   )r%   r&   r   r@   r8   rx   r   r   	TypeErrorr  rM   )	rh   r   r   final_componentscomponent_namescomponent_namethis_componentthat_componentfinals	            r2   r   zMatchSpec._merge  s\   ==ENN*dkkU\\.I@fUGTUUd445E<S<S8TT- 	9N!3377GN"4488HN%.*@'3A 0'3A 0E . 4 4^ D +00@E38 0#	9$ t~~ 
]]4;;
:J
 	
 +J	B E#1"2!N3C DEs   DD54D5)FNrN   )F)-rO   rP   rQ   __doc__r   	frozensetr   r   ri   classmethodrv   r|   r   rx   propertyr   rr   r%   r&   r:   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rg   staticmethodr   rX   r   rJ   rY   rc   r  r   r   r.   rT   r2   r6   r6   U   s   ObK   ,ONB  :#!+ 
 
     ' '*
0
 G R!"$ B B/X # #" 3 3   ' ' 5 5
   - -0 2 2
rT   r6   )	metaclassc                     t        j                  d|       }|r(|j                         \  }}|xr |j                         }n| d}}|xr |j	                  dd      |fS )a  This should reliably pull the build string out of a version + build string combo.
    Examples:
        >>> _parse_version_plus_build("=1.2.3 0")
        ('=1.2.3', '0')
        >>> _parse_version_plus_build("1.2.3=0")
        ('1.2.3', '0')
        >>> _parse_version_plus_build(">=1.0 , < 2.0 py34_0")
        ('>=1.0,<2.0', 'py34_0')
        >>> _parse_version_plus_build(">=1.0 , < 2.0 =py34_0")
        ('>=1.0,<2.0', 'py34_0')
        >>> _parse_version_plus_build("=1.2.3 ")
        ('=1.2.3', None)
        >>> _parse_version_plus_build(">1.8,<2|==1.7")
        ('>1.8,<2|==1.7', None)
        >>> _parse_version_plus_build("* openblas_0")
        ('*', 'openblas_0')
        >>> _parse_version_plus_build("* *")
        ('*', '*')
    z<((?:.+?)[^><!,|]?)(?:(?<![=!|,<>~])(?:[ =])([^-=,|<>~]+?))?$Nr*   r)   )researchgroupsstripreplace)v_plus_brs   rY   rZ   s       r2   _parse_version_plus_buildr    s_    ( IIGE '%++-!4/wsB/66rT   c                 T    t        |       \  } }| j                  dd      \  }}}|||fS )z
    Examples:
        >>> _parse_legacy_dist("_license-1.1-py27_1.tar.bz2")
        ('_license', '1.1', 'py27_1')
        >>> _parse_legacy_dist("_license-1.1-py27_1")
        ('_license', '1.1', 'py27_1')
    rl   r   )r   rp   )rr   _rX   rY   rZ   s        r2   _parse_legacy_distr"  >  s6     &h/KHa#??32D'5%rT   c                 n    | syt        |       }|j                  xs |j                  }||j                  fS )NNN)r   rX   base_urlrW   )channel_valchnchannel_names      r2   _parse_channelr)  K  s3    
+
C88+s||L##rT   c                   ! t         j                  |       }|r|S | }| j                  d      r| d d }d|fdS d| v r+| j                  d      }| d | | |d  }} | j	                          | j                  dd      }t        |      dkD  rt        j                  d|        |d	   } t        |       rt        |       st        t        t        |                   } t        |       }|j                  rCt!        |j"                        \  }}	}
|j$                  |j                  ||	|
|j"                  | d
}|S | j'                  d      rt)        |       }n| }dt+        |      | dS i }t-        j.                  d|       }|rq|j1                         d	   }| j3                  |d      } |dd }t-        j4                  d|      }|D ],  }|j1                         \  }}}}|r|st7        |d      |||<   . t-        j.                  d|       }i }|rj|j1                         d	   }| j3                  |d      } |dd }t-        j4                  d|      }|D ]  }|j1                         \  }}}}|||<    d|v rd|d<   | j9                  dd      }t        |      }|dk(  r|\  }}} n$|dk(  r|\  }} d }n|r|d	   } d\  }}n
t;               t=        |      \  }}d|v r%t=        |j?                  d            \  }}|r|}|r|}d|v r|j?                  d      }t-        j.                  d|       }|r$|j1                         \  }} |t7        |d| z        t7        |d      | xr | j	                         } | rmd| v rt7        |d      tA        |       \  }	}
|	dk(  s|	d k(  rnI|	d	   d k(  rA|	dd  !|	d d dk(  r|
|	dd  }	n,tC        !fd!d"D              s|
!d   dk7  r!dz   }	n!}	nd\  }	}
i }|xs d|d#<   |||d<   |||d<   |	 |	|	|d$<   |
|
|d%<   d#|v r6d#|v r2d&|d#    d'|d#    d(|d#    d)} tE        jF                  | tH               |d#= |jK                  |       ||d*<   |t         |<   |S )+N@r   r   )rX   r\   #z if r   zIgnoring conditional in spec %sr   )rV   rW   rX   rY   rZ   rc   r^   zfile://)rX   rc   r^   z.*(?:(\[.*\]))r)   z2([a-zA-Z0-9_-]+?)=(["\']?)([^\'"]*?)(\2)(?:[, ]|$)zkey-value mismatch in bracketsz.*(?:(\(.*\)))r%   T:r   r   r$  rV   rW   z([^ =<>!~]+)?([><!=~ ].+)?zno package name found in '%s'zno package name found[z&multiple brackets sections not allowedr   r-   c              3   &   K   | ]  }|v  
 y wrN   r.   )r/   ctest_strs     r2   r3   z"_parse_spec_str.<locals>.<genexpr>  s     61h6r   z=,|rX   rY   rZ   z'name' specified both inside (z) and outside (z.) of brackets. The value outside of brackets (z) will be used.r'   )&_PARSE_CACHErx   endswithindexr  ro   rn   logdebugr   r   r   r   r   r   rW   r"  package_filenamecanonical_namer   r   r   r  r   r  r  finditerr   rp   NotImplementedErrorr)  rA   r  r   warningswarnUserWarningr;   )"spec_strcached_resultr:   feature_namendxr!  
spec_splitrV   rX   rY   rZ   resultpath_or_urlr   m3brackets_strm3br   r   r   m4parens
parens_strm4bm5m5_lenru   	namespacerW   	b_channelb_subdir
componentsrL   r1  s"                                    @r2   r?   r?   V  sh    $$X.M  }+o
 	
 hnnS!tnhstn! *J
:		3X>!}H x h{6(+;<=H(#>>#5g6N6N#O D'5"11!.."..F,  ""9-)(3& {+  H	#X	.B	yy{1~##L"5#Ab)kkA<
  	"E$||~CE1e&%'G  "HSM	" 
#X	.BF	YY[^
##J3"%
kkA:
  	 E$||~CE1F3K	  #!%F: 
a	 BWF{+-(Y	1 	8	a5!+Y!##$[1OGVH,X\\)-DE	8GF8h' 
/	:B	h<"!#BX#M  02IJJ ,HNN,H
 (?"!#K  38< d?gn QZ3qr{Hr{d"u}!!"+666=Xb\S%8&nG&G# JJv '
9%
8 '
9#
7 ( 2,Xf-=,> ?6"# $6"#?4 	
 	c;'Vh'8J#$&0L"#rT   c                   T    e Zd Zd Zed        Zd Zed        Ze	d        Z
d Zd Zy)	MatchInterfacec                     || _         y rN   
_raw_valuerh   r   s     r2   ri   zMatchInterface.__init__%  s	    rT   c                     t               rN   r:  r   s     r2   r   zMatchInterface.match(  s    !##rT   c                 $    | j                  |      S rN   )r   rW  s     r2   matcheszMatchInterface.matches,  s    zz%  rT   c                     | j                   S rN   rU  r   s    r2   r~   zMatchInterface.raw_value/      rT   c                     t               )ziIf the match value is an exact specification, returns the value.
        Otherwise returns None.
        rY  r   s    r2   ry   zMatchInterface.exact_value3  s    
 "##rT   c                     | j                   |j                   k7  r%t        d| j                   d|j                         | j                   S )Nz"Incompatible component merge:
  - r	  )r~   r   r   s     r2   r  zMatchInterface.merge:  sE    >>U__,5dnn5GveooM`a  ~~rT   c                 T    | j                   |j                   h}dj                  |      S )Nr
  )r~   rC   )rh   r   optionss      r2   r   zMatchInterface.unionA  s#    >>5??3xx  rT   N)rO   rP   rQ   ri   r   r   r[  r  r~   r   ry   r  r   r.   rT   r2   rS  rS  $  sR      $ $!   $ $!rT   rS  c                   4    e Zd Zd Zd Zd Zd Zed        Zy)_StrMatchMixinc                     | j                   S rN   rU  r   s    r2   r   z_StrMatchMixin.__str__G  s    rT   c                 N    | j                   j                   d| j                   dS )Nz('z'))rM   rO   rV  r   s    r2   r   z_StrMatchMixin.__repr__J  s%    ..))*"T__,=R@@rT   c                 d    t        || j                        xr | j                  |j                  k(  S rN   r5   rM   rV  r   s     r2   r   z_StrMatchMixin.__eq__M  '    %0XT__HXHX5XXrT   c                 ,    t        | j                        S rN   r   rV  r   s    r2   r   z_StrMatchMixin.__hash__P      DOO$$rT   c                     | j                   S rN   rU  r   s    r2   ry   z_StrMatchMixin.exact_valueS  r]  rT   N)	rO   rP   rQ   r   r   r   r   r  ry   r.   rT   r2   rc  rc  F  s,    AY%  rT   rc  c                   (     e Zd ZdZ fdZd Z xZS )r   rU  c                 $    t         |   |       y rN   )r<   ri   rh   r   rM   s     r2   ri   zExactStrMatch.__init__[  s    rT   c                 n    	 |j                   }| j                   |k(  S # t        $ r t        |      }Y %w xY wrN   )rV  r   r>   rh   r   
_other_vals      r2   r   zExactStrMatch.match^  s=    	$))J *,,  	$UJ	$s    44)rO   rP   rQ   	__slots__ri   r   rR   rS   s   @r2   r   r   X  s    I -rT   r   c                   $     e Zd Z fdZd Z xZS )ExactLowerStrMatchc                 @    t         |   |j                                y rN   r<   ri   lowerro  s     r2   ri   zExactLowerStrMatch.__init__g      'rT   c                     	 |j                   }| j                   |j                         k(  S # t        $ r t        |      }Y 3w xY wrN   )rV  r   r>   rx  rq  s      r2   r   zExactLowerStrMatch.matchj  sF    	$))J *"2"2"444  	$UJ	$s   + AA)rO   rP   rQ   ri   r   rR   rS   s   @r2   ru  ru  f  s    (5rT   ru  c                   H     e Zd ZdZ fdZd Zed        Zed        Z xZ	S )GlobStrMatch)rV  	_re_matchc                    t         |   |       d | _        	 |j                  d      r6|j	                  d      r%t        j                  |      j                  | _        y d|v rMt        j                  |      j                  dd      }t        j                  d|z        j                  | _        y y # t
        j                  $ r}t        |d| d      d }~ww xY w)	N^$r   z\*r   ^(?:%s)$)Contains an invalid regular expression. 'r   )r<   ri   r}  r   r3  r  compiler   escaper  errorr   rh   r   rK   rM   s      r2   ri   zGlobStrMatch.__init__u  s    		$)<!#E!2!8!8		%(00>!#K%,?!@!F!F  xx 	"B1#QG 	s   AB2  AB2 2CCCc                     	 |j                   }| j                  r| j                  |      S | j                   |k(  S # t        $ r t        |      }Y Bw xY wrN   )rV  r   r>   r}  rq  s      r2   r   zGlobStrMatch.match  sS    	$))J >>>>*--??j00  	$UJ	$s   : AAc                 6    | j                   | j                  S d S rN   )r}  rV  r   s    r2   ry   zGlobStrMatch.exact_value  s    "&.."8tBdBrT   c                      | j                   dk(  S )Nr   rU  r   s    r2   r   zGlobStrMatch.matches_all  s    #%%rT   )
rO   rP   rQ   rs  ri   r   r  ry   r   rR   rS   s   @r2   r|  r|  r  s<    )I	1 C C & &rT   r|  c                        e Zd Z fdZ xZS )GlobLowerStrMatchc                 @    t         |   |j                                y rN   rw  ro  s     r2   ri   zGlobLowerStrMatch.__init__  ry  rT   )rO   rP   rQ   ri   rR   rS   s   @r2   r  r    s    ( (rT   r  c                   V     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
ed	        Z xZS )
SplitStrMatchrU  c                 B    t         |   | j                  |             y rN   r<   ri   _convertro  s     r2   ri   zSplitStrMatch.__init__      u-.rT   c                     	 t        |j                  dd      j                  d            S # t        $ r t	        |      rt        |      cY S  w xY w)Nr*   r   )r  r  ro   r   r   rW  s     r2   r  zSplitStrMatch._convert  sM    	U]]34::3?@@ 	%  ''	s   ), AAc                     	 |xr | j                   |j                   z  S # t        $ r! | j                   | j                  |      z  cY S w xY wrN   )rV  r   r  r   s     r2   r   zSplitStrMatch.match  sH    	:?T__u/?/??? 	:??T]]5%999	:s    'A	A	c                 x    | j                   r.ddj                  d t        | j                         D              z  S y)Nz{%s}r+   c              3   &   K   | ]	  }d |z    yw'%s'Nr.   )r/   r   s     r2   r3   z)SplitStrMatch.__repr__.<locals>.<genexpr>  s     %RQfqj%R   zset())rV  rC   r   r   s    r2   r   zSplitStrMatch.__repr__  s/    ??DII%R&:Q%RRRRrT   c                 J    dj                  t        | j                              S Nr*   rC   r   rV  r   s    r2   r   zSplitStrMatch.__str__  s    xxt/00rT   c                 d    t        || j                        xr | j                  |j                  k(  S rN   rg  r   s     r2   r   zSplitStrMatch.__eq__  rh  rT   c                 ,    t        | j                        S rN   rj  r   s    r2   r   zSplitStrMatch.__hash__  rk  rT   c                     | j                   S rN   rU  r   s    r2   ry   zSplitStrMatch.exact_value  r]  rT   rO   rP   rQ   rs  ri   r  r   r   r   r   r   r  ry   rR   rS   s   @r2   r  r    s@    I/:1Y%  rT   r  c                   V     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
ed	        Z xZS )
FeatureMatchrU  c                 B    t         |   | j                  |             y rN   r  ro  s     r2   ri   zFeatureMatch.__init__  r  rT   c                     |s
t               S t        |t              r8t        d d |j                  dd      j	                  d      D        D              S t        d d |D        D              S )Nc              3   $   K   | ]  }|r| 
 y wrN   r.   r/   r   s     r2   r3   z(FeatureMatch._convert.<locals>.<genexpr>  s       r   c              3   <   K   | ]  }|j                           y wrN   r  r/   ffs     r2   r3   z(FeatureMatch._convert.<locals>.<genexpr>  s     R"((*R   r*   r   c              3   &   K   | ]	  }|s|  y wrN   r.   r  s     r2   r3   z(FeatureMatch._convert.<locals>.<genexpr>  s     J1QJs   c              3   <   K   | ]  }|j                           y wrN   r  r  s     r2   r3   z(FeatureMatch._convert.<locals>.<genexpr>  s     (D(Dr  )r  r5   r>   r  ro   rW  s     r2   r  zFeatureMatch._convert  se    ;s# Ru}}S#/F/L/LS/QR   J(De(DJJJrT   c                 B    | j                  |      }| j                  |k(  S rN   )r  rV  r   s     r2   r   zFeatureMatch.match  s    e$%''rT   c                 ^    ddj                  d t        | j                        D              z  S )Nr   r+   c              3   &   K   | ]	  }d |z    ywr  r.   )r/   r0   s     r2   r3   z(FeatureMatch.__repr__.<locals>.<genexpr>  s     !N&1*!Nr  r  r   s    r2   r   zFeatureMatch.__repr__  s%    		!NfT__6M!NNNNrT   c                 J    dj                  t        | j                              S r  r  r   s    r2   r   zFeatureMatch.__str__  s    xxt/00rT   c                 d    t        || j                        xr | j                  |j                  k(  S rN   rg  r   s     r2   r   zFeatureMatch.__eq__  rh  rT   c                 ,    t        | j                        S rN   rj  r   s    r2   r   zFeatureMatch.__hash__  rk  rT   c                     | j                   S rN   rU  r   s    r2   ry   zFeatureMatch.exact_value  r]  rT   r  rS   s   @r2   r  r    sB    I/
K(O1Y%  rT   r  c                   0     e Zd Z fdZd Zd Zd Z xZS )ChannelMatchc                    d | _         	 t        |t              r|j                  d      r6|j	                  d      r%t        j                  |      j                  | _         nGd|v r8t        j                  d|j                  dd      z        j                  | _         nt        |      }t        t        | ;  |       y # t
        j                  $ r}t        |d| d      d }~ww xY w)Nr  r  r   r  r   r  r   )r}  r5   r>   r   r3  r  r  r   r  r   r  r   r<   r|  ri   r  s      r2   ri   zChannelMatch.__init__  s    	%%##C(U^^C-@%'ZZ%6%<%<DNE\%'ZZ#emmC&??&e N $ENE 	lD*51 xx 	"B1#QG 	s   BB< <C$CC$c                    	 t        |j                        }| j                  r| j                  |j                        S | j                  j
                  |j
                  |j                  fv S # t        $ r t        |      }Y kw xY wrN   )r   rV  r   r}  r8  rX   rq  s      r2   r   zChannelMatch.match  su    	( !1!12J >>>>*";";<< ??''JOOZ=V=V+WWW  	( J	(s   A, ,BBc                 r    	 d| j                   j                  z  S # t        $ r d| j                   z  cY S w xY w)Nr   )rV  rX   r   r   s    r2   r   zChannelMatch.__str__  s:    	*$//.... 	*$//))	*s    66c                 (    d| j                         z  S )Nr  r   r   s    r2   r   zChannelMatch.__repr__  s    &&rT   )rO   rP   rQ   ri   r   r   r   rR   rS   s   @r2   r  r    s    2(X*'rT   r  c                       e Zd Zd Zy)CaseInsensitiveStrMatchc                     	 |j                   }|j                         }| j                  r| j	                  |      S | j                   |k(  S # t        $ r t        |      }Y Rw xY wrN   )rV  r   r>   rx  r}  rq  s      r2   r   zCaseInsensitiveStrMatch.match  sa    	$))J  %%'
>>>>*--??j00  	$UJ	$s   A
 
A! A!N)rO   rP   rQ   r   r.   rT   r2   r  r    s    
1rT   r  )	rV   rX   rY   rZ   r[   r\   r]   ra   rb   )Jr  r  r;  abcr   r   r   collections.abcr   	functoolsr   	itertoolsr   loggingr	   operatorr
   os.pathr   auxlib.decoratorsr   base.constantsr   r   base.contextr   common.compatr   	common.ior   common.iteratorsr   r   common.pathr   r   r   r   
common.urlr   r   r   
exceptionsr   r   rV   r   rY   r   r    r!   ImportErrorauxlib.collectionrO   r5  typer#   r6   r  r"  r)  r2  r?   rS  rc  r   ru  r|  r  r  r  r  r  r   r.   rT   r2   <module>r     sW   
  9 9 #      0 S " &   9 S S 5 5 6  2/% +:D +:\G
- G
T7>
 $ K\!w !D $-NN -	5 	5#&>> #&L( (
&N &R$> $N)'< )'X1/ 1 $"&-
M   /./s   D< <E
	E
