
    \ZiQ              
         S r SSKJr  SSKrSSKrSSKJrJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJr  SSKJr  SSKJr  SSKJr  SSKJ r!  SSK"J#r#J$r$J%r%  SSK&J'r'J(r(J)r)  SSK*J+r+J,r,  SSK-J.r.  SSK/J0r0J1r1   SSK2J2r2  \" \55      r6 " S S\75      r8 " S S\8S9r9S r:S r;S  r<0 r=S8S! jr>S" r? " S# S$\S9r@ " S% S&5      rA " S' S(\A\@5      rB " S) S*\B5      rC " S+ S,\A\@5      rD " S- S.\D5      rE " S/ S0\@5      rF " S1 S2\@5      rG " S3 S4\D5      rH " S5 S6\E5      rI\H\E\1\D\0\G\G\I\IS7.	rJg! \3 a	    SSK4J2r2   Nf = f)9zImplements 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.
    )annotationsN)ABCMetaabstractmethod)Mapping)reduce)chain)	getLogger)
attrgetter)basename   )memoizedproperty)CONDA_PACKAGE_EXTENSION_V1CONDA_PACKAGE_EXTENSION_V2)context)
isiterable)dashlist)groupby_to_dict)expandstrip_pkg_extensionurl_to_path)is_urlpath_to_urlunquote)InvalidMatchSpecInvalidSpec   )Channel)BuildNumberMatchVersionSpec)
frozendictc                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )MatchSpecType)   c                  >  U(       Ga  [        U[        5      (       a	  U(       d  U$ [        U[        5      (       a~  [        UR                  5      nUR	                  SUR
                  5        UR	                  SUR                  5        UR                  US'   UR                  " S0 UD6  [        TU ](  " S0 UD6$ [        U[        5      (       aU  [        U5      nU(       a3  [        U40 UD6n[        U5      SS1-
  (       a  UR                  SS 5        [        TU ](  " S0 UD6$ [        U[        5      (       a  [        U40 UD6n[        TU ](  " S0 UD6$ [!        US5      (       a%  UR#                  5       nU(       a  [        U40 UD6$ U$ [%        SU SU 35      e[        TU ](  " S0 UD6$ ! [$         aP  nSnU(       a  Xq -  nU(       a,  USS	R'                  S
 UR)                  5        5       5      -   -  n[+        XvS9UeS nAff = f)Noptionaltarget_original_spec_strto_match_speczInvalid MatchSpec:
  spec_arg=z

  kwargs=  , c              3  4   #    U  H  u  pU S U 3v   M     g7f)=N ).0kvs      7lib/python3.13/site-packages/conda/models/match_spec.py	<genexpr>)MatchSpecType.__call__.<locals>.<genexpr>S   s     &Mnda!AaSzns   )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>   MatchSpecType.__call__*   s   )	:h	226#O)44!%h&@&@!AJ))*h6G6GH))(HOOD7?7Q7QJ34%%// 7+9j99#..,X6F!%f!7!7v;*h)?? #JJ';TB 7+5f55'22!(5f5F 7+5f55X7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=   %F. BF. <A)F. &0F. 3F. F.  F. .
H8AHHr.   N)__name__
__module____qualname____firstlineno__r>   __static_attributes____classcell__rN   s   @r2   r"   r"   )   s    *: *:    r"   c                     \ rS rSrSrSr\" \5      r0 rS(S jr	\
S 5       rS rS rS)S	 jr\S
 5       rS r\S 5       r\S 5       r\S 5       rS rS rS rS rS rS rS rS rS rS rS rS r \!S 5       r"S r#S r$\%S 5       r&\S 5       r'\S  5       r(\S! 5       r)\S" 5       r*\S# 5       r+\
S*S$ j5       r,\
S% 5       r-S*S& jr.S'r/g)+r7   W   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 supported more than one string representation
for equivalent :class:`MatchSpec` queries.  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                x    Xl         X l        UR                  SS 5      U l        U R                  " S0 UD6U l        g )Nr'   r.   )	_optional_targetrB   r'   _build_componentsr9   )selfr%   r&   rH   s       r2   __init__MatchSpec.__init__   s6    !"(**-A4"H!%!7!7!A&!ArX   c                   0 nU[        [        5      * S  [        :X  a  US [        [        5      *  nO.U[        [        5      * S  [        :X  a  US [        [        5      *  nSU;   aZ  UR                  SS5      u  p1SU;   a<  UR	                  SS5      u  pEU[
        R                  ;  a  UnS nXBS'   U(       a  XRS'   OX2S'   UR	                  SS5      u  pgnUR                  UUUS.5        U " S	0 UD6$ )
N::r   /r[   r\   -r   r]   r^   r_   r.   )lenr   r   splitrsplitr   known_subdirsr<   )	rF   dist_strpartschannel_subdir_strchannel_strr\   r]   r^   r_   s	            r2   from_dist_str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#!6!66"4K!F#.i &,(O#5i 'sA6u"	
 |U|rX   c                b    U R                   R                  U5      nU=(       a    UR                  $ rP   )r9   getexact_valuerm   
field_namer1   s      r2   get_exact_valueMatchSpec.get_exact_value   s'    ""&&z2"Q]]"rX   c                b    U R                   R                  U5      nU=(       a    UR                  $ rP   )r9   r   	raw_valuer   s      r2   get_raw_valueMatchSpec.get_raw_value   s'    ""&&z2 Q[[ rX   c                2    U R                  U5      nUc  U$ U$ rP   )r   )rm   r   defaultr1   s       r2   r   MatchSpec.get   s!    z*)w**rX   c                    [        U R                  5      S:H  =(       a%    SU R                  ;   =(       a    U R                  S:g  $ )Nr   r]   *)ru   r9   r]   rm   s    r2   is_name_only_specMatchSpec.is_name_only_spec   s@     &&'1, !$000!		S 	
rX   c                "    U R                  5       $ rP   __str__r   s    r2   ry   MatchSpec.dist_str       ||~rX   c                    U R                   $ rP   )rj   r   s    r2   r%   MatchSpec.optional   s    ~~rX   c                    U R                   $ rP   )rk   r   s    r2   r&   MatchSpec.target   s    ||rX   c                    U R                   $ rP   )r'   r   s    r2   r;   MatchSpec.original_spec_str   s    &&&rX   c                    [        U[        5      (       a  SSKJn  UR	                  U5      nU R
                  R                  5        H  u  p4U R                  XU5      (       a  M    g   g)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)r6   r8   recordsr   from_objectsr9   rE   _match_individual)rm   recr   r   r1   s        r2   matchMatchSpec.match  sZ    
 c4  .,,S1C!3399;MJ))#1== < rX   c                d    [        X5      n UR                  U5      $ ! [         a    X4:H  s $ f = frP   )getattrr   AttributeError)rm   recordr   match_componentvals        r2   r   MatchSpec._match_individual  s:    f)	*"((-- 	*"))	*s    //c                f    [        U R                  5      S:H  =(       a    U R                  S5      S L$ )Nr   r]   )ru   r9   r   r   s    r2   
_is_simpleMatchSpec._is_simple  s2    &&'1, 9$$V,D8	
rX   c                2    [        U R                  5      S:H  $ )Nr   )ru   r9   r   s    r2   
_is_singleMatchSpec._is_single  s    4))*a//rX   c                   ^  T R                  S5      nU(       a  U$ [        U 4S jS 5       5      n[        S U 5       5      (       d  SR                  " U6 [        -   $ g )Nrh   c              3  F   >#    U  H  nTR                  U5      v   M     g 7frP   r   )r/   xrm   s     r2   r3   4MatchSpec._to_filename_do_not_use.<locals>.<genexpr>(  s!     S6RT))!,,6Rs   !rt   c              3  (   #    U  H  oS L v   M
     g 7frP   r.   )r/   r   s     r2   r3   r   )  s     +d9ds   z{}-{}-{})r   tupleanyformatr   )rm   fn_fieldvalss   `  r2   _to_filename_do_not_use!MatchSpec._to_filename_do_not_use"  sY     ''-OS6RSS+d+++%%t,0JJJrX   c                $   U R                   R                   SU  S3/nU R                  (       a  UR                  SU R                   S35        U R                  (       a  UR                  S5        UR                  S5        SR                  U5      $ )Nz(""z
, target="z, optional=True)r)   )rN   rQ   r&   appendr%   rD   )rm   builders     r2   __repr__MatchSpec.__repr__.  sq    nn--.ba89;;NNZ}A67==NN,-swwwrX   c                  ^	^
^ / n/ nU R                   R                  S5      nU(       a,  UR                  (       a  UR                  [	        U5      5        O5U(       a.  UR
                  (       d  UR                  S[	        U5       35        U R                   R                  S5      nU(       aA  U(       a&  UR                  (       a  UR                  SU 35        OUR                  SU 35        U R                   R                  SS5      nUR                  U(       a  SOS	U-  5        U R                   R                  S
5      mU R                   R                  S5      m	SnT(       a  [	        T5      m[        U4S jS 5       5      (       a  UR                  ST S35        OTS S S;   a/  T	(       a  UR                  ST S35        OUR                  T5        OTSS  S:X  a  UR                  STS S -   5        OhTS:X  a  OaTS   S:X  a  UR                  STS S -   5        O@TR                  S5      (       a  UR                  T5        SnOUR                  ST-   5        SnT	(       a  [	        T	5      m	[        U	4S jS 5       5      (       a  UR                  ST	 S35        OKST	;   a  UR                  ST	 35        O0U(       a  UR                  ST	-   5        OUR                  ST	 35        1 SknSU R                   ;   a!  SU R                   ;   a  UR                  S5        U R                   H  nX;  d  M
  XR                   ;   d  M  US:X  a	  U(       a  M*  [	        U R                   U   5      m
[        U
4S jS  5       5      (       a  UR                  U S!T
 S35        Mu  UR                  U ST
 35        M     U(       a/  UR                  S"R                  S#R                  U5      5      5        S$R                  U5      $ )%Nr[   zchannel=r\   rr   zsubdir=r]   r   z::%sz%sr^   r_   Fc              3  ,   >#    U  H	  oT;   v   M     g 7frP   r.   )r/   sr^   s     r2   r3   $MatchSpec.__str__.<locals>.<genexpr>P  s     2A<   z><$^|,z	version=''r   )z!=z~=.*r-   ==Tc              3  ,   >#    U  H	  oT;   v   M     g 7frP   r.   )r/   r   r_   s     r2   r3   r   h  s     0x!:xr   zbuild='zbuild=>   r]   r_   r\   r[   r^   rc   rh   c              3  ,   >#    U  H	  oT;   v   M     g 7frP   r.   )r/   r   values     r2   r3   r   z  s     15aEz5r   z, =z='[{}],r)   )r9   r   r   r   r?   matches_allr   
startswithaddFIELD_NAMESr   rD   )rm   r   bracketschannel_matchersubdir_matchername_matcherversion_exact_skipkeyr_   r   r^   s            @@@r2   r   MatchSpec.__str__7  sN   0044Y?::NN3/0_%@%@OOhs?';&<=>//33H=?#>#>>"234'.)9 :;--11&#>'t|CD((,,Y7&&**73'lG2222)G9A 67!,OOiy$:;NN7+%sWSb\12 C#sWSb\12##D))w' $tg~. $JE0x000'% 23& 01sU{+& 01AD***tt7M7M/MIIdO##CC+A+A$A%<OD2237815111OOse2eWA$67OOse1UG$45 $ NN6==();<=wwwrX   c                "    U R                  5       $ rP   r   r   s    r2   __json__MatchSpec.__json__  r   rX   c                6   / nU R                  S5      nU(       d  [        S5      eUR                  U5        U R                  S5      nU R                  S5      nU(       a  U=(       d    SnXU/-  nOU(       a  UR                  U5        SR	                  U5      $ )Nr]   z3.conda_build_form() requires a non-empty spec name.r_   r^   r   r*   )r   
ValueErrorr   r   rD   )rm   r   r]   r_   r^   s        r2   conda_build_formMatchSpec.conda_build_form  s    ##F+RSSt""7+$$Y/nG''GNN7#xx  rX   c                    [        U 5      nSU;   a  UR                  SS5      S   nSU;   a  UR                  SSS5      nU$ )aj  
Return the package specification in conda environment export format.

This produces the format used by `conda env export`: name=version=build
(single equals), without channel prefixes and without .* patterns.

Examples:
    >>> MatchSpec("numpy==1.21.0=py39h1234567_0").conda_env_form()
    'numpy=1.21.0=py39h1234567_0'
    >>> MatchSpec("numpy=1.21.0").conda_env_form()  # no-builds case
    'numpy=1.21.0'
    >>> MatchSpec("conda-forge::numpy==1.21.0=py39h1234567_0").conda_env_form()
    'numpy=1.21.0=py39h1234567_0'  # channel prefix removed

Returns:
    str: Package specification in conda env export format
rq   r   r   r-   )r?   rv   replace)rm   spec_strs     r2   conda_env_formMatchSpec.conda_env_form  sO    & t9 8~~dA.q1H 8''c15HrX   c                `    [        U[        5      (       a  U R                  UR                  :H  $ g)NF)r6   r7   	_hash_keyrm   others     r2   __eq__MatchSpec.__eq__  s%    eY''>>U__44rX   c                ,    [        U R                  5      $ rP   )hashr   r   s    r2   __hash__MatchSpec.__hash__  s    DNN##rX   c                H    U R                   U R                  U R                  4$ rP   )r9   r%   r&   r   s    r2   r   MatchSpec._hash_key  s    %%t}}dkkAArX   c                    XR                   ;   $ rP   r9   )rm   fields     r2   __contains__MatchSpec.__contains__  s    ....rX   c                   ^ [        U5      [        R                  -
  nU(       a  [        U R                  SU 35      e[        R
                  m[        U4S jUR                  5        5       5      $ )NzCannot match on field(s): c              3  8   >#    U  H  u  pT" X5      v   M     g 7frP   r.   )r/   r   r   _make_components      r2   r3   .MatchSpec._build_components.<locals>.<genexpr>  s     W*#/#55s   )rA   r7   FIELD_NAMES_SETr   r'   r   r    rE   )rm   rH   
not_fieldsr   s      @r2   rl   MatchSpec._build_components  s^    [9#<#<<
"''+Ej\)R  $33WWWWrX   c                    [        US5      (       a  UnX4$ [        R                  nX4nUR                  U5      nU(       a  X4$ U [        ;   a  [        U    " U5      nO[        [        U5      5      nX#X4'   X4$ )Nr   )rC   r7   _MATCHER_CACHEr   _implementorsExactStrMatchr?   )r   r   matcherr  	cache_keycached_matchers         r2   r   MatchSpec._make_component  s    5'""G&&"11'	'++I6--&#J/6G#CJ/G.5
*+""rX   c                6    U R                  S5      =(       d    S$ )Nr]   r   r   r   s    r2   r]   MatchSpec.name  s    ##F+2s2rX   c                   ^  [        U 4S jS 5       5      nU[        T R                  5      :  a  gT R                  S5      (       a  ST R                  ;   a  gST R                  ;   a  gg)	Nc              3  @   >#    U  H  oTR                   ;   v   M     g 7frP   r   )r/   frm   s     r2   r3   'MatchSpec.strictness.<locals>.<genexpr>  s     R5QT+++5Qs   rt      r]   r_   r^   r   r   )sumru   r9   r   )rm   r   s   ` r2   
strictnessMatchSpec.strictness  sa     R5QRRs4))**%%f--D<R<R1R$000rX   c                "    U R                  5       $ rP   )r   r   s    r2   rK   MatchSpec.spec  s    $$&&rX   c                8    U R                   R                  S5      $ )Nr^   )r9   r   r   s    r2   r^   MatchSpec.version  s     %%)))44rX   c                    U R                  S5      =(       d    U R                  S5      nU(       a  [        U5      nU(       d  [        S5      eU$ )Nrh   rc   z.fn cannot be empty.)r   r   r   )rm   r   s     r2   rh   MatchSpec.fn  sB      &C$*<*<U*C3-C344
rX   c                H  ^ ^ [        [        U 4S jU 5       5      [        S9n[        [	        S5      U5      nUR                  S/ 5      UR                  S / 5      -   n/ n[        [        R                  " S UR                  5        5       5      5      nU H  n[        [	        S5      U5      nUR                  S S 5        [        U5      S:  a  [        S[        U5       35      eUR                  [        U5      S:  a  [        U4S	 jU5      OUS
   5        M     / UQUQ7$ )Nc              3  D   >#    U  H  o(       d  M  T" U5      v   M     g 7frP   r.   )r/   r   rF   s     r2   r3   "MatchSpec.merge.<locals>.<genexpr>  s     "D;a!63q66;s   
  )r   r]   r   c              3  X   #    U  H   n[        S  U5      R                  5       v   M"     g7f)c                    U R                   $ rP   )r%   )r   s    r2   <lambda>+MatchSpec.merge.<locals>.<genexpr>.<lambda>  s    !**rX   N)groupbyvalues)r/   groups     r2   r3   r    s+       1E ,e4;;==1s   (*r&   r   zIncompatible MatchSpec merge:c                (   > U R                  UT5      $ rP   )_merge)r   yunions     r2   r"  !MatchSpec.merge.<locals>.<lambda>  s    AHHQ$6rX   r   )sortedr   r?   r$  r
   rB   r   from_iterabler%  ru   r   r   r   r   )	rF   match_specsr*  name_groupsunmergeablemerged_specsmergeable_groupsr&  target_groupss	   ` `      r2   mergeMatchSpec.merge  s   U"D;"DD#Nj0+>!ooc2.r1JJ   (//1  
 &E#Jx$8%@MdD)=!A% #@%@Q!RSSu:> 6>1X & -,,,rX   c                "    U R                  USS9$ )NT)r*  )r4  )rF   r.  s     r2   r*  MatchSpec.union%  s    yyDy11rX   c                   U R                   UR                   :w  d  U R                  UR                  :w  a  [        SU  SU 35      e0 n[        U R                  5      [        UR                  5      -  nU H  nU R                  R                  U5      nUR                  R                  U5      nUc  Uc  MA  Uc  XsU'   MJ  Uc  XcU'   MS  U(       a   UR                  U5      nOUR                  U5      nXU'   M     U R                  " SU R                   U R                  S.UD6$ ! [        [        [        4 a
    U SU 3n NOf = f)Nz!Incompatible MatchSpec merge:  - 
  - |)r%   r&   r.   )r%   r&   r   rA   r9   r   r*  r   	TypeErrorr4  rN   )	rm   r   r*  final_componentscomponent_namescomponent_namethis_componentthat_componentfinals	            r2   r(  MatchSpec._merge)  sL   ==ENN*dkkU\\.I@fUGTUUd445E<S<S8TT-N!3377GN"4488HN%.*@'3A0'3A0E . 4 4^ D +00@E380# .$ ~~ 
]]4;;
:J
 	
 +J	B E#1"2!N3C DEs   D$$EE)r9   rj   r'   rk   )FNrP   )F)0rQ   rR   rS   rT   __doc__r   	frozensetr  r  rn   classmethodr}   r   r   r   propertyr   ry   r%   r&   r;   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rl   staticmethodr   r]   r  rK   r^   rh   r4  r*  r(  rU   r.   rX   r2   r7   r7   W   s   ObK   ,ONB  :#!+ 
 
     ' '*
