dolor.versions

Version handling.

class Version(name, proto=- 1, *, check_supported=False)[source]

Bases: object

A version of Minecraft.

Parameters
  • name (str or int or Version or None) –

    If str, then the version’s name.

    If int, then the version’s protocol version. The name of the version will be looked up using name_from_proto().

    If Version, the name and proto attributes will be copied.

    If None, then it will behave as if you had passed latest() as name.

  • proto (int, optional) – The version’s protocol version. If unspecified, it will look up the protocol version from supported_versions.

  • check_supported (bool, optional) – Whether or not to check if the version is supported. Will be ignored if name is None.

name

The version’s name.

Type

str

proto

The version’s protocol version.

Type

int

supported_versions

A chronologically-ordered dictionary with version names as keys and the corresponding protocol version as values.

Type

dict

classmethod latest()[source]

Gets the latest supported version.

Returns

The latest supported version.

Return type

Version

classmethod name_from_proto(proto)[source]

Gets the version name corresponding to the protocol version.

Parameters

proto (int) – The protocol version.

Returns

The corresponding version name.

Return type

str

Raises

ValueError – If no corresponding version name can be found.

__eq__(other)[source]

Checks whether a version is equal to another.

Parameters

other (Version or str) – The other version.

Returns

Whether the version is equal to other.

Return type

bool

Examples

>>> from dolor.versions import Version
>>> Version("1.16.4") == Version("1.16.4")
True
>>> Version("1.16.4") == "1.16.4"
True
>>> Version("1.16.4") == "1.15.2"
False
__gt__(other)[source]

Checks whether a version is greater than another.

Parameters

other (Version or str) – The other version.

Returns

Whether the version is greater than other.

Return type

bool

Examples

>>> from dolor.versions import Version
>>> Version("1.16.4") > Version("1.15.2")
True
>>> Version("1.16.4") > "1.15.2"
True
>>> Version("1.15.2") > "1.16.4"
False
__lt__(other)[source]

Checks whether a version is less than another.

Parameters

other (Version or str) – The other version.

Returns

Whether the version is less than other.

Return type

bool

Examples

>>> from dolor.versions import Version
>>> Version("1.15.2") < Version("1.16.4")
True
>>> Version("1.15.2") < "1.16.4"
True
>>> Version("1.16.4") < "1.15.2"
False
class VersionRange(start, stop)[source]

Bases: object

A range of versions.

A version is contained in the range when it is greater than or equal to start and less than stop. In more mathematical terms, the range is [start, stop), just like the builtin range.

Parameters
  • start (Version or str or None) – The lower bound of the range. If None, then start will not be checked when seeing if a version is contained in the range.

  • stop (Version or str or None) – The upper bound of the range. If None, then stop will not be checked when seeing if a version is contained in the range.

Examples

>>> from dolor.versions import VersionRange
>>> "1.16" in VersionRange("1.15.2", "1.16.4")
True
>>> "1.16" in VersionRange(None, "1.16.4")
True
>>> "1.16" in VersionRange("1.15.2", None)
True
>>> "1.16" in VersionRange(None, None)
True
>>> "1.16" in VersionRange("1.16.2", "1.16.4")
False
>>> "1.15.2" in VersionRange("1.15.2", "1.16.4")
True
>>> "1.16.4" in VersionRange("1.15.2", "1.16.4")
False
class VersionSwitcher(switch)[source]

Bases: object

A class to simplify getting different values based on different versions.

Parameters

switch (dict) –

A dictionary whose keys can be:

  • A function which takes one argument (the version) and returns a bool.

  • A str which is the version’s name.

  • A container (checked with is_container()) which contains versions.

  • None, whose value will be the default if no other key fits a version.

Examples

>>> from dolor.versions import VersionSwitcher, VersionRange
>>> switcher = VersionSwitcher({
...     (lambda v: v == "1.16.4"): 0,
...     "1.16.3": 1,
...     VersionRange("1.16", "1.16.3"): 2,
...     None: 4,
... })
>>> switcher["1.16.4"]
0
>>> switcher["1.16.3"]
1
>>> switcher["1.16.1"]
2
>>> switcher["1.15.2"]
4
get(version)[source]

Gets the appropriate value for the version.

__getitem__(version)[source]

Does the same as get().