random-port 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.

Potentially problematic release.


This version of random-port might be problematic. Click here for more details.

@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2025 Fabrício Barros Cabral
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
13
+ in all 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 NON-INFRINGEMENT. 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,71 @@
1
+ Metadata-Version: 2.4
2
+ Name: random_port
3
+ Version: 0.0.1
4
+ Summary: Generate a free TCP or UDP random port
5
+ Author-email: Fabrício Barros Cabral <fabriciofx@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/fabriciofx/random_port
8
+ Project-URL: Bug Tracker, https://github.com/fabriciofx/random_port/issues
9
+ Keywords: socket,tcp,udp,random,port,test
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE.txt
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest; extra == "dev"
14
+ Requires-Dist: ruff; extra == "dev"
15
+ Dynamic: license-file
16
+
17
+ # Random Port
18
+
19
+ ## Introduction
20
+
21
+ Usually we need start a TCP or UDP server (mainly to use in tests) but, which
22
+ port must be used? So, random-port is the answer. It generate a free random
23
+ TCP or UDP port to be used for any server.
24
+
25
+ ## How to install
26
+
27
+ Install it using `pip` command:
28
+
29
+ ```bash
30
+ pip install random-port
31
+ ```
32
+
33
+ in your project folder.
34
+
35
+ ## Usage
36
+
37
+ - To a TCP random port:
38
+
39
+ ```python
40
+ port = RandomTcpPort().value()
41
+ ```
42
+
43
+ - To a UDP random port:
44
+
45
+ ```python
46
+ port = RandomUdpPort().value()
47
+ ```
48
+
49
+ ## License
50
+
51
+ The MIT License (MIT)
52
+
53
+ Copyright (C) 2025 Fabrício Barros Cabral
54
+
55
+ Permission is hereby granted, free of charge, to any person obtaining a copy
56
+ of this software and associated documentation files (the "Software"), to deal
57
+ in the Software without restriction, including without limitation the rights
58
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
59
+ copies of the Software, and to permit persons to whom the Software is
60
+ furnished to do so, subject to the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be included
63
+ in all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
67
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
68
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
69
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
70
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
71
+ SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # Random Port
2
+
3
+ ## Introduction
4
+
5
+ Usually we need start a TCP or UDP server (mainly to use in tests) but, which
6
+ port must be used? So, random-port is the answer. It generate a free random
7
+ TCP or UDP port to be used for any server.
8
+
9
+ ## How to install
10
+
11
+ Install it using `pip` command:
12
+
13
+ ```bash
14
+ pip install random-port
15
+ ```
16
+
17
+ in your project folder.
18
+
19
+ ## Usage
20
+
21
+ - To a TCP random port:
22
+
23
+ ```python
24
+ port = RandomTcpPort().value()
25
+ ```
26
+
27
+ - To a UDP random port:
28
+
29
+ ```python
30
+ port = RandomUdpPort().value()
31
+ ```
32
+
33
+ ## License
34
+
35
+ The MIT License (MIT)
36
+
37
+ Copyright (C) 2025 Fabrício Barros Cabral
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining a copy
40
+ of this software and associated documentation files (the "Software"), to deal
41
+ in the Software without restriction, including without limitation the rights
42
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
+ copies of the Software, and to permit persons to whom the Software is
44
+ furnished to do so, subject to the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be included
47
+ in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
52
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "random_port"
7
+ version = "0.0.1"
8
+ description = "Generate a free TCP or UDP random port"
9
+ authors = [{ name = "Fabrício Barros Cabral", email = "fabriciofx@gmail.com" }]
10
+ readme = "README.md"
11
+ license = "MIT"
12
+ keywords = ["socket", "tcp", "udp", "random", "port", "test"]
13
+ dependencies = []
14
+
15
+ [project.urls]
16
+ "Homepage" = "https://github.com/fabriciofx/random_port"
17
+ "Bug Tracker" = "https://github.com/fabriciofx/random_port/issues"
18
+
19
+ [project.optional-dependencies]
20
+ dev = ["pytest", "ruff"]
21
+
22
+ [tool.setuptools]
23
+ packages = ["random_port"]
@@ -0,0 +1,21 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (C) 2025 Fabrício Barros Cabral
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
13
+ # in all 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 NON-INFRINGEMENT. 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,71 @@
1
+ Metadata-Version: 2.4
2
+ Name: random_port
3
+ Version: 0.0.1
4
+ Summary: Generate a free TCP or UDP random port
5
+ Author-email: Fabrício Barros Cabral <fabriciofx@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/fabriciofx/random_port
8
+ Project-URL: Bug Tracker, https://github.com/fabriciofx/random_port/issues
9
+ Keywords: socket,tcp,udp,random,port,test
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE.txt
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest; extra == "dev"
14
+ Requires-Dist: ruff; extra == "dev"
15
+ Dynamic: license-file
16
+
17
+ # Random Port
18
+
19
+ ## Introduction
20
+
21
+ Usually we need start a TCP or UDP server (mainly to use in tests) but, which
22
+ port must be used? So, random-port is the answer. It generate a free random
23
+ TCP or UDP port to be used for any server.
24
+
25
+ ## How to install
26
+
27
+ Install it using `pip` command:
28
+
29
+ ```bash
30
+ pip install random-port
31
+ ```
32
+
33
+ in your project folder.
34
+
35
+ ## Usage
36
+
37
+ - To a TCP random port:
38
+
39
+ ```python
40
+ port = RandomTcpPort().value()
41
+ ```
42
+
43
+ - To a UDP random port:
44
+
45
+ ```python
46
+ port = RandomUdpPort().value()
47
+ ```
48
+
49
+ ## License
50
+
51
+ The MIT License (MIT)
52
+
53
+ Copyright (C) 2025 Fabrício Barros Cabral
54
+
55
+ Permission is hereby granted, free of charge, to any person obtaining a copy
56
+ of this software and associated documentation files (the "Software"), to deal
57
+ in the Software without restriction, including without limitation the rights
58
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
59
+ copies of the Software, and to permit persons to whom the Software is
60
+ furnished to do so, subject to the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be included
63
+ in all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
67
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
68
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
69
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
70
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
71
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ LICENSE.txt
2
+ README.md
3
+ pyproject.toml
4
+ random_port/__init__.py
5
+ random_port.egg-info/PKG-INFO
6
+ random_port.egg-info/SOURCES.txt
7
+ random_port.egg-info/dependency_links.txt
8
+ random_port.egg-info/requires.txt
9
+ random_port.egg-info/top_level.txt
10
+ tests/test_random_port.py
@@ -0,0 +1,4 @@
1
+
2
+ [dev]
3
+ pytest
4
+ ruff
@@ -0,0 +1 @@
1
+ random_port
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,64 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (C) 2025 Fabrício Barros Cabral
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
13
+ # in all 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 NON-INFRINGEMENT. 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.
22
+ import socket
23
+
24
+ from random_port import TcpRandomPort, UdpRandomPort
25
+
26
+
27
+ def test_tcp_random_port() -> None:
28
+ begin = 1024
29
+ end = 65535
30
+ port = TcpRandomPort().value()
31
+ assert port >= begin
32
+ assert port <= end
33
+
34
+
35
+ def test_udp_random_port() -> None:
36
+ begin = 1024
37
+ end = 65535
38
+ port = UdpRandomPort().value()
39
+ assert port >= begin
40
+ assert port <= end
41
+
42
+
43
+ def test_tcp_in_use() -> None:
44
+ host = "127.0.0.1"
45
+ begin = 12344
46
+ end = 12345
47
+ server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
48
+ server.setblocking(False)
49
+ server.bind((host, begin))
50
+ free_port = TcpRandomPort(host, begin, end).value()
51
+ assert free_port == end
52
+ server.close()
53
+
54
+
55
+ def test_udp_in_use() -> None:
56
+ host = "127.0.0.1"
57
+ begin = 12344
58
+ end = 12345
59
+ server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
60
+ server.setblocking(False)
61
+ server.bind((host, begin))
62
+ free_port = UdpRandomPort(host, begin, end).value()
63
+ assert free_port == end
64
+ server.close()