Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
packaging.specifiers.Specifier Class Reference
Inheritance diagram for packaging.specifiers.Specifier:
Inheritance graph
[legend]
Collaboration diagram for packaging.specifiers.Specifier:
Collaboration graph
[legend]

Public Member Functions

None __init__ (self, str spec="", bool|None prereleases=None)
 
bool prereleases (self)
 
None prereleases (self, bool value)
 
str operator (self)
 
str version (self)
 
str __repr__ (self)
 
str __str__ (self)
 
int __hash__ (self)
 
bool __eq__ (self, object other)
 
bool __contains__ (self, str|Version item)
 
bool contains (self, UnparsedVersion item, bool|None prereleases=None)
 
Iterator[UnparsedVersionVar] filter (self, Iterable[UnparsedVersionVar] iterable, bool|None prereleases=None)
 

Public Attributes

 version
 

Protected Member Functions

tuple[str, str] _canonical_spec (self)
 
CallableOperator _get_operator (self, str op)
 
bool _compare_compatible (self, Version prospective, str spec)
 
bool _compare_equal (self, Version prospective, str spec)
 
bool _compare_not_equal (self, Version prospective, str spec)
 
bool _compare_less_than_equal (self, Version prospective, str spec)
 
bool _compare_greater_than_equal (self, Version prospective, str spec)
 
bool _compare_less_than (self, Version prospective, str spec_str)
 
bool _compare_greater_than (self, Version prospective, str spec_str)
 
bool _compare_arbitrary (self, Version prospective, str spec)
 

Protected Attributes

 _prereleases
 
 _spec
 
 _canonical_spec
 

Static Protected Attributes

str _operator_regex_str
 
str _version_regex_str
 
 _regex
 
dict _operators
 

Detailed Description

This class abstracts handling of version specifiers.

.. tip::

    It is generally not required to instantiate this manually. You should instead
    prefer to work with :class:`SpecifierSet` instead, which can parse
    comma-separated version specifiers (which is what package metadata contains).

Constructor & Destructor Documentation

◆ __init__()

None packaging.specifiers.Specifier.__init__ (   self,
str   spec = "",
bool | None   prereleases = None 
)
Initialize a Specifier instance.

:param spec:
    The string representation of a specifier which will be parsed and
    normalized before use.
:param prereleases:
    This tells the specifier if it should accept prerelease versions if
    applicable or not. The default of ``None`` will autodetect it from the
    given specifiers.
:raises InvalidSpecifier:
    If the given specifier is invalid (i.e. bad syntax).

Member Function Documentation

◆ __contains__()

bool packaging.specifiers.Specifier.__contains__ (   self,
str | Version  item 
)
Return whether or not the item is contained in this specifier.

:param item: The item to check for.

This is used for the ``in`` operator and behaves the same as
:meth:`contains` with no ``prereleases`` argument passed.

>>> "1.2.3" in Specifier(">=1.2.3")
True
>>> Version("1.2.3") in Specifier(">=1.2.3")
True
>>> "1.0.0" in Specifier(">=1.2.3")
False
>>> "1.3.0a1" in Specifier(">=1.2.3")
False
>>> "1.3.0a1" in Specifier(">=1.2.3", prereleases=True)
True

◆ __eq__()

bool packaging.specifiers.Specifier.__eq__ (   self,
object  other 
)
Whether or not the two Specifier-like objects are equal.

:param other: The other object to check against.

The value of :attr:`prereleases` is ignored.

>>> Specifier("==1.2.3") == Specifier("== 1.2.3.0")
True
>>> (Specifier("==1.2.3", prereleases=False) ==
...  Specifier("==1.2.3", prereleases=True))
True
>>> Specifier("==1.2.3") == "==1.2.3"
True
>>> Specifier("==1.2.3") == Specifier("==1.2.4")
False
>>> Specifier("==1.2.3") == Specifier("~=1.2.3")
False

Reimplemented from packaging.specifiers.BaseSpecifier.

◆ __hash__()

int packaging.specifiers.Specifier.__hash__ (   self)
Returns a hash value for this Specifier-like object.

Reimplemented from packaging.specifiers.BaseSpecifier.

◆ __repr__()

str packaging.specifiers.Specifier.__repr__ (   self)
A representation of the Specifier that shows all internal state.

>>> Specifier('>=1.0.0')
<Specifier('>=1.0.0')>
>>> Specifier('>=1.0.0', prereleases=False)
<Specifier('>=1.0.0', prereleases=False)>
>>> Specifier('>=1.0.0', prereleases=True)
<Specifier('>=1.0.0', prereleases=True)>

◆ __str__()

str packaging.specifiers.Specifier.__str__ (   self)
A string representation of the Specifier that can be round-tripped.

