dolor.versions¶
Version handling.
- class Version(name, proto=- 1, *, check_supported=False)[source]¶
Bases:
objectA version of Minecraft.
- Parameters
name (
strorintorVersionorNone) –If
str, then the version’s name.If
int, then the version’s protocol version. The name of the version will be looked up usingname_from_proto().If
Version, thenameandprotoattributes will be copied.If
None, then it will behave as if you had passedlatest()asname.proto (
int, optional) – The version’s protocol version. If unspecified, it will look up the protocol version fromsupported_versions.check_supported (
bool, optional) – Whether or not to check if the version is supported. Will be ignored ifnameisNone.
- 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
- 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 (
Versionorstr) – 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 (
Versionorstr) – 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 (
Versionorstr) – 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:
objectA range of versions.
A version is contained in the range when it is greater than or equal to
startand less thanstop. In more mathematical terms, the range is [start,stop), just like the builtinrange.- Parameters
start (
VersionorstrorNone) – The lower bound of the range. IfNone, then start will not be checked when seeing if a version is contained in the range.stop (
VersionorstrorNone) – The upper bound of the range. IfNone, 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:
objectA class to simplify getting different values based on different versions.
- Parameters
switch (
dict) –A dictionary whose keys can be:
A
functionwhich takes one argument (the version) and returns abool.A
strwhich 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