miska 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
miska-0.0.1/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2023-2024 Dmitry Burmistrov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
20
+
21
+ Except as contained in this notice, the name(s) of the above copyright holders
22
+ shall not be used in advertising or otherwise to promote the sale, use or other
23
+ dealings in this Software without prior written authorization.
miska-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.1
2
+ Name: miska
3
+ Version: 0.0.1
4
+ Summary: An exceptional library
5
+ Author-email: Dima Burmistrov <pyctrl.dev@gmail.com>
6
+ License: Copyright (c) 2023-2024 Dmitry Burmistrov
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+
26
+ Except as contained in this notice, the name(s) of the above copyright holders
27
+ shall not be used in advertising or otherwise to promote the sale, use or other
28
+ dealings in this Software without prior written authorization.
29
+
30
+ Project-URL: Homepage, https://gitlab.com/pyctrl/miska
31
+ Project-URL: Bug Tracker, https://gitlab.com/pyctrl/miska/-/issues
32
+ Keywords: misc,miska
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Development Status :: 4 - Beta
37
+ Classifier: Intended Audience :: Developers
38
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
39
+ Requires-Python: >=3.11
40
+ Description-Content-Type: text/x-rst
41
+ License-File: LICENSE
42
+
43
+ Miska
44
+ #####
45
+
46
+ Package with **miska**-llaneous code, tools and stuff
47
+
48
+
49
+ Versioning
50
+ **********
51
+
52
+ `SemVer <http://semver.org/>`__ used for versioning.
53
+ For available versions see the repository
54
+ `tags <https://gitlab.com/pyctrl/miska/-/tags>`__
55
+ and `releases <https://gitlab.com/pyctrl/miska/-/releases>`__.
56
+
57
+
58
+ Authors
59
+ *******
60
+
61
+ - **Dima Burmistrov** - *Initial work* -
62
+ `pyctrl <https://gitlab.com/pyctrl/>`__
63
+
64
+
65
+ License
66
+ *******
67
+
68
+ This project is licensed under the X11 License (extended MIT) - see the
69
+ `LICENSE <https://gitlab.com/pyctrl/miska/-/blob/main/LICENSE>`__ file for details
miska-0.0.1/README.rst ADDED
@@ -0,0 +1,27 @@
1
+ Miska
2
+ #####
3
+
4
+ Package with **miska**-llaneous code, tools and stuff
5
+
6
+
7
+ Versioning
8
+ **********
9
+
10
+ `SemVer <http://semver.org/>`__ used for versioning.
11
+ For available versions see the repository
12
+ `tags <https://gitlab.com/pyctrl/miska/-/tags>`__
13
+ and `releases <https://gitlab.com/pyctrl/miska/-/releases>`__.
14
+
15
+
16
+ Authors
17
+ *******
18
+
19
+ - **Dima Burmistrov** - *Initial work* -
20
+ `pyctrl <https://gitlab.com/pyctrl/>`__
21
+
22
+
23
+ License
24
+ *******
25
+
26
+ This project is licensed under the X11 License (extended MIT) - see the
27
+ `LICENSE <https://gitlab.com/pyctrl/miska/-/blob/main/LICENSE>`__ file for details
File without changes
@@ -0,0 +1,8 @@
1
+ class KwargsOnly:
2
+
3
+ def __new__(cls, *args, **kwargs):
4
+ if args:
5
+ raise TypeError("%s only accepts kwargs" % cls)
6
+ inst = super().__new__(cls)
7
+ inst.__kwargs = kwargs
8
+ return inst
@@ -0,0 +1,24 @@
1
+ import typing as t
2
+
3
+
4
+ class RegistryNotFoundError(Exception):
5
+ pass
6
+
7
+
8
+ class BaseRegistry:
9
+
10
+ __repo_map: dict[str, dict[str, type]] = {}
11
+
12
+ __repo_type__: str
13
+
14
+ def __init_subclass__(cls, **kwargs: t.Any):
15
+ super().__init_subclass__(**kwargs)
16
+ BaseRegistry.__repo_map.setdefault(cls.__repo_type__, {}
17
+ )[cls.__name__] = cls
18
+
19
+ @classmethod
20
+ def get_repo_by_name(cls, class_name: str) -> type:
21
+ mapping = cls.__repo_map[cls.__repo_type__]
22
+ if class_name not in mapping:
23
+ raise RegistryNotFoundError(class_name)
24
+ return mapping[class_name]
File without changes
File without changes
@@ -0,0 +1,116 @@
1
+ import contextlib
2
+ import typing as t
3
+
4
+
5
+ # class Community:
6
+ # def __init__(self, value: int): # ???
7
+ # ...
8
+ #
9
+ # @classmethod
10
+ # def from_string(cls, val: str):
11
+ # ...
12
+
13
+
14
+ class ASN:
15
+
16
+ """BGP ASN data type
17
+
18
+ https://networklessons.com/bgp/bgp-4-byte-number
19
+ """
20
+
21
+ _SEP = "."
22
+ _ZERO = 0
23
+ _TWO_BYTES = 2 ** 16
24
+ _FOUR_BYTES = 2 ** 32
25
+
26
+ def __init__(self, number: int):
27
+ if not isinstance(number, int):
28
+ raise TypeError(f"int expected, got: {type(number)}")
29
+
30
+ if not (self._ZERO <= number < self._FOUR_BYTES):
31
+ msg = f"Value must be in range {self._ZERO}-{self._FOUR_BYTES - 1}"
32
+ raise ValueError(msg)
33
+
34
+ self._number = number
35
+
36
+ @classmethod
37
+ def from_plain(cls, string: str) -> t.Self:
38
+ if not isinstance(string, str):
39
+ raise TypeError(f"str expected, got: {type(string)}")
40
+
41
+ return cls(int(string))
42
+
43
+ def to_plain(self) -> str:
44
+ return str(self._number)
45
+
46
+ @classmethod
47
+ def from_asdot(cls, string: str) -> t.Self:
48
+ with contextlib.suppress(Exception):
49
+ result = cls.from_plain(string)
50
+ if int(result) < cls._TWO_BYTES:
51
+ return result
52
+ return cls.from_asdotplus(string)
53
+
54
+ def to_asdot(self) -> str:
55
+ if self._number < self._TWO_BYTES:
56
+ return self.to_plain()
57
+ return self.to_asdotplus()
58
+
59
+ @classmethod
60
+ def from_asdotplus(cls, string: str) -> t.Self:
61
+ if not isinstance(string, str):
62
+ raise TypeError(f"str expected, got: {type(string)}")
63
+
64
+ high, low = map(int, string.split(cls._SEP, maxsplit=1))
65
+ return cls(high * cls._TWO_BYTES + low)
66
+
67
+ def to_asdotplus(self) -> str:
68
+ return self._SEP.join(map(str, divmod(self._number, self._TWO_BYTES)))
69
+
70
+ @classmethod
71
+ def parse(cls, data: int | str) -> t.Self:
72
+ with contextlib.suppress(Exception):
73
+ return cls(t.cast(int, data))
74
+ data = t.cast(str, data)
75
+ with contextlib.suppress(Exception):
76
+ return cls.from_plain(data)
77
+ with contextlib.suppress(Exception):
78
+ return cls.from_asdotplus(data)
79
+ raise ValueError(f"Unable to parse data into {cls}")
80
+
81
+ def __int__(self) -> int:
82
+ return self._number
83
+
84
+ def __str__(self) -> str:
85
+ return f"<{self.__class__.__name__}: {self.to_asdotplus()}>"
86
+
87
+ def __repr__(self) -> str:
88
+ return f"{self.__class__.__name__}({self._number})"
89
+
90
+ def __copy__(self):
91
+ return type(self)(self._number)
92
+
93
+ def __deepcopy__(self, memo: dict[int, t.Any]):
94
+ _id = id(self)
95
+ if _id not in memo:
96
+ memo[_id] = type(self)(self._number)
97
+ return memo[_id]
98
+
99
+ def __reduce__(self) -> tuple[t.Any, ...]:
100
+ return self.__class__, (self._number,)
101
+
102
+ def __hash__(self) -> int:
103
+ return hash(self._number)
104
+
105
+ def __eq__(self, other) -> bool:
106
+ return (isinstance(other, self.__class__)
107
+ and (int(other) == self._number))
108
+
109
+
110
+ # print(ASN(6541)) # 0.6541
111
+ # print(ASN(54233)) # 0.54233
112
+ # print(ASN(544)) # 0.544
113
+ #
114
+ # print(ASN(65536)) # 1.0
115
+ # print(ASN(65537)) # 1.1
116
+ # print(ASN(65538)) # 1.2
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.1
2
+ Name: miska
3
+ Version: 0.0.1
4
+ Summary: An exceptional library
5
+ Author-email: Dima Burmistrov <pyctrl.dev@gmail.com>
6
+ License: Copyright (c) 2023-2024 Dmitry Burmistrov
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+
26
+ Except as contained in this notice, the name(s) of the above copyright holders
27
+ shall not be used in advertising or otherwise to promote the sale, use or other
28
+ dealings in this Software without prior written authorization.
29
+
30
+ Project-URL: Homepage, https://gitlab.com/pyctrl/miska
31
+ Project-URL: Bug Tracker, https://gitlab.com/pyctrl/miska/-/issues
32
+ Keywords: misc,miska
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Development Status :: 4 - Beta
37
+ Classifier: Intended Audience :: Developers
38
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
39
+ Requires-Python: >=3.11
40
+ Description-Content-Type: text/x-rst
41
+ License-File: LICENSE
42
+
43
+ Miska
44
+ #####
45
+
46
+ Package with **miska**-llaneous code, tools and stuff
47
+
48
+
49
+ Versioning
50
+ **********
51
+
52
+ `SemVer <http://semver.org/>`__ used for versioning.
53
+ For available versions see the repository
54
+ `tags <https://gitlab.com/pyctrl/miska/-/tags>`__
55
+ and `releases <https://gitlab.com/pyctrl/miska/-/releases>`__.
56
+
57
+
58
+ Authors
59
+ *******
60
+
61
+ - **Dima Burmistrov** - *Initial work* -
62
+ `pyctrl <https://gitlab.com/pyctrl/>`__
63
+
64
+
65
+ License
66
+ *******
67
+
68
+ This project is licensed under the X11 License (extended MIT) - see the
69
+ `LICENSE <https://gitlab.com/pyctrl/miska/-/blob/main/LICENSE>`__ file for details
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.rst
3
+ pyproject.toml
4
+ miska/__init__.py
5
+ miska/mixins.py
6
+ miska/registry.py
7
+ miska.egg-info/PKG-INFO
8
+ miska.egg-info/SOURCES.txt
9
+ miska.egg-info/dependency_links.txt
10
+ miska.egg-info/top_level.txt
11
+ miska/types/__init__.py
12
+ miska/types/network/__init__.py
13
+ miska/types/network/bgp.py
14
+ tests/test_registry.py
@@ -0,0 +1 @@
1
+ miska
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "miska"
7
+ version = "0.0.1"
8
+ authors = [
9
+ { name="Dima Burmistrov", email="pyctrl.dev@gmail.com" },
10
+ ]
11
+ description = "An exceptional library"
12
+ readme = "README.rst"
13
+ license = {file = "LICENSE"}
14
+
15
+ requires-python = ">=3.11"
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Development Status :: 4 - Beta",
21
+ "Intended Audience :: Developers",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ ]
24
+ keywords = ["misc", "miska"]
25
+
26
+ [project.urls]
27
+ "Homepage" = "https://gitlab.com/pyctrl/miska"
28
+ "Bug Tracker" = "https://gitlab.com/pyctrl/miska/-/issues"
miska-0.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,10 @@
1
+ from miska import registry
2
+
3
+
4
+ def test_registry():
5
+ class Registry(registry.BaseRegistry):
6
+ __repo_type__ = "things"
7
+
8
+ result = Registry.get_repo_by_name("Registry")
9
+
10
+ assert result == Registry