>>> str(Specifier('>=1.0.0'))
'>=1.0.0'
>>> str(Specifier('>=1.0.0', prereleases=False))
'>=1.0.0'

Reimplemented from packaging.specifiers.BaseSpecifier.

◆ contains()

bool packaging.specifiers.Specifier.contains (   self,
UnparsedVersion  item,
bool | None   prereleases = None 
)
Return whether or not the item is contained in this specifier.

:param item:
    The item to check for, which can be a version string or a
    :class:`Version` instance.
:param prereleases:
    Whether or not to match prereleases with this Specifier. If set to
    ``None`` (the default), it uses :attr:`prereleases` to determine
    whether or not prereleases are allowed.

>>> Specifier(">=1.2.3").contains("1.2.3")
True
>>> Specifier(">=1.2.3").contains(Version("1.2.3"))
True
>>> Specifier(">=1.2.3").contains("1.0.0")
False
>>> Specifier(">=1.2.3").contains("1.3.0a1")
False
>>> Specifier(">=1.2.3", prereleases=True).contains("1.3.0a1")
True
>>> Specifier(">=1.2.3").contains("1.3.0a1", prereleases=True)
True

Reimplemented from packaging.specifiers.BaseSpecifier.

◆ filter()

Iterator[UnparsedVersionVar] packaging.specifiers.Specifier.filter (   self,
Iterable[UnparsedVersionVar]  iterable,
bool | None   prereleases = None 
)
Filter items in the given iterable, that match the specifier.

:param iterable:
    An iterable that can contain version strings and :class:`Version` instances.
    The items in the iterable will be filtered according to the specifier.
:param prereleases:
    Whether or not to allow prereleases in the returned iterator. If set to
    ``None`` (the default), it will be intelligently decide whether to allow
    prereleases or not (based on the :attr:`prereleases` attribute, and
    whether the only versions matching are prereleases).

This method is smarter than just ``filter(Specifier().contains, [...])``
because it implements the rule from :pep:`440` that a prerelease item
SHOULD be accepted if no other versions match the given specifier.

>>> list(Specifier(">=1.2.3").filter(["1.2", "1.3", "1.5a1"]))
['1.3']
>>> list(Specifier(">=1.2.3").filter(["1.2", "1.2.3", "1.3", Version("1.4")]))
['1.2.3', '1.3', <Version('1.4')>]
>>> list(Specifier(">=1.2.3").filter(["1.2", "1.5a1"]))
['1.5a1']
>>> list(Specifier(">=1.2.3").filter(["1.3", "1.5a1"], prereleases=True))
['1.3', '1.5a1']
>>> list(Specifier(">=1.2.3", prereleases=True).filter(["1.3", "1.5a1"]))
['1.3', '1.5a1']

Reimplemented from packaging.specifiers.BaseSpecifier.

◆ operator()

str packaging.specifiers.Specifier.operator (   self)
The operator of this specifier.

>>> Specifier("==1.2.3").operator
'=='

◆ prereleases() [1/2]

bool packaging.specifiers.Specifier.prereleases (   self)
Whether or not pre-releases as a whole are allowed.

This can be set to either ``True`` or ``False`` to explicitly enable or disable
prereleases or it can be set to ``None`` (the default) to use default semantics.

Reimplemented from packaging.specifiers.BaseSpecifier.

◆ prereleases() [2/2]

None packaging.specifiers.Specifier.prereleases (   self,
bool  value 
)
Whether or not pre-releases as a whole are allowed.

This can be set to either ``True`` or ``False`` to explicitly enable or disable
prereleases or it can be set to ``None`` (the default) to use default semantics.

Reimplemented from packaging.specifiers.BaseSpecifier.

◆ version()

str packaging.specifiers.Specifier.version (   self)
The version of this specifier.

>>> Specifier("==1.2.3").version
'1.2.3'

Member Data Documentation

◆ _operator_regex_str

str packaging.specifiers.Specifier._operator_regex_str
staticprotected
Initial value:
= r"""
(?P<operator>(~=|==|!=|<=|>=|<|>|===))
"""

◆ _operators

dict packaging.specifiers.Specifier._operators
staticprotected
Initial value:
= {
"~=": "compatible",
"==": "equal",
"!=": "not_equal",
"<=": "less_than_equal",
">=": "greater_than_equal",
"<": "less_than",
">": "greater_than",
"===": "arbitrary",
}

◆ _regex

packaging.specifiers.Specifier._regex
staticprotected
Initial value:
= re.compile(
r"^\s*" + _operator_regex_str + _version_regex_str + r"\s*$",
re.VERBOSE | re.IGNORECASE,
)

The documentation for this class was generated from the following file: