
    #jnD                   X   d Z ddlmZ ddlZddlZddlmZmZmZmZ ddl	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ erddlmZmZmZm Z  dd	l	m!Z! dd
l"m#Z# dgZ$ ed      Z%eee&f   Z' ede'      Z(dZ) G d dejT                        Z+d+dZ,	 	 	 	 	 	 d,dZ-d-dZ.d.dZ/d/dZ0d.dZ1	 	 	 	 	 	 	 	 d0dZ2d1dZ3d2dZ4d3dZ5d4dZ6d5dZ7d6dZ8	 	 	 	 	 	 d7dZ9d8d Z:d9d!Z;d:d"Z<d;d#Z=	 	 	 	 	 	 	 	 d<d$Z>	 	 	 	 	 	 d=d%Z?e)f	 	 	 	 	 	 	 	 	 d>d&Z@d?d'ZAd@d(ZBd.d)ZC G d* d      ZDy)Aa	  Public :class:`VersionRange` API.

A set-algebra view of the versions accepted by a
:class:`~packaging.specifiers.SpecifierSet`. Ranges support intersection,
union, complement, and difference; membership and filtering match the
originating specifier set; and conversion back to a
:class:`~packaging.specifiers.SpecifierSet` is available where a PEP 440 form
exists.

.. testsetup::

    from packaging.ranges import VersionRange
    from packaging.specifiers import SpecifierSet
    from packaging.version import Version
    )annotationsN)TYPE_CHECKINGAnyTypeVarUnion   )
FULL_RANGEMIN_VERSIONNEG_INFPOS_INFBoundaryKindBoundaryVersion
LowerBound
UpperBoundcoerce_versionfilter_by_rangesintersect_rangesleast_version_abovematches_bounds_onlyrange_is_emptyranges_are_prerelease_onlytrim_release)Version)CallableIterableIteratorSequence)Interval)SpecifierSetVersionRangeTUnparsedVersionVar)bound   c                  v    e Zd ZdZ ej
                         Z ej
                         Z ej
                         Zy)_SetOpzNThe binary set operation ``_combine_literals`` resolves over ``===`` literals.N)	__name__
__module____qualname____doc__enumautoINTERSECTIONUNION
DIFFERENCE     T/var/www/oz-panel.ru/ozpay-pub/venv/lib/python3.12/site-packages/packaging/ranges.pyr&   r&   K   s,    X499;LDIIKEJr1   r&   c                     t         S N)__all__r0   r1   r2   __dir__r6   S   s    Nr1   c                   | st        |      S |st        |       S g }dx}}|t        |       k  ro|t        |      k  ra| |   d   ||   d   k  r|j                  | |          |dz  }n|j                  ||          |dz  }|t        |       k  r|t        |      k  ra|j                  | |d        |j                  ||d        |d   g}|dd D ]  \  }}|d   \  }}	|	j                  %|j                  |	j                  |j                  kD  rd}
n|	j                  |j                  k(  r|	j
                  xs |j
                  }
nNt        |	j                  |	j
                         }t        |j                  |j
                         }t        ||      }
|
r|t        |	|      f|d<   |j                  ||f        |S )zUnion two sorted, non-overlapping interval lists.

    A linear merge over the two pre-sorted inputs followed by a single
    coalescing pass: adjacent or overlapping intervals collapse so the result
    is itself sorted and non-overlapping.
    r   r   NT)
listlenappendextendversion	inclusiver   r   r   max)leftrightmerged_input
left_indexright_indexmergedlowerupper
prev_lower
prev_upperoverlaps	gap_lower	gap_uppers                r2   _union_rangesrM   \   s    E{Dz#%L  J
s4y
 [3u:%=
A%"4Q"77Z 01!OJk 231K s4y
 [3u:%= Z[)*kl+,*1o.F$QR( *u!'
J &}}$!!EMM1H5==0!++>uH
 #:#5#5:;O;O7OPI"5==eoo2EFI%i;H$c*e&<=F2JMM5%.)-*0 Mr1   c                   | st        t              S g }d}| D ]  \  }}|E|j                  t        |j                  |j                         }|j                  t        |f       nUt        |j                  |j                         }t        |j                  |j                         }|j                  ||f       |} |J |j                  8t        |j                  |j                         }|j                  |t        f       |S )a  Complement a sorted, non-overlapping interval list.

    Yields the gaps between intervals plus a leading gap before the first and
    a trailing gap after the last. Bound inclusivity flips so that
    complement-of-complement round-trips back to the input.
    N)	r9   r	   r=   r   r>   r;   r   r   r   )rangesresultrI   rF   rG   rL   rK   s          r2   _complement_rangesrQ      s     JF$(J u }}(&u}}%//6IJ	w	23":#5#5:;O;O7OPI"5==eoo2EFI MM9i01
!& !!!%z11z7K7K3KL	y'*+Mr1   c                    | s| S | d   \  }}t        t        |      r| dd S |j                  r<t        |j                  t
              r"|j                  t        k  rt        |fg| dd S | S )ae  Collapse the PEP 440 floor in a sorted interval list.

    Only the first interval can touch ``0.dev0`` (the minimum version). An
    inclusive lower at or below it admits everything below, the same as
    ``-inf``, so ``>=0.dev0`` becomes the one canonical full range. An
    exclusive upper at or below it leaves the interval empty, so it is dropped.
    r   r   N)r   r   r>   
