shadow-tools 0.2.2__tar.gz → 0.2.4__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.
Files changed (24) hide show
  1. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/PKG-INFO +6 -2
  2. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/README.md +5 -1
  3. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/pyproject.toml +1 -1
  4. shadow_tools-0.2.4/release-0.2.2/shadow_tools-0.2.2-py3-none-any.whl +0 -0
  5. shadow_tools-0.2.4/release-0.2.2/shadow_tools-0.2.2.tar.gz +0 -0
  6. shadow_tools-0.2.4/release-0.2.3/shadow_tools-0.2.3-py3-none-any.whl +0 -0
  7. shadow_tools-0.2.4/release-0.2.3/shadow_tools-0.2.3.tar.gz +0 -0
  8. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/__init__.py +1 -1
  9. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/network.py +15 -7
  10. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/tests/test_core.py +3 -1
  11. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/.gitignore +0 -0
  12. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/LICENSE +0 -0
  13. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/release-0.2.0/shadow_tools-0.2.0-py3-none-any.whl +0 -0
  14. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/release-0.2.0/shadow_tools-0.2.0.tar.gz +0 -0
  15. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/release-0.2.1/shadow_tools-0.2.1-py3-none-any.whl +0 -0
  16. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/release-0.2.1/shadow_tools-0.2.1.tar.gz +0 -0
  17. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/ai.py +0 -0
  18. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/async_tools.py +0 -0
  19. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/cli.py +0 -0
  20. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/data.py +0 -0
  21. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/files.py +0 -0
  22. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/http.py +0 -0
  23. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/validation.py +0 -0
  24. {shadow_tools-0.2.2 → shadow_tools-0.2.4}/src/shadowtools/websocket.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: shadow-tools
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: A practical all-in-one Python toolkit for HTTP, WebSockets, files, data, validation, async work, and CLIs.
5
5
  Project-URL: Homepage, https://github.com/WilliamLaurento/shadow-tools
6
6
  Project-URL: Issues, https://github.com/WilliamLaurento/shadow-tools/issues
@@ -64,8 +64,9 @@ from shadowtools import generate_random_ips, generate_test_ips, make_subdomain,
64
64
  print(make_subdomain("api", "example.com")) # api.example.com
65
65
  print(resolve_dns("example.com"))
66
66
  print(generate_test_ips(2)) # safe documentation-only addresses
67
- print(generate_random_ips(5)) # mixed private, public, and special IPv4 addresses
67
+ print(generate_random_ips(5)) # globally routable public IPv4 addresses only
68
68
  print(generate_random_ips(3, family=6))
69
+ print(generate_random_ips(3, include_private=True, include_special=True))
69
70
  ```
70
71
 
71
72
  Reverse-DNS lookup for IP addresses:
@@ -75,6 +76,9 @@ from shadowtools import generate_random_ips, reverse_dns
75
76
 
76
77
  for ip in generate_random_ips(5):
77
78
  print(reverse_dns(ip))
79
+
80
+ # Or look up every generated IP at once.
81
+ print(reverse_dns(generate_random_ips(5)))
78
82
  ```
79
83
 
80
84
  ## AI app helpers
@@ -40,8 +40,9 @@ from shadowtools import generate_random_ips, generate_test_ips, make_subdomain,
40
40
  print(make_subdomain("api", "example.com")) # api.example.com
41
41
  print(resolve_dns("example.com"))
42
42
  print(generate_test_ips(2)) # safe documentation-only addresses
43
- print(generate_random_ips(5)) # mixed private, public, and special IPv4 addresses
43
+ print(generate_random_ips(5)) # globally routable public IPv4 addresses only
44
44
  print(generate_random_ips(3, family=6))
45
+ print(generate_random_ips(3, include_private=True, include_special=True))
45
46
  ```
46
47
 
47
48
  Reverse-DNS lookup for IP addresses:
@@ -51,6 +52,9 @@ from shadowtools import generate_random_ips, reverse_dns
51
52
 
52
53
  for ip in generate_random_ips(5):
53
54
  print(reverse_dns(ip))
55
+
56
+ # Or look up every generated IP at once.
57
+ print(reverse_dns(generate_random_ips(5)))
54
58
  ```
55
59
 
56
60
  ## AI app helpers
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "shadow-tools"
7
- version = "0.2.2"
7
+ version = "0.2.4"
8
8
  description = "A practical all-in-one Python toolkit for HTTP, WebSockets, files, data, validation, async work, and CLIs."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -6,7 +6,7 @@ from .http import get, request