0
 K Z!$>$ B B/X # #" 3 3   ' ' 5 5
   - -0 2 2
rX   r7   )	metaclassc                    [         R                  " SU 5      nU(       a,  UR                  5       u  p#U=(       a    UR                  5       nOU Sp2U=(       a    UR	                  SS5      U4$ )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stripr   )v_plus_brz   r^   r_   s       r2   _parse_version_plus_buildrO  F  s[    ( IIGE '%++-!4/wsB/66rX   c                N    [        U 5      u  pU R                  SS5      u  p#nX#U4$ )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')
rs   r   )r   rw   )ry   _r]   r^   r_   s        r2   _parse_legacy_distrR  e  s0     &h/KH#??32D5%rX   c                    U (       d  g[        U 5      nUR                  =(       d    UR                  nX!R                  4$ )NNN)r   r]   base_urlr\   )channel_valchnchannel_names      r2   _parse_channelrY  r  s1    
+
C88+s||L##rX   c                  ^ U S;   a  U $ U R                  S5      (       d  U $ U R                  S5      mU R                  S5      (       a  Uc  T$ [        U4S jS 5       5      (       d   Uc  TR                  S5      (       d  TS-   $ T$ U $ )a  
Sanitize version strings for MatchSpec parsing.

Handles edge cases and translates version patterns for proper MatchSpec processing.