isinstancer=   r   r
   )boundsrF   rG   s      r2   _canonical_floorrU      sp     !9LE5gu%abz 	u}}g.MM[(% .6!":..Mr1   c                   | j                   yd}| j                  `| j                   dk(  rQ| j                  E| j                  \  }}|dk\  rt        | j	                  ||dz
  fd      t
        j                        }n| j                   dk\  r8t        | j	                  | j                   dz
        t
        j                        }nw| j                   dk(  rh| j                  \| j                  dk(  r| j	                  dd      n| j	                  | j                  dz
  d      }t        |t
        j                        }|t        |      | k(  r|S y)a  The boundary whose least successor is *version*, or ``None``.

    Inverse of :func:`~packaging._ranges.least_version_above`. A plain version
    that is exactly such a successor (``1.0a2.dev0`` sits just above
    ``AFTER_POSTS(1.0a1)``) folds back to that boundary, so ``>=1.0a2.dev0`` and
    ``>1.0a1`` share one form. The proposed boundary is confirmed by
    round-tripping through ``least_version_above``.
    Nr   r   )predevrX   postrX   )	rX   rW   r[   r   __replace__r   AFTER_POSTSAFTER_LOCALSr   )r=   	candidatekindnumberbases        r2   _predecessor_boundaryrc      s;    {{(,I{{7;;!#38L{{fQ;'##vz(:#E((I 
	#GKK!O4l6O6O
	 
	gll6 ||q  Tt4$$',,*:$E 	
 $D,*C*CD	!4Y!?7!Jr1   c                   g }| D ]  \  }}||}}t        |j                  t              r0|j                  r$t	        |j                        }|t        |d      }t        |j                  t              r0|j                  s$t	        |j                        }|t        |d      }|j                  ||f        t        |      S )a  Fold least-successor bounds to their boundary form.

    ``>=1.0a2.dev0`` and ``>1.0a1`` denote the same set, so both must reduce to
    one representation for ``==`` and ``hash`` to agree. An inclusive lower or
    exclusive upper sitting on a boundary's least successor becomes that
    boundary; the engine's emptiness check has already dropped the synthetic
    gaps such intervals would otherwise leave.
    Fr>   T)	rS   r=   r   r>   rc   r   r   r;   tuple)rT   rP   rF   rG   	new_lower	new_upperboundarys          r2   _canonicalizerj      s      F .u$e9	emmW-%//,U]];H#&x5A	emmW-eoo,U]];H#&x4@	y),-. =r1   c                N    t        |      }||xr	 | t        k(  S t        | |      S )a  True when the bounds (plus arbitrary admission) admit ``literal``.

    Skips the explicit admit/reject sets, which the caller layers on top. A
    non-version string matches via ``admit_arbitrary`` only on full bounds;
    on narrower bounds the flag is metadata only.
    )r   r	   r   )rT   admit_arbitraryliteralparseds       r2   _struct_admitsro     s0     G$F~76Z#77vv..r1   c                    t        | t              r&| j                   d| j                  j                   dS t        |       S )z?Printout for a bound's inner value, kind-tagged for boundaries.[])rS   r   r=   r`   namestr)values    r2   _bound_version_strrv   +  s6    %)--%**//!2!44u:r1   c                n    | j                   y| j                  rdnd}| t        | j                          S )Nz(-infrq   (r=   r>   rv   r#   brackets     r2   _format_lowerr|   2  s6    }}__c#GY)%--89::r1   c                n    | j                   y| j                  rdnd}t        | j                          | S )Nz+inf)rr   )ry   rz   s     r2   _format_upperr   9  s5    }}__c#G /0	::r1   c                2    dj                  d | D              S )zARender a sorted interval list as ``lower, upper | lower, upper``. | c              3  T   K   | ]   \  }}t        |       d t        |        " yw), N)r|   r   ).0rF   rG   s      r2   	<genexpr>z$_format_intervals.<locals>.<genexpr>B  s0      >JeU=
 =#7"89s   &()join)	intervalss    r2   _format_intervalsr   @  s     :: NW  r1   c                    | j                   dk(  xr. | j                  du xr | j                  du xr | j                  du S )zFTrue when version is exactly ``X[.Y]*.dev0`` (the shape ``<X`` makes).r   N)rX   rW   r[   local)r=   s    r2   _is_dev0_versionr   R  sJ     	q 	"KK4	"LLD 	" MMT!	r1   c                   | j                   dk7  s| j                  | j                  y| j                  4| j                  dk  ryd| j	                  | j                  dz
  d       gS t        | j                        }|d   }|dk  ryg |dd |dz
  }t        j                  | j                  |      }| j                  dk(  rt        |      sd| d	gS d
| d| d	gS )ae  A prerelease-free spelling for an inclusive ``[version`` lower, or ``None``.

    Several ``[V`` lowers come from an operator whose own spelling carries no
    synthetic ``.dev0``. Recovering that spelling gives the range an empty opt-in
    region, so it is offered in the prerelease-free spelling mode (see
    :meth:`VersionRange.to_specifier_set`).
    r   Nr   >rZ   r8   epochrelease!=.*>=)rX   rW   r   r[   r\   r   r   r   
from_partsr   any)r=   familylastbelow_releasebelows        r2   _clean_lowerr   \  s     {{a7;;2gmm6O ||<<!G''W\\A-=4'HIJKK '//*F":Dax,fSbk,4!8,MW]]MJE }}#m"4UG2LBugR.))r1   c                   | j                   }t        |t              rG|j                  t        j
                  k7  ry|j                   }|j                  y|j                  dz   }n0t        |t              r| j                  r|j                  dk7  ryd}ny|j                  dk(  ry|j                  |j                  |j                  yt        t        |j                              ryt        j                   |j                  dd      }t#        |d      }||kD  ryt        j                   |j                  d      }||||k(  fS )	a  The ``E!0`` family of a lower sitting on an epoch>0 zero-family floor.

    An epoch>0 zero-family base such as ``1!0.dev0`` has no ``>=P,!=P.*`` spelling
    since no version sorts below ``E!0`` within the epoch. While the interval
    stays within ``==E!0.*`` it is that wildcard, trimmed by the upper and with a
    leading ``.dev`` run excluded: an ``AFTER_LOCALS(E!0.dev(k))`` lower drops
    ``E!0.dev0..E!0.dev(k)``, a plain inclusive ``E!0.dev0`` lower drops none.
    Returns the ``E!0`` family, how many leading ``.dev`` releases to exclude, and
    whether the upper sits at the family cap (so ``==E!0.*`` needs no upper), else
    ``None``.
    Nr   r   )r   )r   r   rX   Fr   r   )r=   rS   r   r`   r   r^   rX   r   r>   r   rW   r[   r   r   r   r   r   r   )rF   rG   r=   excluded_devsnext_familycapr   s          r2   _epoch_floor_lowerr     s    mmG'?+<<<444//;;a	GW	%%// ;;! }}{{',,":gmm>W
<() $$7==$ANK
[%
(Cs{gmmTBF=%3,..r1   c                    | t         k  rg S t        |       }||S | j                  ,| j                  dk(  r| j	                  dd      }d| d| gS y)aB  Prerelease-free fragments for ``[family, ..)``, or ``None`` if it has none.

    ``family`` is an ``X.dev0``. The floor gives ``[]`` (every version); a release
    base its ``_clean_lower`` family-floor spelling (``!=0.*`` ...); an ``X.post0``
    base ``>=X,!=X``. A pre-release base has no prerelease-free spelling.
    Nr   rZ   r   r   )r
   r   rW   r[   r\   )r   cleanrb   s      r2   _dev_family_anchorr     sj     	 EzzfkkQ.!!t!6TFr$[))r1   c                v   | j                   }|g S t        |t              r|j                  t        j
                  k(  rd|j                    gS |j                   }|t        k  rd| gS |s|j                  s|j                  d      }t        |      }|r|j                  dz   t        kD  ryt        |j                  dz         D cg c]  }d|j                  |        }}||z   S t        |      }|t        |      nd}	|	|	S d| d| gS | j                  sy|st        |      }	|	|	S d| gS c c}w )a  Encode a lower bound as specifier fragments, or ``None``.

    ``[]`` for ``-inf``. An ``AFTER_POSTS(V)`` lower is ``>V``. An
    ``AFTER_LOCALS(V)`` lower is the set ``[successor, ..)`` and emits ``>=V,!=V``,
    except in the prerelease-free spelling mode (``keep_dev0`` false), where it
    recovers a spelling with no synthetic ``.dev0`` when one exists:
    ``>3.8.post1`` for a post release, or a dev family's anchor plus the dev run
    up to V for a ``.dev`` release.
    Nr   r   r   rY   r   r   )r=   rS   r   r`   r   r]   r
   rX   r\   r   _MAX_EXCLUSION_RUNranger   r   r>   )
