simplysocket 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 simplysocket contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: simplysocket
3
+ Version: 0.1.0
4
+ Summary: Small helpers for creating standard-library sockets
5
+ License-Expression: MIT
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: System :: Networking
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # simplysocket
17
+
18
+ `simplysocket` is a small helper for creating Python standard-library sockets
19
+ using familiar family and protocol names. It has no runtime dependencies.
20
+
21
+ ## Installation
22
+
23
+ ```console
24
+ python -m pip install simplysocket
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```python
30
+ from simplysocket import socket
31
+
32
+ tcp_socket = socket.defaultSocket()
33
+ udp_socket = socket.createSocket(socketType="UDP")
34
+ ipv6_socket = socket.createSocket(socketFamily="ipv6")
35
+
36
+ for sock in (tcp_socket, udp_socket, ipv6_socket):
37
+ sock.close()
38
+ ```
39
+
40
+ `createSocket` supports the families `v4`, `ipv4`, `inet`, `ip4`, `v6`,
41
+ `ipv6`, `inet6`, `ip6`, and `bluetooth`; and the types `TCP`, `UDP`, and
42
+ `RAW`. Omitting the family or type selects IPv4 or TCP, respectively.
43
+ Unsupported family or type names raise `ValueError`. Bluetooth raises
44
+ `NotImplementedError` on platforms where Python does not expose Bluetooth
45
+ sockets. Creating raw sockets may require elevated operating-system
46
+ permissions.
47
+
48
+ ## Development
49
+
50
+ Build and validate the distribution with:
51
+
52
+ ```console
53
+ python -m pip install --upgrade build twine
54
+ python -m unittest discover -s tests
55
+ python -m build
56
+ python -m twine check dist/*
57
+ ```
58
+
59
+ Upload only after reviewing the built artifacts and confirming the project
60
+ name and release metadata:
61
+
62
+ ```console
63
+ python -m twine upload dist/*
64
+ ```
65
+
66
+ ## License
67
+
68
+ Distributed under the MIT License. See [LICENSE](LICENSE).
@@ -0,0 +1,53 @@
1
+ # simplysocket
2
+
3
+ `simplysocket` is a small helper for creating Python standard-library sockets
4
+ using familiar family and protocol names. It has no runtime dependencies.
5
+
6
+ ## Installation
7
+
8
+ ```console
9
+ python -m pip install simplysocket
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```python
15
+ from simplysocket import socket
16
+
17
+ tcp_socket = socket.defaultSocket()
18
+ udp_socket = socket.createSocket(socketType="UDP")
19
+ ipv6_socket = socket.createSocket(socketFamily="ipv6")
20
+
21
+ for sock in (tcp_socket, udp_socket, ipv6_socket):
22
+ sock.close()
23
+ ```
24
+
25
+ `createSocket` supports the families `v4`, `ipv4`, `inet`, `ip4`, `v6`,
26
+ `ipv6`, `inet6`, `ip6`, and `bluetooth`; and the types `TCP`, `UDP`, and
27
+ `RAW`. Omitting the family or type selects IPv4 or TCP, respectively.
28
+ Unsupported family or type names raise `ValueError`. Bluetooth raises
29
+ `NotImplementedError` on platforms where Python does not expose Bluetooth
30
+ sockets. Creating raw sockets may require elevated operating-system
31
+ permissions.
32
+
33
+ ## Development
34
+
35
+ Build and validate the distribution with:
36
+
37
+ ```console
38
+ python -m pip install --upgrade build twine
39
+ python -m unittest discover -s tests
40
+ python -m build
41
+ python -m twine check dist/*
42
+ ```
43
+
44
+ Upload only after reviewing the built artifacts and confirming the project
45
+ name and release metadata:
46
+
47
+ ```console
48
+ python -m twine upload dist/*
49
+ ```
50
+
51
+ ## License
52
+
53
+ Distributed under the MIT License. See [LICENSE](LICENSE).
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "simplysocket"
7
+ version = "0.1.0"
8
+ description = "Small helpers for creating standard-library sockets"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Operating System :: OS Independent",
17
+ "Programming Language :: Python :: 3",
18
+ "Topic :: System :: Networking",
19
+ ]
20
+
21
+ [tool.setuptools]
22
+ py-modules = ["simplysocket"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: simplysocket
3
+ Version: 0.1.0
4
+ Summary: Small helpers for creating standard-library sockets
5
+ License-Expression: MIT
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: System :: Networking
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # simplysocket
17
+
18
+ `simplysocket` is a small helper for creating Python standard-library sockets
19
+ using familiar family and protocol names. It has no runtime dependencies.
20
+
21
+ ## Installation
22
+
23
+ ```console
24
+ python -m pip install simplysocket
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```python
30
+ from simplysocket import socket
31
+
32
+ tcp_socket = socket.defaultSocket()
33
+ udp_socket = socket.createSocket(socketType="UDP")
34
+ ipv6_socket = socket.createSocket(socketFamily="ipv6")
35
+
36
+ for sock in (tcp_socket, udp_socket, ipv6_socket):
37
+ sock.close()
38
+ ```
39
+
40
+ `createSocket` supports the families `v4`, `ipv4`, `inet`, `ip4`, `v6`,
41
+ `ipv6`, `inet6`, `ip6`, and `bluetooth`; and the types `TCP`, `UDP`, and
42
+ `RAW`. Omitting the family or type selects IPv4 or TCP, respectively.
43
+ Unsupported family or type names raise `ValueError`. Bluetooth raises
44
+ `NotImplementedError` on platforms where Python does not expose Bluetooth
45
+ sockets. Creating raw sockets may require elevated operating-system
46
+ permissions.
47
+
48
+ ## Development
49
+
50
+ Build and validate the distribution with:
51
+
52
+ ```console
53
+ python -m pip install --upgrade build twine
54
+ python -m unittest discover -s tests
55
+ python -m build
56
+ python -m twine check dist/*
57
+ ```
58
+
59
+ Upload only after reviewing the built artifacts and confirming the project
60
+ name and release metadata:
61
+
62
+ ```console
63
+ python -m twine upload dist/*
64
+ ```
65
+
66
+ ## License
67
+
68
+ Distributed under the MIT License. See [LICENSE](LICENSE).
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ simplysocket.py
5
+ simplysocket.egg-info/PKG-INFO
6
+ simplysocket.egg-info/SOURCES.txt
7
+ simplysocket.egg-info/dependency_links.txt
8
+ simplysocket.egg-info/top_level.txt
9
+ tests/test_simplysocket.py
@@ -0,0 +1 @@
1
+ simplysocket
@@ -0,0 +1,76 @@
1
+ """Small helpers for creating standard-library sockets."""
2
+
3
+ import socket as _socket
4
+ from typing import Optional
5
+
6
+ __all__ = ["socket"]
7
+
8
+
9
+ class socket:
10
+ """Factory for TCP, UDP, raw, IPv4, IPv6, and Bluetooth sockets."""
11
+
12
+ TCP = _socket.SOCK_STREAM
13
+ UDP = _socket.SOCK_DGRAM
14
+ RAW_SOCKET = _socket.SOCK_RAW
15
+
16
+ IPv4 = _socket.AF_INET
17
+ IPv6 = _socket.AF_INET6
18
+ BLUETOOTH = getattr(_socket, "AF_BLUETOOTH", None)
19
+
20
+ @staticmethod
21
+ def defaultSocket() -> _socket.socket:
22
+ """Create a default IPv4 TCP socket."""
23
+ return _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
24
+
25
+ @classmethod
26
+ def createSocket(
27
+ cls,
28
+ socketFamily: Optional[str] = None,
29
+ socketType: Optional[str] = None,
30
+ ) -> _socket.socket:
31
+ """Create a socket for a supported family and protocol type.
32
+
33
+ Families accept ``v4``, ``ipv4``, ``inet``, ``ip4``, ``v6``,
34
+ ``ipv6``, ``inet6``, ``ip6``, or ``bluetooth``. Types accept
35
+ ``TCP``, ``UDP``, or ``RAW``. Omitting either argument selects
36
+ IPv4 or TCP, respectively.
37
+
38
+ Raises:
39
+ ValueError: If the requested family or type is not supported.
40
+ NotImplementedError: If Bluetooth sockets are unavailable.
41
+ """
42
+ family = socketFamily.lower() if socketFamily is not None else "v4"
43
+ socket_kind = socketType.upper() if socketType is not None else "TCP"
44
+
45
+ families = {
46
+ "v4": cls.IPv4,
47
+ "ipv4": cls.IPv4,
48
+ "inet": cls.IPv4,
49
+ "ip4": cls.IPv4,
50
+ "v6": cls.IPv6,
51
+ "ipv6": cls.IPv6,
52
+ "inet6": cls.IPv6,
53
+ "ip6": cls.IPv6,
54
+ }
55
+ if family in families:
56
+ family_id = families[family]
57
+ elif family == "bluetooth":
58
+ if cls.BLUETOOTH is None:
59
+ raise NotImplementedError(
60
+ "Bluetooth sockets are not supported on this platform"
61
+ )
62
+ family_id = cls.BLUETOOTH
63
+ else:
64
+ raise ValueError(f"Unsupported socket family: {socketFamily!r}")
65
+
66
+ socket_types = {
67
+ "TCP": cls.TCP,
68
+ "UDP": cls.UDP,
69
+ "RAW": cls.RAW_SOCKET,
70
+ }
71
+ try:
72
+ socket_type = socket_types[socket_kind]
73
+ except KeyError:
74
+ raise ValueError(f"Unsupported socket type: {socketType!r}") from None
75
+
76
+ return _socket.socket(family_id, socket_type)
@@ -0,0 +1,55 @@
1
+ import socket as standard_socket
2
+ import unittest
3
+
4
+ from simplysocket import socket
5
+
6
+
7
+ class SocketFactoryTests(unittest.TestCase):
8
+ def test_default_socket_is_ipv4_tcp(self):
9
+ sock = socket.defaultSocket()
10
+ try:
11
+ self.assertEqual(sock.family, standard_socket.AF_INET)
12
+ self.assertEqual(sock.type, standard_socket.SOCK_STREAM)
13
+ finally:
14
+ sock.close()
15
+
16
+ def test_create_socket_defaults_to_ipv4_tcp(self):
17
+ sock = socket.createSocket()
18
+ try:
19
+ self.assertEqual(sock.family, standard_socket.AF_INET)
20
+ self.assertEqual(sock.type, standard_socket.SOCK_STREAM)
21
+ finally:
22
+ sock.close()
23
+
24
+ def test_create_udp_socket(self):
25
+ sock = socket.createSocket(socketType="udp")
26
+ try:
27
+ self.assertEqual(sock.family, standard_socket.AF_INET)
28
+ self.assertEqual(sock.type, standard_socket.SOCK_DGRAM)
29
+ finally:
30
+ sock.close()
31
+
32
+ def test_create_ipv6_socket(self):
33
+ sock = socket.createSocket(socketFamily="IPv6")
34
+ try:
35
+ self.assertEqual(sock.family, standard_socket.AF_INET6)
36
+ finally:
37
+ sock.close()
38
+
39
+ def test_unknown_family_raises_value_error(self):
40
+ with self.assertRaisesRegex(ValueError, "Unsupported socket family"):
41
+ socket.createSocket(socketFamily="unknown")
42
+
43
+ def test_unknown_type_raises_value_error(self):
44
+ with self.assertRaisesRegex(ValueError, "Unsupported socket type"):
45
+ socket.createSocket(socketType="unknown")
46
+
47
+ def test_bluetooth_without_platform_support_raises(self):
48
+ if socket.BLUETOOTH is not None:
49
+ self.skipTest("This platform exposes Bluetooth socket support")
50
+ with self.assertRaisesRegex(NotImplementedError, "Bluetooth sockets"):
51
+ socket.createSocket(socketFamily="bluetooth")
52
+
53
+
54
+ if __name__ == "__main__":
55
+ unittest.main()