6
6
  from .network import generate_random_ips, generate_test_ips, is_subdomain_of, make_subdomain, resolve_dns, reverse_dns
7
7
  from .validation import is_email, is_url, require_keys
8
8
 
9
- __version__ = "0.2.2"
9
+ __version__ = "0.2.4"
10
10
 
11
11
  __all__ = [
12
12
  "append_text", "ensure_dir", "generate_random_ips", "generate_test_ips", "get", "is_email", "is_subdomain_of", "is_url", "make_subdomain", "read_csv",
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
  import ipaddress
5
5
  import random
6
6
  import socket
7
+ from collections.abc import Iterable
7
8
 
8
9
 
9
10
  def resolve_dns(hostname: str) -> dict[str, list[str]]:
@@ -17,12 +18,14 @@ def resolve_dns(hostname: str) -> dict[str, list[str]]:
17
18
  return {kind: sorted(addresses) for kind, addresses in results.items()}
18
19
 
19
20
 
20
- def reverse_dns(ip: str) -> dict[str, object]:
21
- """Look up the DNS name assigned to one IPv4 or IPv6 address.
21
+ def reverse_dns(ip: str | Iterable[str]) -> dict[str, object] | list[dict[str, object]]:
22
+ """Look up DNS names for one IP address or each address in a list.
22
23
 
23
24
  An address without a PTR record returns ``hostname: None`` instead of
24
25
  raising an exception.
25
26
  """
27
+ if not isinstance(ip, str):
28
+ return [reverse_dns(one_ip) for one_ip in ip]
26
29
  address = ipaddress.ip_address(ip)
27
30
  try:
28
31
  hostname, aliases, _ = socket.gethostbyaddr(str(address))
@@ -56,18 +59,23 @@ def generate_test_ips(count: int = 1, *, family: int = 4) -> list[str]:
56
59
 
57
60
 
58
61
  def generate_random_ips(count: int = 1, *, family: int = 4,
59
- include_special: bool = True) -> list[str]:
62
+ include_private: bool = False,
63
+ include_special: bool = False) -> list[str]:
60
64
  """Generate random IPv4 or IPv6 addresses for test data and mock inputs.
61
65
 
62
- When ``include_special`` is true, the results can include private, public,
63
- loopback, link-local, unspecified, and (for IPv4) broadcast addresses.
64
- This function only creates address strings; it never connects to them.
66
+ By default, results are globally routable public addresses only. Set
67
+ ``include_private=True`` to include private ranges, or
68
+ ``include_special=True`` to include loopback, link-local, unspecified, and
69
+ broadcast-style addresses. This function only creates address strings; it
70
+ never connects to them.
65
71
  """
66
72
  if not 1 <= count <= 10_000:
67
73
  raise ValueError("count must be between 1 and 10,000")
68
74
  if family not in (4, 6):
69
75
  raise ValueError("family must be 4 or 6")
70
- kinds = ["private", "public"]
76
+ kinds = ["public"]
77
+ if include_private:
78
+ kinds.append("private")
71
79
  if include_special:
72
80
  kinds += ["loopback", "link_local", "unspecified"]
73
81
  if family == 4:
@@ -1,4 +1,5 @@
1
1
  import asyncio
2
+ import ipaddress
2
3
 
3
4
  import pytest
4
5
 
@@ -41,8 +42,9 @@ def test_network_and_ai_helpers():
41
42
  assert make_subdomain("API", "Example.COM") == "api.example.com"
42
43
  assert is_subdomain_of("api.example.com", "example.com")
43
44
  assert generate_test_ips(1)[0].startswith("192.0.2.")
44
- assert len(generate_random_ips(3)) == 3
45
+ assert all(ipaddress.ip_address(ip).is_global for ip in generate_random_ips(3))
45
46
  assert len(generate_random_ips(2, family=6)) == 2
46
47
  assert reverse_dns("0.0.0.0")["hostname"] is None
48
+ assert len(reverse_dns(["0.0.0.0", "127.0.0.1"])) == 2
47
49
  assert prompt("Hi {name}", name="Will") == "Hi Will"
48
50
  assert tool_schema("lookup_dns", "Lookup DNS", {"host": {"type": "string"}})["name"] == "lookup_dns"
File without changes
File without changes