rF   	keep_dev0lower_versioninnerr   anchordrun	successorr   s
             r2   _encode_lowerr     s|    MMM	-1!9!99--./00%%K L>! yy$
 **q*1+F3%yy1}'99#BG		TUBV=>"V//A/678C  "C<' 0>	3<3HY/d$ L
 UG5'l++?? ]+L !!3s   D6c                   | j                   }|g S t        |t              r|j                  t        j
                  k(  r[|j                   }|sG|j                  ;|j                  /|j                  #d|j                  |j                  dz          gS d| gS t        |      }|d| gS y| j                  sO|j                  dk(  r6|j                  *|j                  |sd|j                  d       gS d| gS d| d| gS y)	a4  Encode an upper bound as specifier fragments, or ``None``.

    ``[]`` for ``+inf``. In the prerelease-free spelling mode (``keep_dev0``
    false) the ``<X`` spelling is used for the ``X.dev0`` upper that ``<X``
    builds; otherwise the synthetic ``.dev0`` is kept so the range opts its
    bounds in.
    N<r   )r[   z<=r   rY   r   )r=   rS   r   r`   r   r^   rW   r[   rX   r\   r   r>   r   )rG   r   upper_versionr   r   s        r2   _encode_upperr     s<    MMM	-1 !:!::!))EII%JJ*II%
 E--5::>-BCDEEL>! (6	 	{O$$??
 "!!)##+M55$5?@ABB'((]O$=/&:;;r1   c                   t        | j                  t              st        |j                  t              ry| j                  |j                  y| j                  r|j                  ryt	        | j                        rt	        |j                        sy| j                  j
                  |j                  j
                  k7  ryt        | j                  j                        }t        |j                  j                        }t        t        |      t        |            }|dkD  sJ |d|t        |      z
  z  z  }|d|t        |      z
  z  z  }|dd |dd k7  ry|d   |d   dz   k7  ry| j                  j                  |d      S )z;If ``[lower, upper)`` is the ``==V.*`` shape, return ``V``.Nr   r   r8   r   )r   rX   )rS   r=   r   r>   r   r   r   r   r?   r:   r\   )rF   rG   lower_releaseupper_releasepadded_lengths        r2   _detect_equal_wildcardr   8  sR   %--1Z6 }} 5??eooU]]+0@0O}}emm111 !6!67M !6!67MM*C,>?M1T]S-??@@MT]S-??@@MSb]3B//
 RM"-11==$$]$EEr1   c                  
 | j                   |j                   t        | j                   t              sqt        |j                   t              sW| j                  rK|j                  r?| j                   |j                   k(  r&| j                   j                  d| j                    gS t        | j                   t
              r| j                  r|j                  rtt        |j                   t              rZ|j                   j                  t        j                  k(  r3|j                   j                   | j                   k(  rd| j                    gS t        | |      }|d| dgS |st        | |      nd}|^|\  
}}|t        kD  ryd
 dg}|j                  
fdt        |      D               |s t        ||      }|y|j                  |       |S t        | |      }	|	yt        ||      }|y|	|z   S )a  Encode one interval as specifier fragments, or ``None``.

    Special-cases the ``==V`` singleton (``[V, AFTER_LOCALS(V)]`` for a plain
    ``V``, and ``[V+local, V+local]`` for a local one) and the ``==V.*`` shape
    so the fragment is one equality rather than a bound pair.
    Nz==r   c              3  H   K   | ]  }d j                  |         ywr   rY   Nr\   )r   r   r   s     r2   r   z#_encode_interval.<locals>.<genexpr>  s'     T!r&,,,345T   ")r=   rS   r   r>   r   r   r`   r   r^   r   r   r   r<   r   r   r   )rF   rG   r   wildcardfloorr   upper_at_cappartsupper_partslower_partsr   s             @r2   _encode_intervalr   Z  s    	!MM%5==/:5==/:OOOOMMU]]*MM+U]]O$%%
 	5=='*OOOOu}}o6MM,";";;MM!!U]]2U]]O$%%%eU3HXJb!"" 5>ue,4E.3+|--fXR!Tu]?STT 'y9K"LL%y1Ky1K$$r1   c                v   t        | j                  t              rt        | j                        }|&y| j                  | j                  ry| j                  }t        |j                  t              s7|j                  *|j                  s|j                  |k(  r|j
                  |gS y|j                  j                  t        j                  k7  ry|j                  j                  }||k(  r|gS t        t        |t        j                              j                  |j                  |j                  j                  k\  rt|j                  j                        k(  rU|j                  j                  z
  dz   t        kD  ryfdt        j                  |j                  dz         D        }|g|S y)a  If the gap between two intervals is a ``!=V`` chain, list its points.

    A plain exclusive left upper names the first excluded V directly; an inclusive
    boundary left upper names it via its least successor. Adjacent exclusions
    (``V`` and its immediate successors) share a single gap spanning a contiguous
    dev run, so one gap can name a short chain: ``!=1.0,!=1.0.post0.dev0`` is one
    gap from ``1.0`` up to ``AFTER_LOCALS(1.0.post0.dev0)``.
    NrY      c              3  B   K   | ]  }j                  |         yw)rY   Nr   )r   r   seconds     r2   r   z$_detect_not_equal.<locals>.<genexpr>  s     RQv!!a!(Rs   r   )rS   r=   r   r   r>   r   r`   r   r^   rX   r\   r   r   )
left_upperright_lowerfirstr   r   r   s        @r2   _detect_not_equalr     s    *$$o6 $J$6$67=				#z';';""k))?;+))##u,'7N<#<#<< &&D}w !8Q8Q!RSFJJ"HH HH

",6 88fjj 1$'99R%

DHHqL2QR}}r1   c           
        d}|t        |       k  rF|t        |      k  r8| |   ||   k(  r-|dz  }|t        |       k  r|t        |      k  r| |   ||   k(  r-t        |       |dz   kD  ry| d| }t        |       |kD  r| |   nd}||   }||z
  }||kD  ryt        ||      D 	cg c]  }	t        j                  |g ||	        }
}	t        |      |dz   k(  r|
S t	        g |||||t        |d      z
        }|y|
|z   S c c}	w )a  Decompose the gap ``[L.dev0, U.dev0)`` into wildcard prefixes.

    ``lower_trim``/``upper_trim`` are trimmed release tuples with
    ``lower_trim < upper_trim`` lexicographically. The chain sweeps at the
    first differing level. The gap is undecomposable when L has trailing
    components below that level (the chain cannot escape L's subtree), or when
    the chain, summed across levels, would exceed ``budget`` prefixes.
    r   r   Nr   )r:   r   r   r   _decompose_dev0_gapr?   )
lower_trim
upper_trimr   budgetdiffcommon	lower_val	upper_valspansegment	fragmentstails               r2   r   r     sX    Ds:3z?"t
4 00		 	s:3z?"t
4 00 :!F$'
Od$:
4 I4 Iy Df} Y	2 	0B&0B'0BCI 
 :$(" &)j%#dA,1FD |t#s   !#Dc                   t        | |      }||D cg c]  }d| 	 c}S | j                  }t        |t              r| j                  st        |      sy|j                  }t        |t              r|j                  r|d}t        }nt        |t              r|j                  t        j                  k(  rf|j                  sZ|j                  }|j                  |j                  dz   t        kD  ry|j                  d      |j                  dz   }t        |z
  }nyt              sy|j                  j                  k7  s|k\  ryt        t        |j                         t        j                         |j                  |      }	|	y|	D 
cg c]  }
d|
 d
 }}
|j#                  fdt%        |      D               |S c c}w c c}
w )a;  Encode the gap between two adjacent intervals as ``!=`` fragments.

    A point chain becomes ``!=V`` fragments and a dev0 family span becomes
    ``!=P.*`` prefixes, followed by a leading dev run in the last family when
    the gap ends inside it. Any other gap has no exclusion form and returns
    ``None``.
    Nr   r   r   rY   r   c              3  H   K   | ]  }d j                  |         ywr   r   )r   r   
upper_dev0s     r2   r   z_encode_gap.<locals>.<genexpr>R  s'     Vq:11a189:Vr   )r   r=   rS   r   r>   r   r   r   r`   r   r^   rX   r\   r   r   r   r   r<   r   )r   r   pointspointleft_vright_v
run_lengthr   rG   prefixesprefix
exclusionsr   s               @r2   _encode_gapr     s    z;7F*01"UG11 Fvw''!!G'7#(=(=

#7O,LLL555%%
 99		A0B B&&1&-
