simplysocket 0.1.0__py3-none-any.whl
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,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,6 @@
|
|
|
1
|
+
simplysocket.py,sha256=jpEFiQNjrVN0oVh9MVVlao5wJr_Pr2d3aQIEeKNLudc,2521
|
|
2
|
+
simplysocket-0.1.0.dist-info/licenses/LICENSE,sha256=uaDU83igCLWcXF_iqqQBcAwNz4zOQdNkuHo1CS3OfUs,1103
|
|
3
|
+
simplysocket-0.1.0.dist-info/METADATA,sha256=97Ck-2kzTdjeNTTcCEJvKGYtGvywGS2fqjo391n9WWY,1910
|
|
4
|
+
simplysocket-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
+
simplysocket-0.1.0.dist-info/top_level.txt,sha256=AIEngTbzMunE458RiqdBwYVGFNQCF1g9dL1759ru8lA,13
|
|
6
|
+
simplysocket-0.1.0.dist-info/RECORD,,
|
|
@@ -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 @@
|
|
|
1
|
+
simplysocket
|
simplysocket.py
ADDED
|
@@ -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)
|