Empty operators like "==" are passed through so existing error handling code can
treat them like other incomplete operators ("<=" or ">="). This is necessary because
downstream translation code would mangle "==" into an empty string, resulting in an
empty version field that breaks logic expecting missing versions to be represented
as operators like "==", "<=", and ">=".

These missing version cases result from match specs like "numpy==", "numpy<=",
"numpy>=", "numpy= " (with trailing space), which should be treated as errors.
Note: "numpy=" (no trailing space) is treated as valid.

For simple versions starting with "=", translates patterns like "=1.2.3" to "1.2.3*"
when appropriate conditions are met.

Args:
    version: The version string to sanitize
    build: Optional build string that affects sanitization behavior

Returns:
    Sanitized version string

Examples:
    "==" or "=" -> passed through for error handling
    "==1.2.3" -> "1.2.3" (when build is None)
    "=1.2.3" -> "1.2.3*" (when build is None and no special chars)
    ">=1.0" -> ">=1.0" (unchanged, doesn't start with "=")
)r   r-   r-   r   c              3  ,   >#    U  H	  oT;   v   M     g 7frP   r.   )r/   charversion_without_equalss     r2   r3   (_sanitize_version_str.<locals>.<genexpr>  s     @%$--%r   z=,|r   )r   lstripr   endswith)r^   r_   r]  s     @r2   _sanitize_version_strra  }  s    B + c""$^^C0 $EM%% @%@@@=!7!@!@!E!E)C//%%NrX   c                	   [         R                  U 5      nU(       a  U$ U nU R                  S5      (       a  U S S nSU4S.$ SU ;   a)  U R                  S5      nU S U XS  pPU R	                  5         U R                  SS5      n[        U5      S:  a  [        R                  SU 5        US	   n [        R                  R                  U 5      (       a  [        U 5      (       d  [        [        [        U 5      5      5      n [!        U 5      nUR"                  (       aB  [%        UR&                  5      u  pn
UR(                  UR"                  UU	U
UR&                  U S
.nU$ U R+                  S5      (       a  [-        U 5      nOU nS[/        U5      U S.$ 0 n[0        R2                  " SU 5      nU(       a  UR5                  5       S	   nU R7                  US5      n USS n[0        R8                  " SU5      nU Hm  nUR5                  5       u  nnnnU(       a  U(       d  [;        US5      eUS:X  a0  U(       a)  [=        UUR?                  5       R                  S5      5      nUUU'   Mo     [0        R2                  " SU 5      n0 nU(       ao  UR5                  5       S	   nU R7                  US5      n USS n[0        R8                  " SU5      nU H  nUR5                  5       u  nnnnUUU'   M     SU;   a  SUS'   U RA                  SS5      n[        U5      nUS:X  a  Uu  nnn O*US:X  a  Uu  nn S nOU(       a  US	   n Su  nnO
[C        5       e[E        U5      u  nnSU;   a/  [E        URG                  S5      5      u  nnU(       a  UnU(       a  UnSU;   a  URG                  S5      n[0        R2                  " SU 5      nU(       a&  UR5                  5       u  pUc  [;        USU  S35      eO[;        US5      eU =(       a    U R	                  5       n U (       a+  S U ;   a  [;        US!5      e[I        U 5      u  p[=        X5      n	OSu  p0 nU=(       d    SUS"'   Ub  UUS'   Ub  UUS'   Ub   U	b  U	US'   U
b  U
US'   S"U;   a9  S"U;   a3  S#US"    S$US"    S%US"    S&3n [J        RL                  " U [N        5        US"	 URQ                  U5        UUS''   U[         U'   U$ )(N@r   r   )r]   ra   #z if r   zIgnoring conditional in spec %sr   )r[   r\   r]   r^   r_   rh   rc   zfile://)r]   rh   rc   z.*(?:(\[.*\]))r)   z2([a-zA-Z0-9_-]+?)=(["\']?)([^\'"]*?)(\2)(?:[, ]|$)zkey-value mismatch in bracketsr^   r_   z.*(?:(\(.*\)))r%   T:r   r  rT  r[   r\   z([^ =<>!~]+)?([><!=~ ].+)?zno package name found in 'r   zno package name found[z&multiple brackets sections not allowedr]   z'name' specified both inside (z) and outside (z.) of brackets. The value outside of brackets (z) will be used.r'   ))_PARSE_CACHEr   r`  indexrM  rv   ru   logdebugr   plugin_managerhas_package_extensionr   r   r   r   r   r\   rR  package_filenamecanonical_namer   r   r   rJ  r   rL  r   finditerr   ra  	groupdictrw   NotImplementedErrorrY  rB   rO  warningswarnUserWarningr<   )!r   cached_resultr;   feature_namendxrQ  
spec_splitr[   r]   r^   r_   resultpath_or_urlr   m3brackets_strm3br   r   r   m4parens
parens_strm4bm5m5_lenr|   	namespacer\   	b_channelb_subdir
componentsrM   s!                                    r2   r@   r@     s0    $$X.M  }+o
 	
 hnnS!tnhtn! *J
:		3X>!}H 33H==h{6(+;<=H(#>>#5g6N6N#O D5"11!.."..F,  ""9--)(3& {+  H	#X	.B	yy{1~##L"5#Ab)kkA<
 E$||~CE1e&%'G  iE-eU__5F5J5J75ST!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	<"!%?z#K  
 02IJJ ,HNN,H
 (?"!#K  38<'7# JJv '
9%
8 '
9#
7 ( 2,Xf-=,> ?6"# $6"#?4 	
 	c;'Vh'8J#$&0L"#rX   c                  f    \ rS rSrS r\S 5       rS r\S 5       r	\\S 5       5       r
S rS rS	rg
)MatchInterfaceik  c                    Xl         g rP   
_raw_valuerm   r   s     r2   rn   MatchInterface.__init__l  s    rX   c                    [        5       erP   rq  r   s     r2   r   MatchInterface.matcho  s    !##rX   c                $    U R                  U5      $ rP   )r   r  s     r2   matchesMatchInterface.matchess  s    zz%  rX   c                    U R                   $ rP   r  r   s    r2   r   MatchInterface.raw_valuev      rX   c                    [        5       e)zYIf the match value is an exact specification, returns the value.
Otherwise returns None.
r  r   s    r2   r   MatchInterface.exact_valuez  s     "##rX   c                    U R                   UR                   :w  a'  [        SU R                   < SUR                   < 35      eU R                   $ )Nz"Incompatible component merge:
  - r9  )r   r   r   s     r2   r4  MatchInterface.merge  sE    >>U__,5dnn5GveooM`a  ~~rX   c                T    U R                   UR                   1nSR                  U5      $ )Nr:  )r   rD   )rm   r   optionss      r2   r*  MatchInterface.union  s#    >>5??3xx  rX   r  N)rQ   rR   rS   rT   rn   r   r   r  rF  r   r   r4  r*  rU   r.   rX   r2   r  r  k  sZ      $ $!   $  $!rX   r  c                  <    \ rS rSrS rS rS rS r\S 5       r	Sr
g)	_StrMatchMixini  c                    U R                   $ rP   r  r   s    r2   r   _StrMatchMixin.__str__  s    rX   c                N    U R                   R                   SU R                   S3$ )Nz('z'))rN   rQ   r  r   s    r2   r   _StrMatchMixin.__repr__  s%    ..))*"T__,=R@@rX   c                l    [        XR                  5      =(       a    U R                  UR                  :H  $ rP   r6   rN   r  r   s     r2   r   _StrMatchMixin.__eq__  %    %0XT__HXHX5XXrX   c                ,    [        U R                  5      $ rP   r   r  r   s    r2   r   _StrMatchMixin.__hash__      DOO$$rX   c                    U R                   $ rP   r  r   s    r2   r   _StrMatchMixin.exact_value  r  rX   r.   N)rQ   rR   rS   rT   r   r   r   r   rF  r   rU   r.   rX   r2   r  r    s,    AY%  rX   r  c                  2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r  i  r  c                $   > [         TU ]  U5        g rP   )r=   rn   rm   r   rN   s     r2   rn   ExactStrMatch.__init__  s    rX   c                p     UR                   nU R                   U:H  $ ! [         a    [        U5      n N&f = frP   )r  r   r?   rm   r   
_other_vals      r2   r   ExactStrMatch.match  s=    	$))J *,,  	$UJ	$s    55r.   )	rQ   rR   rS   rT   	__slots__rn   r   rU   rV   rW   s   @r2   r  r    s    I - -rX   r  c                  .   ^  \ rS rSrU 4S jrS rSrU =r$ )ExactLowerStrMatchi  c                @   > [         TU ]  UR                  5       5        g rP   r=   rn   lowerr  s     r2   rn   ExactLowerStrMatch.__init__      'rX   c                     UR                   nU R                   UR                  5       :H  $ ! [         a    [        U5      n N4f = frP   )r  r   r?   r  r  s      r2   r   ExactLowerStrMatch.match  sF    	$))J *"2"2"444  	$UJ	$s   + AAr.   )rQ   rR   rS   rT   rn   r   rU   rV   rW   s   @r2   r  r    s    (5 5rX   r  c                  ^   ^  \ rS rSrSrU 4S jrS r\S 5       r\S 5       r	U 4S jr
SrU =r$ )	GlobStrMatchi  )r  	_re_matchc                  > [         TU ]  U5        S U l         UR                  S5      (       a<  UR	                  S5      (       a&  [
        R                  " U5      R                  U l        g SU;   aP  [
        R                  " U5      R                  SS5      n[
        R                  " SU S35      R                  U l        g g ! [
        R                   a  n[        USU S	35      eS nAff = f)
N^$r   \*r   z^(?:)$)Contains an invalid regular expression. 'r   )r=   rn   r  r   r`  rJ  compiler   escaper   errorr   rm   r   rL   rN   s      r2   rn   GlobStrMatch.__init__  s    		$$)<)<!#E!2!8!8		%(00>!#tE7",=!>!D!D  xx 	"B1#QG 	s   AC +AC C+C&&C+c                     UR                   nU R                  (       a  U R                  U5      $ U R                   U:H  $ ! [         a    [        U5      n NHf = frP   )r  r   r?   r  r  s      r2   r   GlobStrMatch.match  sS    	$))J >>>>*--??j00  	$UJ	$s   ? AAc                8    U R                   c  U R                  $ S $ rP   )r  r  r   s    r2   r   GlobStrMatch.exact_value  s    "&.."8tBdBrX   c                     U R                   S:H  $ )Nr   r  r   s    r2   r   GlobStrMatch.matches_all  s    #%%rX   c                  > U R                   UR                   :X  a  U R                   $ U R                  (       d(  [        U[        5      (       a  UR                  (       a  Xp[	        U5      nSU;  aB  U R                  (       a"  U R                  U5      (       a  UR                   $ [
        TU ]  U5      $ U R                   R                  S5      UR                  S5      s=:X  a  S:X  a  O  OU R                   S   US   s=:X  a  S:X  d"  O  U R                   S   US   s=:X  a  S:X  a`  O  O]U R                   R                  S5      nUR                  S5      nX4;   a  UR                   $ XC;   a  U R                   $ [
        TU ]  U5      $ / nU R                   U4 H  nUR                  S5      (       a,  UR                  S5      (       a  UR                  USS 5        ME  SU;   a9  [        R                  " U5      R                  SS5      nUR                  U5        M  UR                  U5        M     S	US    S
US    S3$ )Nr   r   r   r   r  r  r  r   z^(?=z)(?:r  )r   r  r6   r  r?   r=   r4  countrM  r   r`  r   rJ  r  r   )rm   r   other_as_strself_strippedother_strippedpatternsr   rN   s          r2   r4  GlobStrMatch.merge  s   >>U__,>>!~~*UL"A"Aeoo4 5zl" ~~$..">">& w}U++  NN  %););C)@EAE^^A,q/8S8r"l2&6=#= NN005M)//4N.&.~~%7='' nnl3E$$)<)<a,		%(00>&& 4 x{m4}B77rX   r  )rQ   rR   rS   rT   r  rn   r   rF  r   r   r4  rU   rV   rW   s   @r2   r  r    sH    )I	1 C C & &@8 @8rX   r  c                  (   ^  \ rS rSrU 4S jrSrU =r$ )GlobLowerStrMatchi"  c                @   > [         TU ]  UR                  5       5        g rP   r  r  s     r2   rn   GlobLowerStrMatch.__init__#  r  rX   r.   )rQ   rR   rS   rT   rn   rU   rV   rW   s   @r2   r  r  "  s    ( (rX   r  c                  `   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 r\S
 5       rSrU =r$ )SplitStrMatchi'  r  c                B   > [         TU ]  U R                  U5      5        g rP   r=   rn   _convertr  s     r2   rn   SplitStrMatch.__init__*      u-.rX   c                     [        UR                  SS5      R                  S5      5      $ ! [         a    [	        U5      (       a  [        U5      s $ e f = f)Nr*   r   )rD  r   rv   r   r   r  s     r2   r  SplitStrMatch._convert-  sP    	U]]34::3?@@ 	%   ''	s   ), %AAc                     U=(       a    U R                   UR                   -  $ ! [         a!    U R                   U R                  U5      -  s $ f = frP   )r  r   r  r   s     r2   r   SplitStrMatch.match5  sH    	:?T__u/?/??? 	:??T]]5%999	:s   !$ (AAc                    U R                   (       a:  SR                  SR                  S [        U R                   5       5       5      5      $ g)Nz{{{}}}r+   c              3  .   #    U  H  nS U S 3v   M     g7fr   Nr.   )r/   r   s     r2   r3   )SplitStrMatch.__repr__.<locals>.<genexpr>=  s     ,W?V!q1X?V   zset())r  r   rD   r,  r   s    r2   r   SplitStrMatch.__repr__;  s3    ????499,Wvdoo?V,W#WXXrX   c                J    SR                  [        U R                  5      5      $ Nr*   rD   r,  r  r   s    r2   r   SplitStrMatch.__str__A  s    xxt/00rX   c                l    [        XR                  5      =(       a    U R                  UR                  :H  $ rP   r  r   s     r2   r   SplitStrMatch.__eq__E  r  rX   c                ,    [        U R                  5      $ rP   r  r   s    r2   r   SplitStrMatch.__hash__H  r  rX   c                    U R                   $ rP   r  r   s    r2   r   SplitStrMatch.exact_valueK  r  rX   r.   rQ   rR   rS   rT   r  rn   r  r   r   r   r   r   rF  r   rU   rV   rW   s   @r2   r  r  '  s@    I/:1Y%  rX   r  c                  `   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 r\S
 5       rSrU =r$ )FeatureMatchiP  r  c                B   > [         TU ]  U R                  U5      5        g rP   r  r  s     r2   rn   FeatureMatch.__init__S  r  rX   c                    U(       d
  [        5       $ [        U[        5      (       a8  [        S S UR                  SS5      R	                  S5       5        5       5      $ [        S S U 5        5       5      $ )Nc              3  8   #    U  H  nU(       d  M  Uv   M     g 7frP   r.   r/   r  s     r2   r3   (FeatureMatch._convert.<locals>.<genexpr>Z  s      RA Rs   	c              3  @   #    U  H  oR                  5       v   M     g 7frP   rM  r/   ffs     r2   r3   r  \  s     R/Q((**/Q   r*   r   c              3  6   #    U  H  o(       d  M  Uv   M     g 7frP   r.   r  s     r2   r3   r  `  s     J(D1QQ(Ds   
	c              3  @   #    U  H  oR                  5       v   M     g 7frP   r  r  s     r2   r3   r  `  s     (Deer	  )rD  r6   r?   r   rv   r  s     r2   r  FeatureMatch._convertV  sh    ;s## Ru}}S#/F/L/LS/QR   J(De(DJJJrX   c                B    U R                  U5      nU R                  U:H  $ rP   )r  r  r   s     r2   r   FeatureMatch.matchb  s    e$%''rX   c                v    SR                  SR                  S [        U R                  5       5       5      5      $ )Nr   r+   c              3  .   #    U  H  nS U S 3v   M     g7fr  r.   )r/   r0   s     r2   r3   (FeatureMatch.__repr__.<locals>.<genexpr>g  s     &Q9PA1#Qx9Pr  )r   rD   r,  r  r   s    r2   r   FeatureMatch.__repr__f  s)    }}TYY&Q9P&QQRRrX   c                J    SR                  [        U R                  5      5      $ r  r  r   s    r2   r   FeatureMatch.__str__i  s    xxt/00rX   c                l    [        XR                  5      =(       a    U R                  UR                  :H  $ rP   r  r   s     r2   r   FeatureMatch.__eq__l  r  rX   c                ,    [        U R                  5      $ rP   r  r   s    r2   r   FeatureMatch.__hash__o  r  rX   c                    U R                   $ rP   r  r   s    r2   r   FeatureMatch.exact_valuer  r  rX   r.   r  rW   s   @r2   r  r  P  sB    I/
K(S1Y%  rX   r  c                  :   ^  \ rS rSrU 4S jrS rS rS rSrU =r	$ )ChannelMatchiw  c                  > S U l          [        U[        5      (       a  UR                  S5      (       a<  UR	                  S5      (       a&  [
        R                  " U5      R                  U l         OVSU;   aE  [
        R                  " SR                  UR                  SS5      5      5      R                  U l         O[        U5      n[        [        U ]?  U5        g ! [
        R                   a  n[        USU S35      eS nAff = f)Nr  r  r   z^(?:{})$r   r  r   )r  r6   r?   r   r`  rJ  r  r   r   r   r   r  r   r=   r  rn   r  s      r2   rn   ChannelMatch.__init__x  s    	%%%##C((U^^C-@-@%'ZZ%6%<%<DNE\%'ZZ#**5==e+DE&e N $ENE 	lD*51 xx 	"B1#QG 	s%   A&C 1A
C <C D/C??Dc                    [        UR                  5      nU R                  (       a  U R                  UR                  5      $ U R                  R
                  UR
                  UR                  4;   $ ! [         a    [        U5      n Nrf = frP   )r   r  r   r  rn  r]   r  s      r2   r   ChannelMatch.match  su    	( !1!12J >>>>*";";<< ??''JOOZ=V=V+WWW  	( J	(s   A2 2B
	B
c                l     U R                   R                   $ ! [         a    U R                    s $ f = frP   )r  r]   r   r   s    r2   r   ChannelMatch.__str__  s6    	(oo**+, 	(oo&'	(s    33c                *    SU R                  5        S3$ )Nr   r   r   s    r2   r   ChannelMatch.__repr__  s    4<<>"!$$rX   r  )
rQ   rR   rS   rT   rn   r   r   r   rU   rV   rW   s   @r2   r  r  w  s    2(X(% %rX   r  c                      \ rS rSrS rSrg)CaseInsensitiveStrMatchi  c                     UR                   nUR                  5       nU R                  (       a  U R	                  U5      $ U R                   U:H  $ ! [         a    [        U5      n NXf = frP   )r  r   r?   r  r  r  s      r2   r   CaseInsensitiveStrMatch.match  sa    	$))J  %%'
>>>>*--??j00  	$UJ	$s   A A'&A'r.   N)rQ   rR   rS   rT   r   rU   r.   rX   r2   r&  r&    s    
1rX   r&  )	r[   r]   r^   r_   r`   ra   rb   rf   rg   )r^   r?   r_   z
str | Nonereturnr?   )KrC  
__future__r   rJ  rr  abcr   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   
common.urlr   r   r   
exceptionsr   r   r[   r   r^   r   r   r    ImportErrorauxlib.collectionrQ   ri  typer"   r7   rO  rR  rY  rg  ra  r@   r  r  r  r  r  r  r  r  r  r&  r  r.   rX   r2   <module>r>     s_   # 	  ' #      0 S " &   9 B B 5 5 6  2/% +:D +:\l
- l
^7>
 $ 4ntn !w  !F $-NN -	5 	5e8>> e8P( (
&N &R$> $N)%< )%X1/ 1 $"&-
]$  /./s   D= =EE