YY]
#j0 J'||z'''6Z+?"V^^$Z''(	H 089fBvhb/9J9VE*DUVVi 2d :s   GGc                    g }t        dt        |             D ]2  }t        | |dz
     d   | |   d         }| y|j                  |       4 |S )a  Encode every between-interval gap as ``!=`` fragments, or ``None``.

    When each gap has an exclusion spelling, the intervals fuse into one
    contiguous span (``==1.* | ==3.*`` is ``!=0.*,!=2.*,<4``): the outer
    interval across all the bounds plus these exclusions. A gap with no
    exclusion spelling makes the bounds a disjoint union, which no single
    set expresses.
    r   r   N)r   r:   r   r<   )rT   r   indexgaps       r2   _encode_gapsr   V  sd     Jq#f+& &+A.ua0@A;#	 r1   c                    | d   \  }}|j                   }t        |t              rM|j                  sA|j                  s5|j
                  )t        |j                  d      d      }g | dd ||fS | S )a  Snap the range's final upper out of the pre-release band ``False`` drops.

    An exclusive upper at a final ``V`` admits the versions in ``[V.dev0, V)`` at
    the bounds level, but a ``prereleases=False`` policy filters them all out, so
    it accepts the same releases as ``<V`` (upper at ``V.dev0``). Snapping it lets
    :meth:`VersionRange.to_specifier_set` reach the ``<V`` spelling.

    Only the last interval's upper is snapped, the one that gives a terser outer
    bound. Inner uppers are left alone: snapping one turns its gap to the next
    interval into a ``.dev0`` wildcard gap, which a far-apart neighbour would blow
    up into an unbounded ``!=N.*`` chain. Those shapes recover as ``None`` here,
    the same as under ``None`` / ``True``. The snap is conservative (it skips
    boundary, pre-release, and local uppers); the caller keeps it only when it
    stays release-equivalent, so an unsnapped shape falls back to the exact form.
    r8   Nr   rY   Fre   )r=   rS   r   r>   is_prereleaser   r   r\   )rT   rF   rG   r=   s       r2   _tighten_no_prereleasesr   j  sw      ":LE5mmG7G$%%MM!7..1.5G--uen--Mr1   c                     e Zd ZU dZdZded<   ded<   ded<   ded	<   ded
<   ded<   d9dZe e        e       dfddd	 	 	 	 	 	 	 	 	 	 	 	 	 d:d       Z	d;dZ
d;dZd;dZd<dZd=dZ	 	 	 	 	 	 d>dZeddd?d       Zeddd	 	 	 	 	 d@d       Zedd	 	 	 	 	 dAd       ZdBdZdBd ZdCd!ZdBd"Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 dDd#ZdEd$ZdFd%ZdFd&ZdCd'ZdFd(ZdGd)ZdGd*ZdGd+ZdGd,Z e!jD                  	 	 dH	 	 	 	 	 	 	 dId-       Z#e!jD                  	 	 dH	 	 	 	 	 	 	 dJd.       Z#	 	 dK	 	 	 	 	 	 	 dLd/Z#	 	 	 	 	 	 	 	 	 	 	 	 dMd0Z$edNd1       Z%dOd2Z&e'd;d3       Z(	 	 dK	 	 	 	 	 	 	 dPd4Z)dQd5Z*dRd6Z+dSd7Z,dTd8Z-y)Ur    a  A set of :class:`~packaging.version.Version` values accepted by a
    :class:`~packaging.specifiers.SpecifierSet`.

    Construct via :meth:`~packaging.specifiers.SpecifierSet.to_range`, or with
    the :meth:`full`, :meth:`empty`, and :meth:`singleton` class methods.
    Compose with :meth:`intersection`, :meth:`union`, :meth:`complement`, and
    :meth:`difference` (or the ``&`` / ``|`` / ``~`` / ``-`` operators). Test
    membership with ``in`` or :meth:`contains`, filter an iterable with
    :meth:`filter`, and convert back to a
    :class:`~packaging.specifiers.SpecifierSet` with :meth:`to_specifier_set`.

    The configured pre-release policy of the originating specifier set carries
    onto the range and controls whether pre-releases are admitted under ``in``,
    :meth:`contains`, and :meth:`filter`. With no configured policy,
    :meth:`filter` also admits pre-releases in the autodetected opt-in region
    (the versions a pre-release-naming specifier asked for). Set algebra keeps
    that opt-in scoped to those versions, so unrelated pre-releases are not
    admitted wholesale.

    :meth:`intersection`, :meth:`union`, :meth:`difference`, and the
    :meth:`is_subset` / :meth:`is_superset` / :meth:`is_disjoint` predicates
    require both operands to share the same configured policy.

    >>> r = SpecifierSet(">=1.0,<2.0").to_range()
    >>> "1.5" in r
    True
    >>> "2.0" in r
    False
    >>> SpecifierSet(">=2.0,<1.0").to_range().is_empty
    True

    PEP 440's ``===`` operator matches a candidate string verbatim
    (case-insensitive) rather than a set of versions. Ranges built from
    ``===`` specifiers still support membership, set operations, and conversion
    back to a :class:`~packaging.specifiers.SpecifierSet`; matching follows the
    literal-equality rule. A ``===`` literal that names a pre-release is
    admitted under the default policy by both :meth:`contains` and
    :meth:`filter`, since it was named outright.

    .. versionadded:: 26.3
    )_admit_admit_arbitrary_bounds_pre_region_prereleases_configured_rejecttuple[Interval, ...]r   boolr   frozenset[str]r   r   r   bool | Noner   c                    t        d      )Nzcannot create 'VersionRange' instances directly; use SpecifierSet.to_range(), VersionRange.full(), VersionRange.empty(), or VersionRange.singleton() instead)	TypeError)clsargskwargss      r2   __new__zVersionRange.__new__  s    H
 	
r1   Fr0   N)
pre_regionprereleases_configuredc               ^   t              |r|r||z
  }|rt        fd|D              }|rt        fd|D              }t        j                  |       }|_        ||_        ||_        |_        ||_        ||s	d|_	        |S t        t        t        |                  |_	        |S )a  Internal factory; bypasses :meth:`__new__`.

        Canonicalizes the bounds so equal version sets share one representation,
        then drops admit literals the bounds already admit and reject literals
        the bounds do not match anyway. Reject wins over admit on overlap. The
        pre-release policy is set here and never reassigned afterwards;
        ``pre_region`` is canonicalized like the bounds and clipped to them,
        or dropped when a configured policy makes it inert.
        c              3  <   K   | ]  }t        |      s|  y wr4   ro   r   rm   rl   rT   s     r2   r   z&VersionRange._build.<locals>.<genexpr>  s%      %fowG    c              3  <   K   | ]  }t        |      r|  y wr4   r  r  s     r2   r   z&VersionRange._build.<locals>.<genexpr>  s%      !&/7C r  r0   )rj   	frozensetobjectr   r   r   r   r   r   r   rf   r   )r   rT   admitrejectrl   r   r   instances    `  `   r2   _buildzVersionRange._build  s    ( v&VFNE $ E
  % F >>#&!!$3!+A( "-Z#%H  	 $) z!:FC$H  r1   c                Z    t        | j                        xs t        | j                        S r4   )r   r   r   selfs    r2   _has_literalszVersionRange._has_literals%  s    DKK 6D$66r1   c                D    | j                   xr | j                  t        k(  S )as  True when ``_admit_arbitrary`` actually admits non-version strings.

        The flag rides through set algebra but only fires admission on full
        bounds. Intersection and difference drop it when the bounds shrink, so
        away from full bounds it survives only on empty-bounds ranges, where
        it keeps ``~~full() == full()`` and union idempotent.
        )r   r   r	   r  s    r2   _arbitrary_activezVersionRange._arbitrary_active(  s     $$C)CCr1   c                b    | j                          xr | j                   xr | j                  duS )zTrue when membership is decided by ``_bounds`` alone, enabling the
        bounds-only fast paths in :meth:`is_subset` and :meth:`is_disjoint`.
        F)r  r   r   r  s    r2   	_is_plainzVersionRange._is_plain2  s<    
 ""$$ :))):,,E9	
r1   c                    t        |t              s!t        dt        |      j                         | j
                  |j
                  k7  r%t        d| j
                  d|j
                        y)z<Refuse combining ranges with different pre-release policies.zexpected VersionRange, got zJCannot combine VersionRange operands with different pre-release policies: z and N)rS   r    r   typer'   r   
ValueErrorr  others     r2   _check_policy_compatz!VersionRange._check_policy_compat<  sy    %.9$u+:N:N9OPQQ''5+H+HH))-)E)E(H I4479  Ir1   c                    |j                   s| j                   S | j                   s|j                   S t        t        | j                   |j                               S )a  Union of ``self`` and ``other``'s opt-in regions.

        Used by :meth:`union` and :meth:`intersection`; :meth:`_build` clips the
        merge to the result bounds. A configured operand carries an empty region,
        so it contributes nothing to the merge.
        )r   rf   rM   r  s     r2   _merged_regionzVersionRange._merged_regionG  sN       ###$$$ ]4#3#3U5F5FGHHr1   c                   | j                  | j                  | j                  | j                  | j                  ||      S )zFA structural copy of this range carrying the given pre-release policy.r  r  rl   r   r   )r
  r   r   r   r   )r  r   
configureds      r2   _with_policyzVersionRange._with_policyY  s>     {{LL++<< 11!#-  
 	
r1   prereleasesc               (    | j                  d|      S )zReturn the empty range. No version satisfies it.

        >>> VersionRange.empty().is_empty
        True
        >>> "1.0" in VersionRange.empty()
        False
        r0   r   )r
  )r   r   s     r2   emptyzVersionRange.emptyf  s     zz"[zAAr1   T)rl   r   c               2    | j                  t        ||      S )ah  Return the full range. Every PEP 440 version satisfies it.

        ``admit_arbitrary=False`` restricts the range to PEP 440 versions only
        (matching the same versions as ``SpecifierSet(">=0.dev0").to_range()``);
        its complement is :meth:`empty`. The flag propagates through set algebra
        and is part of equality. Default ``True`` so that ``r & full()``
        preserves ``r``'s own flag structurally.

        >>> "1.0" in VersionRange.full()
        True
        >>> "wat" in VersionRange.full()
        True
        >>> "wat" in VersionRange.full(admit_arbitrary=False)
        False
        )rl   r   )r
  r	   )r   rl   r   s      r2   fullzVersionRange.fullq  s#    & zz+#.  
 	
r1   c                   t        |t              st        |      }t        |d      }t        |d      }| j	                  t        ||ff      |      S )a   Return the strict singleton range ``{version}``.

        Built as the closed interval ``[version, version]`` with strict
        equality. ``Specifier("==V")`` matches ``V+local`` too, so the strict
        singleton is narrower:

        >>> "1.0+local" in VersionRange.singleton("1.0")
        False
        >>> "1.0+local" in SpecifierSet("==1.0").to_range()
        True

        :raises packaging.version.InvalidVersion: if version is a string that
            does not parse as a PEP 440 version.
        Tr"  )rS   r   r   r   r
  rU   )r   r=   r   rF   rG   s        r2   	singletonzVersionRange.singleton  sZ    $ '7+g&G7D)7D) zzuen./#.  
 	
r1   c                   | j                  |       | j                  }t        t        | j                  |j                              }| j                  |      }| j                  xr |j                  xr t        |      }| j                         s%|j                         s| j                  ||||      S | j                  ||t        j                  |||      S )au  Range containing exactly the versions in both self and other.

        Both operands must share the same configured pre-release policy;
        otherwise :exc:`ValueError` is raised.

        >>> a = SpecifierSet(">=1.0").to_range()
        >>> b = SpecifierSet("<2.0").to_range()
        >>> a.intersection(b) == SpecifierSet(">=1.0,<2.0").to_range()
        True
        rl   r   r   oprl   r   r   )r  r   rf   r   r   r  r   r   r  r
  _combine_literalsr&   r-   r  r  r  
new_bounds
new_regioncombined_arbs         r2   intersectionzVersionRange.intersection  s     	!!%(11
+DLL%--HI
((/
 !!Qe&<&<QjAQ 	 !!#E,?,?,A;; ,%'1	    %%""(!#- & 
 	
r1   c                .   | j                  |       | j                  }t        t        | j                  |j                              }| j                  |      }|rI| j                  xr t        | j                        xs# |j                  xr t        |j                        }n| j                  xs |j                  }| j                         s%|j                         s| j                  ||||      S | j                  ||t        j                  |||      S )a  Range containing every version in self or other.

        Both operands must share the same configured pre-release policy;
        otherwise :exc:`ValueError` is raised.

        >>> a = VersionRange.singleton("1.0")
        >>> b = VersionRange.singleton("2.0")
        >>> "1.0" in a.union(b) and "2.0" in a.union(b)
        True
        >>> "1.5" in a.union(b)
        False
        r)  r*  )r  r   rf   rM   r   r  r   r   r  r
  r,  r&   r.   r-  s         r2   unionzVersionRange.union  s    	!!%(11
=u}}EF
((/

  11Hd4<<6H &&>4+> 
  00JE4J4JL!!#E,?,?,A;; ,%'1	    %%||(!#- & 
 	
r1   c                    | j                  t        t        | j                              | j                  | j
                  | j                  d| j                        S )a  Range containing every version not in self.

        Preserves the configured pre-release policy. On the version set, double
        negation holds for a range with no ``===`` literals (the arbitrary-string
        flag round-trips, so ``~~full() == full()``); for ``===`` ranges
        complement is one-way. The opt-in region is not restored (see below).

        The opt-in region is dropped: a complement is an exclusion, and an
        exclusion expresses no pre-release preference. This is what lets
        ``a & ~b`` shed ``b``'s opt-in, so an excluded ``b`` never force-admits a
        pre-release into the result. Complement stays involutive on the version
        set, but not on the opt-in region: ``~~r`` covers the same versions as
        ``r`` yet force-admits none of its pre-releases.

        >>> r = SpecifierSet(">=1.0").to_range()
        >>> "0.5" in r.complement()
        True
        >>> "1.5" in r.complement()
        False
        >>> r.complement().complement() == r
        True
        r0   r  )r
  rf   rQ   r   r   r   r   r   r  s    r2   
complementzVersionRange.complement  sO    2 {{$T\\23,,;; 11#'#?#?  
 	
r1   c                   | j                  |       |j                  s|j                  s| S t        t	        | j                  t        |j                                    }d}| j                  | j                  }| j                  xr || j                  k(  }| j                         s/|j                         s| j                  |||| j                        S | j                  ||t        j                  ||| j                        S )a8  Range containing the versions in self but not in other.

        Matches ``self & ~other`` on the version set and the opt-in region;
        ``other`` acts as a bounds-only exclusion that grants no opt-in. The
        arbitrary-string flag survives only when ``other`` removed no versions:
        a difference that shrinks the bounds forgets it, as ``self & ~other``
        would, so no later widening union can revive it. They still part on
        ``===`` literals, whose complement is one-way: a ``===`` literal stays
        when ``self`` admits it and ``other`` does not. Both operands must
        share the same configured pre-release policy (as :meth:`intersection`
        and :meth:`union` require); otherwise :exc:`ValueError` is raised.
        ``a - empty()`` returns a range equal to ``a``.

        >>> a = SpecifierSet(">=1.0").to_range()
        >>> b = SpecifierSet(">=2.0").to_range()
        >>> "1.5" in a.difference(b)
        True
        >>> "2.0" in a.difference(b)
        False
        >>> a.difference(VersionRange.empty()) == a
        True
        r0   r)  r*  )r  r   r   rf   r   rQ   r   r   r   r  r
  r,  r&   r/   )r  r  r.  r/  r0  s        r2   
differencezVersionRange.difference#  s    . 	!!%( }}U\\K T\\+=emm+LM

 ,.
''/))J ,,Kt||1K!!#E,?,?,A;; ,%'+'C'C	    %%  (!#'#?#? & 
 	
r1   c                  t               }t               }| j                  | j                  z  |j                  z  |j                  z  D ]  }	| j                  |	      }
|j                  |	      }|t        j
                  u r|
xr |}n |t        j                  u r|
xs |}n|
xr | }|r|j                  |	       r|j                  |	        | j                  |t        |      t        |      |||      S )zGResolve admit/reject for ``self`` ``op`` ``other`` over their literals.r  )
setr   r   _matches_literalr&   r-   r.   addr
  r  )r  r  r.  r+  rl   r   r   admitsrejectsrm   self_inother_inwants                r2   r,  zVersionRange._combine_literalsd  s     5E {{T\\1ELL@5==P 	%G++G4G--g6HV(((+8v||#*(/x<

7#G$	%  {{F#W%+!#9  
 	
r1   c                    || j                   v ry|| j                  v ryt        |      }|| j                         S t	        | j
                  |      S )z=Whether literal (case-folded) matches this range's predicate.FT)r   r   r   r  r   r   )r  rm   rn   s      r2   r:  zVersionRange._matches_literal  sO    dll"dkk!(>))++"4<<88r1   c                P    t        |t              st        S | j                  |      S )z(Operator alias for :meth:`intersection`.)rS   r    NotImplementedr1  r  s     r2   __and__zVersionRange.__and__  s#    %.!!  ''r1   c                P    t        |t              st        S | j                  |      S )z!Operator alias for :meth:`union`.)rS   r    rC  r3  r  s     r2   __or__zVersionRange.__or__  s!    %.!!zz%  r1   c                "    | j                         S )z&Operator alias for :meth:`complement`.)r5  r  s    r2   
__invert__zVersionRange.__invert__  s      r1   c                P    t        |t              st        S | j                  |      S )z&Operator alias for :meth:`difference`.)rS   r    rC  r7  r  s     r2   __sub__zVersionRange.__sub__  s!    %.!!u%%r1   c                0   | j                  |       | j                         r|j                         sy| j                         r:|j                         r*t        | j                  t        |j                               S | j                  |      j                  S )a  Return whether every member of self is also a member of other.

        On versions and ``===`` literals this is
        ``self.difference(other).is_empty``: subtracting other leaves nothing
        behind. A live arbitrary admission (the flag at full bounds) is only a
        subset of another live one.

        Both operands must share the same configured pre-release policy;
        otherwise :exc:`ValueError` is raised.

        >>> inner = SpecifierSet(">=1.5,<1.8").to_range()
        >>> outer = SpecifierSet(">=1.0,<2.0").to_range()
        >>> inner.is_subset(outer)
        True
        >>> outer.is_subset(inner)
        False
        >>> VersionRange.empty().is_subset(outer)
        True
        F)r  r  r  r   r   rQ   r7  is_emptyr  s     r2   	is_subsetzVersionRange.is_subset  sx    ( 	!!%( !!#E,C,C,E >> 1'6H6WXXX u%...r1   c                F    | j                  |       |j                  |       S )a  Return whether every member of other is also a member of self.

        The mirror of :meth:`is_subset`: ``a.is_superset(b)`` is
        ``b.is_subset(a)``.

        Both operands must share the same configured pre-release policy;
        otherwise :exc:`ValueError` is raised.

        >>> outer = SpecifierSet(">=1.0,<2.0").to_range()
        >>> outer.is_superset(SpecifierSet(">=1.5,<1.8").to_range())
        True
        )r  rM  r  s     r2   is_supersetzVersionRange.is_superset  s!     	!!%(t$$r1   c                    | j                  |       | j                         r1|j                         r!t        | j                  |j                         S | j	                  |      j
                  S )a  Return whether self and other share no member.

        Equivalent to ``(self & other).is_empty``.

        Both operands must share the same configured pre-release policy;
        otherwise :exc:`ValueError` is raised.

        >>> a = SpecifierSet(">=1.0,<2.0").to_range()
        >>> a.is_disjoint(SpecifierSet(">=2.0,<3.0").to_range())
        True
        >>> a.is_disjoint(SpecifierSet(">=1.5,<2.5").to_range())
        False
        )r  r  r   r   r1  rL  r  s     r2   is_disjointzVersionRange.is_disjoint  sV     	!!%( >> 1'emmDDD  '000r1   c                r    | j                  |      j                  xr |j                  |       j                  S )a  Whether self and other admit the same non-pre-release versions.

        Used by :meth:`to_specifier_set` under a ``prereleases=False`` policy,
        where pre-releases are unobservable: the symmetric difference is empty
        exactly when the two ranges accept the same releases. Both operands
        carry that policy, so the difference below reads emptiness through it.
        )r7  rL  r  s     r2   _same_releaseszVersionRange._same_releases  s/     u%..R53C3CD3I3R3RRr1   c                     y r4   r0   r  iterabler   keys       r2   filterzVersionRange.filter  s     (+r1   c                     y r4   r0   rU  s       r2   rX  zVersionRange.filter	  s     r1   c                <   d}|| j                   }| j                  }| j                         }| j                  sP| j                  sD|sB|r'|| j
                  k(  rt        | j
                  ||d      S t        | j
                  ||||      S | j                  |||||      S )a  Yield items from iterable whose version falls inside the range.

        With prereleases ``None`` the PEP 440 default applies: pre-releases are
        buffered and only emitted if no final release in iterable is in range,
        except that a pre-release inside the autodetected opt-in region, or named
        outright by a ``===`` literal, is force-admitted in place (as
        ``prereleases=True`` would yield it). A flushed buffer comes after
        every in-place yield, so the output is not version-sorted.

        The signature mirrors
        :meth:`~packaging.specifiers.SpecifierSet.filter`.

        >>> r = SpecifierSet(">=1.0,<2.0").to_range()
        >>> list(r.filter(["0.9", "1.5", "2.0"]))
        ['1.5']
        r0   T)r   r   r  r   r   r   r   _filter_with_admission)r  rV  r   rW  regionarbitrary_actives         r2   rX  zVersionRange.filter  s    , (* 66K%%F113{{4<<8H
 &DLL0'hTJJ#DLL(CfUU**c;(8&
 	
r1   c              #  V   K    j                    j                  d fd}|du r|D ]  } ||      \  }}	}	|s|  y|du r*|D ]$  } ||      \  }}
}	|s|
|
j                  r!| & yg }g }d}|D ]  } ||      \  }}
}|s|
*|r| n"|j                  |       |j                  |       >|
j                  s#|s|E d{    |j	                          d}| m|s|rt        ||
      r| |r|j                  |        |s|E d{    yy7 T7 w)zFilter for ranges with admit/reject literals or live arbitrary
        admission (including the universal ``SpecifierSet("")`` range).c                    | n |       }t        |      j                         }r|v ryr|v rdt        |      dfS t        |      }|d dfS t        j                  |      syd|dfS )N)FNFTF)rt   rF   r   r   r   )	itemraw	raw_lowerrn   	admit_setr]  rW  
reject_setr  s	       r2   r  z2VersionRange._filter_with_admission.<locals>.admitH  s    ),#d)CC(Ii:5)Y)3^C0$66#C(F~'u44&t||V<)&&r1   TNF)r`  r   returnz!tuple[bool, Version | None, bool])r   r   r   r;   clearr   )r  rV  rW  r   r]  r\  r  r`  ok_rn   all_nonfinalarbitrary_stringsfound_final
by_literalrc  rd  s   ` ` `          @@r2   r[  z#VersionRange._filter_with_admission;  sz     KK	\\
	' 	'" $   ;AqJ %   %dFA%&*>*>
  #%') 	*D%*4["B
~J%,,T2 ''-''"000%++-"&K

 f)<VV)L
##D);	*> ### ! 1" $s0   :D)BD)D%2D)D)D'D)'D)c           	        |s| j                         }n|j                  s3| j                  t        t	        |j                                           }n| j                         }|D ]  }|j                  dk(  r6| j                  dt        |j                  j                         h            }n2| j                  t        t	        |j                                           }|j                  |      } g }|j                  R|D ]M  }|j                  dk7  s|j                  s t        t	        |j                                     }t        ||      }O |j                  t	        |      |j                        S )aa  Build the range accepted by ``specifier_set``.

        Friend constructor for :meth:`~packaging.specifiers.SpecifierSet.to_range`.
        The intersection of every specifier in the set: an empty set yields the
        full range, an unsatisfiable set yields the empty range, and ``===``
        specifiers contribute literal-string admission.
        )rT   ===r0   )rT   r  )r   r  )r%  _has_arbitraryr
  rU   rf   _get_rangesoperatorr  r=   rF   
_to_rangesr1  _prereleasesr   rM   r  )r   specifier_setrP   specoperandr\  spec_boundss          r2   _from_specifier_setz VersionRange._from_specifier_set  sX    XXZF--ZZ'm.G.G.I(JK   F XXZF% 	6==E)!jj!DLL4F4F4H3I)J ) G "jj/doo6G0HI ) G  ,,W5	6 "$%%-% @==E)d.>.>"259J3K"LK*6;?F	@ ""V}$11 # 
 	
r1   c                `   ddl m}m} | j                  }| j                  ry| j
                  r| j                  t        k7  ry| j                  r
 |d|      S | j                  s.t        | j                        dk7  ry| j                  \  }d| g}n| j                  ry| j                  t        k(  r| j
                  rdndg}n| j                  g}|d	u r5t        | j                        }|| j                  k7  r|j                  |       g }|D ]]  }t        |      }	|	d
D ]H  }
t        |d   d   |d   d   |
      }|dj                  ||	z         }||vs8|j                  |       J _ |du xr | j                   | j                  k(  }d}d}|D ]  }|g}|r|j                  |r| dnd       |D ]i  }	  |||      }t        |      t        t#        |            f}|||k\  r5|j%                         }|| k(  xs |d	u xr | j'                  |      }|sf||}}k  |S # |$ r Y ww xY w)a	  Return a :class:`~packaging.specifiers.SpecifierSet` matching the same
        versions as self, or ``None`` if no single set expresses it.

        PEP 440 has no syntax for the strict singleton ``{V}`` (an exclusive
        plain-version bound), a disjoint union of two or more intervals, or a
        partial pre-release opt-in region, so ranges built by set algebra often
        return ``None``. A gap that takes more than ``_MAX_EXCLUSION_RUN``
        contiguous ``!=`` exclusions to spell returns ``None`` too,
        rather than a pathologically long chain; reaching that cap takes either
        set algebra or a specifier set that already spells the gap out with
        over a hundred contiguous ``!=N.*`` exclusions. An empty range maps to
        ``SpecifierSet("<0")``, unless it still carries the arbitrary-string
        flag (which no set reproduces), and a full range that admits arbitrary
        strings maps to ``SpecifierSet("")``.

        A range built from a :class:`~packaging.specifiers.SpecifierSet`
        re-encodes, short of that exclusion cap. The result is the simplest
        candidate whose own
        :meth:`~packaging.specifiers.SpecifierSet.to_range` reproduces self
        exactly (bounds, ``===`` literals, and the opt-in region are all part of
        equality), so it filters the same versions. Two cases relax that
        exactness without changing what is filtered: an empty range recovers as
        the canonical empty range (same versions, none, but not self's bounds),
        and under a ``prereleases=False`` policy the result need only match self's
        releases, so ``(-inf, 3.14)`` recovers as the tighter ``<3.14`` rather
        than ``!=3.14,<=3.14``.

        Each call encodes a handful of candidate spellings and keeps the
        simplest one that verifies, where verifying means parsing the candidate
        and round-tripping it through
        :meth:`~packaging.specifiers.SpecifierSet.to_range`. The work grows
        with the number of intervals and exclusions in the range, and the
        result is not cached, so convert once and reuse the returned set rather
        than converting per candidate version in a hot loop.

        >>> str(SpecifierSet(">=1.0,<2.0").to_range().to_specifier_set())
        '<2.0,>=1.0'
        >>> str(SpecifierSet("==1.0").to_range().to_specifier_set())
        '==1.0'
        >>> VersionRange.singleton("1.5").to_specifier_set() is None
        True
        r   )InvalidSpecifierr   Nz<0r  rn   z>=0.dev0F)FTr   r8   ,)r   r   z	,>=0.dev0)
specifiersrz  r   r   r   r   r   r	   rL  r:   r   r   r;   r   r   r   r   rt   to_rangerS  )r  rz  r   r  rm   baseslayouts	tightenedlayoutr   r   outerrb   	add_floorbestbest_key
candidatesspec_str	recoveredrW  r_   matchess                         r2   to_specifier_setzVersionRange.to_specifier_set  so   V 	?11
<<  T\\Z%?==  *==||4;;1$JW7)_%E[[\\Z'00RjAE ||nGU"3DLLA	,NN9- E! +)&1
%!. +I,VAYq\6":a=)TE} 88EJ$67D5(T*++" $&K4+;+;t||+K	 %) 	4DJ!!TF)"4*M& 4 ,X: NI 9~s3y>':;#x &..0	#t+ %'JD,?,?	,J  %.(D14	4> % ( s   9
H%%H-,H-c                    | j                         ry| j                  du }| j                  D ]  }|rt        |      }||j                  r y | j
                  sy|xr t        | j
                        S )a  ``True`` if no version or string satisfies this range.

        Agrees with :meth:`~packaging.specifiers.SpecifierSet.is_unsatisfiable`,
        including the pre-release policy: a range whose only members are
        pre-releases is empty when that policy excludes them.

        >>> SpecifierSet(">=2,<1").to_range().is_empty
        True
        >>> SpecifierSet(">=1,<2").to_range().is_empty
        False
        >>> SpecifierSet("==1.0a1", prereleases=False).to_range().is_empty
        True
        FT)r  r   r   r   r   r   r   )r  excludes_prereleasesrm   rn   s       r2   rL  zVersionRange.is_emptyP  sy    " !!##;;uD{{ 	G#'0%&*>*>	 ||#P(B4<<(PPr1   c                   t        |t        t        f      s!t        dt	        |      j
                         t        |t              r|nd}|r|t        |      }|r||j                  rd}|| j                  n|}| j                  s| j                  rUt        |      j                         }|| j                  v ry|| j                  v r|du rt        |      }||j                  ryyt        |t              s!|t        |      }|| j                         S |}|du r|j                  ryt        | j                  |      S )aI  Return whether item is contained in this range.

        :param item: a version string or :class:`~packaging.version.Version`.
        :param prereleases: whether to match pre-releases. ``None`` (default)
            uses the range's own policy.
        :param installed: when ``True``, accept a pre-release item even if the
            range would not otherwise allow it.

        Unlike :meth:`filter`, this does not consult the autodetected pre-release
        opt-in region; it reads only the configured policy. This mirrors
        :meth:`~packaging.specifiers.SpecifierSet.contains` versus
        :meth:`~packaging.specifiers.SpecifierSet.filter`.

        Unparsable strings do not match, except where the full
        ``SpecifierSet`` would also match: the full range admits any string,
        and a ``===`` range admits items equal to the literal
        case-insensitively.

        >>> r = SpecifierSet(">=1.0,<2.0").to_range()
        >>> r.contains("1.5")
        True
        >>> r.contains("2.0")
        False

        :raises TypeError: if item is not a str or Version.
        z5VersionRange.contains() expected str or Version, got NTF)rS   rt   r   r   r  r'   r   r   r   r   r   rF   r  r   r   )r  r`  r   	installedrn   effective_preitem_strliteral_parseds           r2   containszVersionRange.containsq  s?   @ $g/Dz**+- 
 *4D')B#D)F+0D0DK -8,?D(([ 	 ;;$,,4y(H4<<'4;;& E)%3H%=N%1n6R6R$$(~'-~--//DE!d&8&8"4<<66r1   c                $    | j                  |      S )zReturn whether item is contained in this range.

        Forwards to :meth:`contains` with default arguments.

        >>> "1.5" in SpecifierSet(">=1.0,<2.0").to_range()
        True
        )r  )r  r`  s     r2   __contains__zVersionRange.__contains__  s     }}T""r1   c                n   t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  xrj | j
                  |j
                  k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S )a  Structural equality.

        Compares the bounds, the ``===`` admit/reject literals, the
        arbitrary-string flag, the configured pre-release policy, and the
        opt-in region, not just the version set. Keying on the region makes
        equality a congruence (equal ranges stay equal under further operations),
        so equal implies same :meth:`contains` and :meth:`filter`, but not the
        converse: an empty range keeps the flag it was built with, so two empty
        ranges need not be equal.

        Different specifiers for the same range fold to one canonical form:

        >>> SpecifierSet(">1.0a1").to_range() == SpecifierSet(">=1.0a2.dev0").to_range()
        True

        The opt-in region is part of equality, so ``<=1.0`` (no pre-releases) and
        ``<1.0.post0.dev0`` (autodetects a ``.dev`` opt-in) cover the same
        versions yet compare unequal:

        >>> le, lt = SpecifierSet("<=1.0"), SpecifierSet("<1.0.post0.dev0")
        >>> le.to_range() == lt.to_range()
        False

        >>> r = SpecifierSet(">=1.0,<2.0").to_range()
        >>> r == SpecifierSet(">=1.0,<2.0").to_range()
        True
        )	rS   r    rC  r   r   r   r   r   r   r  s     r2   __eq__zVersionRange.__eq__  s    8 %.!!LLEMM) 6u||+6-6 %%)?)??6 ,,0M0MM	6
   E$5$55	
r1   c                    t        | j                  | j                  | j                  | j                  | j
                  | j                  f      S r4   )hashr   r   r   r   r   r   r  s    r2   __hash__zVersionRange.__hash__  sD    %%,,  	
 		
r1   c                t   g }| j                   r$|j                  t        | j                                | j                  r9|j                  ddj	                  t        | j                              z   dz          |rdj	                  |      nd}| j                  r*| ddj	                  t        | j                               d}d}| j                  r|dz  }| j                  |d	| j                   z  }| j                  r|d
t        | j                        z  }d| j                  j                   d|| dS )a<  Human-readable representation for debugging.

        >>> SpecifierSet(">=1.0,<2.0").to_range()
        <VersionRange '[1.0, 2.0.dev0)'>
        >>> SpecifierSet("").to_range()
        <VersionRange '(-inf, +inf)' arbitrary>
        >>> SpecifierSet(">=2.0,<1.0").to_range()
        <VersionRange '(empty)'>
        {r   }r   z(empty)z \ {r{  z
 arbitraryz pre=z pre-region=r    r   )r   r;   r   r   r   sortedr   r   r   r   	__class__r'   )r  r   bodyr   s       r2   __repr__zVersionRange.__repr__  s    <<LL*4<<89;;LLtyy)<==CD$)uzz% y <<V6$))F4<<,@"A!B"ED   L D''3eD889::Dl#4T5E5E#F"IJJD4>>**+1THTF!<<r1   )r   r  r   r  re  r    )rT   r   r  r   r  r   rl   r   r   r   r   r   re  r    )re  r   )r  r    re  None)r  r    re  r   )r   r   r  r   re  r    )r   r   re  r    )rl   r   r   r   re  r    )r=   Version | strr   r   re  r    )r  r    re  r    )re  r    )r  r    r.  r   r+  r&   rl   r   r   r   r   r   re  r    )rm   rt   re  r   )r  r  re  r    )r  r    re  r   )N.)rV  zIterable[UnparsedVersionVar]r   r   rW  r  re  zIterator[UnparsedVersionVar])rV  zIterable[T]r   r   rW  zCallable[[T], UnparsedVersion]re  zIterator[T])NN)rV  Iterable[Any]r   r   rW  %Callable[[Any], Version | str] | Nonere  Iterator[Any])rV  r  rW  r  r   r   r]  r   r\  r   re  r  )rt  r   re  r    )re  zSpecifierSet | None)r`  r  r   r   r  r   re  r   )r`  r  re  r   )r  r  re  r   )re  int)re  rt   ).r'   r(   r)   r*   	__slots____annotations__r   classmethodr  r
  r  r  r  r  r  r  r#  r%  r'  r1  r3  r5  r7  r,  r:  rD  rF  rH  rJ  rM  rO  rQ  rS  typingoverloadrX  r[  rx  r  propertyrL  r  r  r  r  r  r0   r1   r2   r    r      s   (TI "!  
  &% )(
  !*!* %6 ,..26$6 6 	6
 6 )6 !,6 
6 6p7D
	I$
1
?J
	
 15 B B (,
!%
;F
	
 
0 CG
#
5@
	
 
<'
R-
^ 
D?
B&
&
 )&

 &
 &
 )&
 !,&
 
&
P
9(!!&!/F%"1*S __ $(	+.+ !+ 	+
 
&+ + __ $(.1	 ! ,	
 
  $(59	(
(
 !(
 3	(

 
(
TU$U$ 3U$ !	U$
 U$ %U$ 
U$n *
 *
XOb Q QF $(!%	D7D7 !D7 	D7
 
D7L#%
N

=r1   )re  z	list[str])r@   Sequence[Interval]rA   r  re  list[Interval])rO   r  re  r  )rT   r   re  r   )r=   r   re  zBoundaryVersion | None)rT   r   rl   r   rm   rt   re  r   )ru   zBoundaryVersion | Versionre  rt   )r#   r   re  rt   )r#   r   re  rt   )r   r  re  rt   )r=   r   re  r   )r=   r   re  list[str] | None)rF   r   rG   r   re  z tuple[Version, int, bool] | None)r   r   re  r  )rF   r   r   r   re  r  )rG   r   r   r   re  r  )rF   r   rG   r   re  zVersion | None)rF   r   rG   r   r   r   re  r  )r   r   r   r   re  list[Version] | None)
r   tuple[int, ...]r   r  r   r  r   r  re  r  )r   r   r   r   re  r  )rT   r  re  r  )Er*   
__future__r   r+   r  r   r   r   r   _rangesr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r=   r   collections.abcr   r   r   r   r   r}  r   r5   r!   rt   UnparsedVersionr"   r   Enumr&   r6   rM   rQ   rU   rc   rj   ro   rv   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r0   r1   r2   <module>r     s    #       $ FF!( 
CL%1I   TYY 4
44 4n%P2&R6/ /37/BE/	/&;;$ *F././(./%./b$>"B2jFDA%A%(A%59A%A%N::)3::B %	222 2 	2
 2j@F(:L= L=r1   