multiaddr 0.0.11__tar.gz → 0.0.12__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.
- {multiaddr-0.0.11 → multiaddr-0.0.12}/HISTORY.rst +21 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/PKG-INFO +2 -2
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/__init__.py +1 -1
- multiaddr-0.0.12/multiaddr/codecs/garlic32.py +93 -0
- multiaddr-0.0.12/multiaddr/codecs/garlic64.py +86 -0
- multiaddr-0.0.12/multiaddr/codecs/http_path.py +60 -0
- multiaddr-0.0.12/multiaddr/codecs/ipcidr.py +44 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/multiaddr.py +33 -33
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/protocols.py +7 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/transforms.py +3 -2
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr.egg-info/PKG-INFO +2 -2
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr.egg-info/SOURCES.txt +4 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/pyproject.toml +3 -3
- {multiaddr-0.0.11 → multiaddr-0.0.12}/tests/test_multiaddr.py +184 -0
- multiaddr-0.0.12/tests/test_protocols.py +561 -0
- multiaddr-0.0.11/tests/test_protocols.py +0 -271
- {multiaddr-0.0.11 → multiaddr-0.0.12}/AUTHORS +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/CONTRIBUTING.rst +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/LICENSE-APACHE2 +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/LICENSE-MIT +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/MANIFEST.in +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/README.rst +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/__init__.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/cid.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/domain.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/fspath.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/ip4.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/ip6.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/memory.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/onion.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/onion3.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/uint16be.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/codecs/utf8.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/exceptions.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/resolvers/__init__.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/resolvers/base.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/resolvers/dns.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr/utils.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr.egg-info/dependency_links.txt +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr.egg-info/not-zip-safe +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr.egg-info/requires.txt +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/multiaddr.egg-info/top_level.txt +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/setup.cfg +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/tests/__init__.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/tests/test_resolvers.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/tests/test_thin_waist_addresses.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.0.12}/tests/test_transforms.py +0 -0
|
@@ -3,6 +3,27 @@ History
|
|
|
3
3
|
|
|
4
4
|
.. towncrier release notes start
|
|
5
5
|
|
|
6
|
+
py-multiaddr v0.0.12 (2025-10-21)
|
|
7
|
+
---------------------------------
|
|
8
|
+
|
|
9
|
+
Features
|
|
10
|
+
~~~~~~~~
|
|
11
|
+
|
|
12
|
+
- Added the http-path protocol in reference with go-multiaddr. (`#94 <https://github.com/multiformats/py-multiaddr/issues/94>`__)
|
|
13
|
+
- Added ipcidr protocol support to py-multiaddr
|
|
14
|
+
|
|
15
|
+
- Implements protocol code 43 (0x2B) for CIDR notation support
|
|
16
|
+
- Full compatibility with Go multiaddr implementation
|
|
17
|
+
- Comprehensive test coverage including edge cases (`#95 <https://github.com/multiformats/py-multiaddr/issues/95>`__)
|
|
18
|
+
- Added garlic32 and garlic64 protocol support to py-multiaddr
|
|
19
|
+
|
|
20
|
+
- Implements protocol code 446 and 447.
|
|
21
|
+
- Full compatibility with Go multiaddr implementation
|
|
22
|
+
- Comprehensive test coverage including edge cases
|
|
23
|
+
- Complete documentation and examples in examples/garlic/garlic_examples.py
|
|
24
|
+
- Integration with multiaddr documentation system (`#96 <https://github.com/multiformats/py-multiaddr/issues/96>`__)
|
|
25
|
+
|
|
26
|
+
|
|
6
27
|
py-multiaddr v0.0.11 (2025-09-15)
|
|
7
28
|
---------------------------------
|
|
8
29
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multiaddr
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.12
|
|
4
4
|
Summary: Python implementation of jbenet's multiaddr
|
|
5
5
|
Author-email: Steven Buss <steven.buss@gmail.com>
|
|
6
6
|
Maintainer: acul71
|
|
7
7
|
Maintainer-email: pacrob <pacrob@protonmail.com>, Manu Sheel Gupta <manu@seeta.in>
|
|
8
8
|
License: MIT License
|
|
9
9
|
Project-URL: Homepage, https://github.com/multiformats/py-multiaddr
|
|
10
|
-
Project-URL: Download, https://github.com/multiformats/py-multiaddr/tarball/0.0.
|
|
10
|
+
Project-URL: Download, https://github.com/multiformats/py-multiaddr/tarball/0.0.12
|
|
11
11
|
Keywords: multiaddr
|
|
12
12
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import binascii
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from ..codecs import CodecBase
|
|
6
|
+
|
|
7
|
+
# A garlic32 address is variable-length, so we set SIZE to -1.
|
|
8
|
+
SIZE = -1
|
|
9
|
+
IS_PATH = False
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Codec(CodecBase):
|
|
13
|
+
"""
|
|
14
|
+
Codec for I2P garlic32 addresses
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
SIZE = SIZE
|
|
18
|
+
IS_PATH = IS_PATH
|
|
19
|
+
|
|
20
|
+
def validate(self, b: bytes) -> None:
|
|
21
|
+
"""
|
|
22
|
+
Validates the byte representation of a garlic32 address.
|
|
23
|
+
According to the go-multiaddr implementation, the decoded byte array
|
|
24
|
+
must be exactly 32 bytes long, or >= 35 bytes long.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
b: The bytes to validate.
|
|
28
|
+
|
|
29
|
+
Raises:
|
|
30
|
+
ValueError: If the byte length is invalid.
|
|
31
|
+
"""
|
|
32
|
+
# https://geti2p.net/spec/b32encrypted
|
|
33
|
+
if not (len(b) == 32 or len(b) >= 35):
|
|
34
|
+
raise ValueError(
|
|
35
|
+
f"Invalid length for garlic32: must be 32 or >= 35 bytes, got {len(b)}"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def to_bytes(self, proto: Any, string: str) -> bytes:
|
|
39
|
+
"""
|
|
40
|
+
Converts the string representation of a garlic32 address to bytes.
|
|
41
|
+
This involves handling the lowercase alphabet, adding necessary padding,
|
|
42
|
+
decoding, and then validating the resulting bytes.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
proto: The multiaddr protocol code (unused).
|
|
46
|
+
string: The string representation of the address.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
The byte representation of the address.
|
|
50
|
+
|
|
51
|
+
Raises:
|
|
52
|
+
ValueError: If the string is not valid Base32 or fails validation.
|
|
53
|
+
"""
|
|
54
|
+
# The Go implementation uses a lowercase alphabet, but Python's b32decode
|
|
55
|
+
# expects uppercase.
|
|
56
|
+
s_upper = string.upper()
|
|
57
|
+
|
|
58
|
+
# Add padding if it was stripped during encoding. Base32 requires
|
|
59
|
+
# the input length to be a multiple of 8.
|
|
60
|
+
padding = "=" * (-len(s_upper) % 8)
|
|
61
|
+
s_padded = s_upper + padding
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
decoded_bytes = base64.b32decode(s_padded)
|
|
65
|
+
except (ValueError, binascii.Error) as e:
|
|
66
|
+
raise ValueError(f"Failed to decode base32 i2p addr: {string}") from e
|
|
67
|
+
|
|
68
|
+
# Validate the decoded bytes after decoding.
|
|
69
|
+
self.validate(decoded_bytes)
|
|
70
|
+
return decoded_bytes
|
|
71
|
+
|
|
72
|
+
def to_string(self, proto: Any, buf: bytes) -> str:
|
|
73
|
+
"""
|
|
74
|
+
Converts the byte representation of a garlic32 address to its string form.
|
|
75
|
+
This involves validating the bytes, encoding them, converting to lowercase,
|
|
76
|
+
and stripping any padding characters.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
proto: The multiaddr protocol code (unused).
|
|
80
|
+
buf: The byte representation of the address.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
The string representation of the address.
|
|
84
|
+
"""
|
|
85
|
+
# Validate the bytes before encoding.
|
|
86
|
+
self.validate(buf)
|
|
87
|
+
|
|
88
|
+
# Encode to Base32, which produces an uppercase string with padding.
|
|
89
|
+
encoded_bytes = base64.b32encode(buf)
|
|
90
|
+
addr_string = encoded_bytes.decode("utf-8")
|
|
91
|
+
|
|
92
|
+
# The Go implementation uses a lowercase alphabet and trims padding.
|
|
93
|
+
return addr_string.lower().rstrip("=")
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import binascii
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from ..codecs import CodecBase
|
|
6
|
+
|
|
7
|
+
SIZE = -1
|
|
8
|
+
IS_PATH = False
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Codec(CodecBase):
|
|
12
|
+
"""
|
|
13
|
+
Codec for I2P garlic64 addresses.
|
|
14
|
+
|
|
15
|
+
garlic64 is a custom Base64 encoding used by I2P with an alternate
|
|
16
|
+
character set ('-~' instead of '+/'). The decoded addresses have a
|
|
17
|
+
minimum byte length of 386.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
SIZE = SIZE
|
|
21
|
+
IS_PATH = IS_PATH
|
|
22
|
+
|
|
23
|
+
def validate(self, b: bytes) -> None:
|
|
24
|
+
"""
|
|
25
|
+
Validates that the byte representation of a garlic64 address is valid.
|
|
26
|
+
According to the go-multiaddr implementation, the decoded byte array
|
|
27
|
+
must be at least 386 bytes long.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
b: The bytes to validate.
|
|
31
|
+
|
|
32
|
+
Raises:
|
|
33
|
+
ValueError: If the byte length is less than 386.
|
|
34
|
+
"""
|
|
35
|
+
# A garlic64 address will always be at least 386 bytes long when decoded.
|
|
36
|
+
if len(b) < 386:
|
|
37
|
+
raise ValueError(
|
|
38
|
+
f"Invalid length for garlic64: must be at least 386 bytes, got {len(b)}"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def to_bytes(self, proto: Any, string: str) -> bytes:
|
|
42
|
+
"""
|
|
43
|
+
Converts the string representation of a garlic64 address to bytes.
|
|
44
|
+
This involves decoding the string using the I2P-specific Base64
|
|
45
|
+
alphabet and then validating the resulting bytes.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
proto: The multiaddr protocol code (unused).
|
|
49
|
+
string: The string representation of the address.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
The byte representation of the address.
|
|
53
|
+
|
|
54
|
+
Raises:
|
|
55
|
+
ValueError: If the string is not valid Base64 or fails validation.
|
|
56
|
+
"""
|
|
57
|
+
try:
|
|
58
|
+
# Decode using the I2P garlic alphabet by replacing '+' with '-' and '/' with '~'.
|
|
59
|
+
decoded_bytes = base64.b64decode(string, altchars=b"-~")
|
|
60
|
+
except (ValueError, binascii.Error) as e:
|
|
61
|
+
# Catch potential padding errors or invalid characters.
|
|
62
|
+
raise ValueError(f"Failed to decode base64 i2p addr: {string}") from e
|
|
63
|
+
|
|
64
|
+
# Validate the decoded bytes *after* decoding, as per the Go implementation.
|
|
65
|
+
self.validate(decoded_bytes)
|
|
66
|
+
return decoded_bytes
|
|
67
|
+
|
|
68
|
+
def to_string(self, proto: Any, buf: bytes) -> str:
|
|
69
|
+
"""
|
|
70
|
+
Converts the byte representation of a garlic64 address to its string form.
|
|
71
|
+
This involves validating the bytes first and then encoding them using
|
|
72
|
+
the I2P-specific Base64 alphabet.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
proto: The multiaddr protocol code (unused).
|
|
76
|
+
buf: The byte representation of the address.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
The string representation of the address.
|
|
80
|
+
"""
|
|
81
|
+
# Validate the bytes *before* encoding, as per the Go implementation.
|
|
82
|
+
self.validate(buf)
|
|
83
|
+
|
|
84
|
+
# Encode using the I2P garlic alphabet. The result is bytes, so decode to UTF-8.
|
|
85
|
+
addr_string = base64.b64encode(buf, altchars=b"-~").decode("utf-8")
|
|
86
|
+
return addr_string
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import Any
|
|
3
|
+
from urllib.parse import quote, unquote
|
|
4
|
+
|
|
5
|
+
from ..codecs import CodecBase
|
|
6
|
+
from ..exceptions import BinaryParseError, StringParseError
|
|
7
|
+
|
|
8
|
+
IS_PATH = False
|
|
9
|
+
SIZE = -1 # LengthPrefixedVarSize
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Codec(CodecBase):
|
|
13
|
+
SIZE = SIZE
|
|
14
|
+
IS_PATH = IS_PATH
|
|
15
|
+
|
|
16
|
+
def to_bytes(self, proto: Any, string: str) -> bytes:
|
|
17
|
+
"""
|
|
18
|
+
Convert an HTTP path string to bytes
|
|
19
|
+
Unescape URL-encoded characters, validated non-empty, then encode
|
|
20
|
+
as UTF-8
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
# Reject invalid percent-escapes like "%zz" or "%f" (but allow standalone %)
|
|
24
|
+
# Look for % followed by exactly 1 hex digit OR % followed by non-hex characters OR % at end
|
|
25
|
+
invalid_escape = (
|
|
26
|
+
re.search(r"%[0-9A-Fa-f](?![0-9A-Fa-f])", string)
|
|
27
|
+
or re.search(r"%[^0-9A-Fa-f]", string)
|
|
28
|
+
or re.search(r"%$", string)
|
|
29
|
+
)
|
|
30
|
+
if invalid_escape:
|
|
31
|
+
raise StringParseError("Invalid percent-escape in path", string)
|
|
32
|
+
|
|
33
|
+
# Now safely unquote
|
|
34
|
+
try:
|
|
35
|
+
unescaped = unquote(string)
|
|
36
|
+
except Exception:
|
|
37
|
+
raise StringParseError("Invalid HTTP path string", string)
|
|
38
|
+
|
|
39
|
+
if not unescaped:
|
|
40
|
+
raise StringParseError("empty http path is not allowed", string)
|
|
41
|
+
|
|
42
|
+
return unescaped.encode("utf-8")
|
|
43
|
+
|
|
44
|
+
def to_string(self, proto: Any, buf: bytes) -> str:
|
|
45
|
+
"""
|
|
46
|
+
Convert bytes to an HTTP path string
|
|
47
|
+
Decode as UTF-8 and URL-encode (matches Go implementation)
|
|
48
|
+
"""
|
|
49
|
+
if len(buf) == 0:
|
|
50
|
+
raise BinaryParseError("Empty http path is not allowed", buf, "http-path")
|
|
51
|
+
|
|
52
|
+
return quote(buf.decode("utf-8"), safe="")
|
|
53
|
+
|
|
54
|
+
def validate(self, b: bytes) -> None:
|
|
55
|
+
"""
|
|
56
|
+
Validate an HTTP path buffer.
|
|
57
|
+
Just check non-empty.
|
|
58
|
+
"""
|
|
59
|
+
if len(b) == 0:
|
|
60
|
+
raise ValueError("Empty http path is not allowed")
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from ..codecs import CodecBase
|
|
4
|
+
from ..exceptions import BinaryParseError, StringParseError
|
|
5
|
+
|
|
6
|
+
IS_PATH = False
|
|
7
|
+
SIZE = 8
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Codec(CodecBase):
|
|
11
|
+
SIZE = SIZE
|
|
12
|
+
IS_PATH = False
|
|
13
|
+
|
|
14
|
+
def to_bytes(self, proto: Any, string: str) -> bytes:
|
|
15
|
+
"""
|
|
16
|
+
Convert an IPCIDR string (eg. "24") into a single byte buffer
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
ip_mask = int(string)
|
|
21
|
+
except ValueError:
|
|
22
|
+
raise StringParseError("Invalid IPCIDR value: ", string)
|
|
23
|
+
|
|
24
|
+
if not (0 <= ip_mask <= 255):
|
|
25
|
+
raise StringParseError("IPCIDR out of range: ", string)
|
|
26
|
+
|
|
27
|
+
return bytes([ip_mask])
|
|
28
|
+
|
|
29
|
+
def to_string(self, proto: Any, buf: bytes) -> str:
|
|
30
|
+
"""
|
|
31
|
+
Convert a single-byte IPCIDR buffer into a string (eg, b'\\x18' -> "24")
|
|
32
|
+
"""
|
|
33
|
+
try:
|
|
34
|
+
self.validate(buf)
|
|
35
|
+
return str(buf[0])
|
|
36
|
+
except Exception as e:
|
|
37
|
+
raise BinaryParseError("Failed to convert IPCIDR bytes to string", buf, "ipcidr") from e
|
|
38
|
+
|
|
39
|
+
def validate(self, b: bytes) -> None:
|
|
40
|
+
"""
|
|
41
|
+
Validate IPCIDR buffer is exactly one byte.
|
|
42
|
+
"""
|
|
43
|
+
if len(b) != 1:
|
|
44
|
+
raise ValueError("Invalid IPCIDR length (should be == 1)")
|
|
@@ -20,17 +20,17 @@ class MultiAddrKeys(collections.abc.KeysView[Any], collections.abc.Sequence[Any]
|
|
|
20
20
|
self._mapping = mapping
|
|
21
21
|
super().__init__(mapping)
|
|
22
22
|
|
|
23
|
-
def __contains__(self,
|
|
24
|
-
proto = self._mapping.registry.find(
|
|
23
|
+
def __contains__(self, value: object) -> bool: # type: ignore[bad-param-name-override]
|
|
24
|
+
proto = self._mapping.registry.find(value)
|
|
25
25
|
return collections.abc.Sequence.__contains__(self, proto)
|
|
26
26
|
|
|
27
|
-
def __getitem__(self,
|
|
28
|
-
if isinstance(
|
|
29
|
-
return list(self)[
|
|
30
|
-
if
|
|
31
|
-
|
|
27
|
+
def __getitem__(self, index: int | slice) -> Any | Sequence[Any]:
|
|
28
|
+
if isinstance(index, slice):
|
|
29
|
+
return list(self)[index]
|
|
30
|
+
if index < 0:
|
|
31
|
+
index = len(self) + index
|
|
32
32
|
for idx2, proto in enumerate(self):
|
|
33
|
-
if idx2 ==
|
|
33
|
+
if idx2 == index:
|
|
34
34
|
return proto
|
|
35
35
|
raise IndexError("Protocol list index out of range")
|
|
36
36
|
|
|
@@ -49,26 +49,26 @@ class MultiAddrItems(
|
|
|
49
49
|
self._mapping = mapping
|
|
50
50
|
super().__init__(mapping)
|
|
51
51
|
|
|
52
|
-
def __contains__(self,
|
|
53
|
-
if not isinstance(
|
|
52
|
+
def __contains__(self, value: object) -> bool: # type: ignore[bad-param-name-override]
|
|
53
|
+
if not isinstance(value, tuple) or len(value) != 2:
|
|
54
54
|
return False
|
|
55
|
-
proto,
|
|
55
|
+
proto, val = value
|
|
56
56
|
proto = self._mapping.registry.find(proto)
|
|
57
|
-
return collections.abc.Sequence.__contains__(self, (proto,
|
|
57
|
+
return collections.abc.Sequence.__contains__(self, (proto, val))
|
|
58
58
|
|
|
59
59
|
@overload
|
|
60
|
-
def __getitem__(self,
|
|
60
|
+
def __getitem__(self, index: int) -> tuple[Any, Any]: ...
|
|
61
61
|
|
|
62
62
|
@overload
|
|
63
|
-
def __getitem__(self,
|
|
63
|
+
def __getitem__(self, index: slice) -> Sequence[tuple[Any, Any]]: ...
|
|
64
64
|
|
|
65
|
-
def __getitem__(self,
|
|
66
|
-
if isinstance(
|
|
67
|
-
return list(self)[
|
|
68
|
-
if
|
|
69
|
-
|
|
65
|
+
def __getitem__(self, index: int | slice) -> tuple[Any, Any] | Sequence[tuple[Any, Any]]:
|
|
66
|
+
if isinstance(index, slice):
|
|
67
|
+
return list(self)[index]
|
|
68
|
+
if index < 0:
|
|
69
|
+
index = len(self) + index
|
|
70
70
|
for idx2, item in enumerate(self):
|
|
71
|
-
if idx2 ==
|
|
71
|
+
if idx2 == index:
|
|
72
72
|
return item
|
|
73
73
|
raise IndexError("Protocol item list index out of range")
|
|
74
74
|
|
|
@@ -99,13 +99,13 @@ class MultiAddrValues(collections.abc.ValuesView[Any], collections.abc.Sequence[
|
|
|
99
99
|
def __contains__(self, value: object) -> bool:
|
|
100
100
|
return collections.abc.Sequence.__contains__(self, value)
|
|
101
101
|
|
|
102
|
-
def __getitem__(self,
|
|
103
|
-
if isinstance(
|
|
104
|
-
return list(self)[
|
|
105
|
-
if
|
|
106
|
-
|
|
102
|
+
def __getitem__(self, index: int | slice) -> Any | Sequence[Any]:
|
|
103
|
+
if isinstance(index, slice):
|
|
104
|
+
return list(self)[index]
|
|
105
|
+
if index < 0:
|
|
106
|
+
index = len(self) + index
|
|
107
107
|
for idx2, value in enumerate(self):
|
|
108
|
-
if idx2 ==
|
|
108
|
+
if idx2 == index:
|
|
109
109
|
return value
|
|
110
110
|
raise IndexError("Protocol value list index out of range")
|
|
111
111
|
|
|
@@ -354,12 +354,12 @@ class Multiaddr(collections.abc.Mapping[Any, Any]):
|
|
|
354
354
|
continue
|
|
355
355
|
|
|
356
356
|
# Special handling for unix paths
|
|
357
|
-
if part
|
|
357
|
+
if part in ("unix",):
|
|
358
358
|
try:
|
|
359
359
|
# Get the next part as the path value
|
|
360
|
-
|
|
361
|
-
if not
|
|
362
|
-
raise exceptions.StringParseError("empty
|
|
360
|
+
protocol_path_value = next(parts)
|
|
361
|
+
if not protocol_path_value:
|
|
362
|
+
raise exceptions.StringParseError("empty protocol path", addr)
|
|
363
363
|
|
|
364
364
|
# Join any remaining parts as part of the path
|
|
365
365
|
remaining_parts = []
|
|
@@ -373,16 +373,16 @@ class Multiaddr(collections.abc.Mapping[Any, Any]):
|
|
|
373
373
|
break
|
|
374
374
|
|
|
375
375
|
if remaining_parts:
|
|
376
|
-
|
|
376
|
+
protocol_path_value = protocol_path_value + "/" + "/".join(remaining_parts)
|
|
377
377
|
|
|
378
|
-
proto = protocol_with_name(
|
|
378
|
+
proto = protocol_with_name(part)
|
|
379
379
|
codec = codec_by_name(proto.codec)
|
|
380
380
|
if not codec:
|
|
381
381
|
raise exceptions.StringParseError(f"unknown codec: {proto.codec}", addr)
|
|
382
382
|
|
|
383
383
|
try:
|
|
384
384
|
self._bytes += varint.encode(proto.code)
|
|
385
|
-
buf = codec.to_bytes(proto,
|
|
385
|
+
buf = codec.to_bytes(proto, protocol_path_value)
|
|
386
386
|
# Add length prefix for variable-sized or zero-sized codecs
|
|
387
387
|
if codec.SIZE <= 0:
|
|
388
388
|
self._bytes += varint.encode(len(buf))
|
|
@@ -49,6 +49,7 @@ __all__ = ("PROTOCOLS", "REGISTRY", "Protocol")
|
|
|
49
49
|
P_IP4 = 0x04
|
|
50
50
|
P_IP6 = 0x29
|
|
51
51
|
P_IP6ZONE = 0x2A
|
|
52
|
+
P_IPCIDR = 0x2B
|
|
52
53
|
P_TCP = 0x06
|
|
53
54
|
P_UDP = 0x0111
|
|
54
55
|
P_DCCP = 0x21
|
|
@@ -65,6 +66,8 @@ P_WS = 0x01DD
|
|
|
65
66
|
P_WSS = 0x01DE
|
|
66
67
|
P_ONION = 0x01BC
|
|
67
68
|
P_ONION3 = 0x01BD
|
|
69
|
+
P_GARLIC64 = 0x1BE
|
|
70
|
+
P_GARLIC32 = 0x1BF
|
|
68
71
|
P_P2P_CIRCUIT = 0x0122
|
|
69
72
|
P_DNS = 0x35
|
|
70
73
|
P_DNS4 = 0x36
|
|
@@ -144,6 +147,7 @@ PROTOCOLS = [
|
|
|
144
147
|
Protocol(P_DCCP, "dccp", "uint16be"),
|
|
145
148
|
Protocol(P_IP6, "ip6", "ip6"),
|
|
146
149
|
Protocol(P_IP6ZONE, "ip6zone", "utf8"),
|
|
150
|
+
Protocol(P_IPCIDR, "ipcidr", "ipcidr"),
|
|
147
151
|
Protocol(P_DNS, "dns", "domain"),
|
|
148
152
|
Protocol(P_DNS4, "dns4", "domain"),
|
|
149
153
|
Protocol(P_DNS6, "dns6", "domain"),
|
|
@@ -154,10 +158,13 @@ PROTOCOLS = [
|
|
|
154
158
|
Protocol(P_P2P, "p2p", "cid"),
|
|
155
159
|
Protocol(P_ONION, "onion", "onion"),
|
|
156
160
|
Protocol(P_ONION3, "onion3", "onion3"),
|
|
161
|
+
Protocol(P_GARLIC64, "garlic64", "garlic64"),
|
|
162
|
+
Protocol(P_GARLIC32, "garlic32", "garlic32"),
|
|
157
163
|
Protocol(P_QUIC, "quic", None),
|
|
158
164
|
Protocol(P_QUIC1, "quic-v1", None),
|
|
159
165
|
Protocol(P_HTTP, "http", None),
|
|
160
166
|
Protocol(P_HTTPS, "https", None),
|
|
167
|
+
Protocol(P_HTTP_PATH, "http-path", "http_path"),
|
|
161
168
|
Protocol(P_TLS, "tls", None),
|
|
162
169
|
Protocol(P_WS, "ws", None),
|
|
163
170
|
Protocol(P_WSS, "wss", None),
|
|
@@ -27,9 +27,9 @@ def string_to_bytes(string: str) -> bytes:
|
|
|
27
27
|
logger.debug(f"[DEBUG string_to_bytes] Encoded protocol code: {encoded_code}")
|
|
28
28
|
bs.append(encoded_code)
|
|
29
29
|
|
|
30
|
-
# Special case: protocols with codec=None are flag protocols
|
|
30
|
+
# Special case: protocols with codec=None or SIZE=0 are flag protocols
|
|
31
31
|
# (no value, no length prefix, no buffer)
|
|
32
|
-
if codec is None:
|
|
32
|
+
if codec is None or getattr(codec, "SIZE", None) == 0:
|
|
33
33
|
logger.debug(
|
|
34
34
|
f"[DEBUG string_to_bytes] Protocol {proto.name} has no data, "
|
|
35
35
|
"skipping value encoding"
|
|
@@ -93,6 +93,7 @@ def bytes_to_string(buf: bytes) -> str:
|
|
|
93
93
|
value = codec.to_string(proto, bs.read(size))
|
|
94
94
|
logger.debug(f"[DEBUG] bytes_to_string: proto={proto.name}, value='{value}'")
|
|
95
95
|
if codec.IS_PATH and value.startswith("/"):
|
|
96
|
+
# For path protocols, the codec already handles URL encoding
|
|
96
97
|
strings.append("/" + proto.name + value) # type: ignore[arg-type]
|
|
97
98
|
else:
|
|
98
99
|
strings.append("/" + proto.name + "/" + value) # type: ignore[arg-type]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multiaddr
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.12
|
|
4
4
|
Summary: Python implementation of jbenet's multiaddr
|
|
5
5
|
Author-email: Steven Buss <steven.buss@gmail.com>
|
|
6
6
|
Maintainer: acul71
|
|
7
7
|
Maintainer-email: pacrob <pacrob@protonmail.com>, Manu Sheel Gupta <manu@seeta.in>
|
|
8
8
|
License: MIT License
|
|
9
9
|
Project-URL: Homepage, https://github.com/multiformats/py-multiaddr
|
|
10
|
-
Project-URL: Download, https://github.com/multiformats/py-multiaddr/tarball/0.0.
|
|
10
|
+
Project-URL: Download, https://github.com/multiformats/py-multiaddr/tarball/0.0.12
|
|
11
11
|
Keywords: multiaddr
|
|
12
12
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -22,8 +22,12 @@ multiaddr/codecs/__init__.py
|
|
|
22
22
|
multiaddr/codecs/cid.py
|
|
23
23
|
multiaddr/codecs/domain.py
|
|
24
24
|
multiaddr/codecs/fspath.py
|
|
25
|
+
multiaddr/codecs/garlic32.py
|
|
26
|
+
multiaddr/codecs/garlic64.py
|
|
27
|
+
multiaddr/codecs/http_path.py
|
|
25
28
|
multiaddr/codecs/ip4.py
|
|
26
29
|
multiaddr/codecs/ip6.py
|
|
30
|
+
multiaddr/codecs/ipcidr.py
|
|
27
31
|
multiaddr/codecs/memory.py
|
|
28
32
|
multiaddr/codecs/onion.py
|
|
29
33
|
multiaddr/codecs/onion3.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "multiaddr"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.12"
|
|
8
8
|
description = "Python implementation of jbenet's multiaddr"
|
|
9
9
|
readme = "README.rst"
|
|
10
10
|
authors = [{ name = "Steven Buss", email = "steven.buss@gmail.com" }]
|
|
@@ -42,7 +42,7 @@ dependencies = [
|
|
|
42
42
|
|
|
43
43
|
[project.urls]
|
|
44
44
|
Homepage = "https://github.com/multiformats/py-multiaddr"
|
|
45
|
-
Download = "https://github.com/multiformats/py-multiaddr/tarball/0.0.
|
|
45
|
+
Download = "https://github.com/multiformats/py-multiaddr/tarball/0.0.12"
|
|
46
46
|
|
|
47
47
|
[project.optional-dependencies]
|
|
48
48
|
dev = [
|
|
@@ -135,7 +135,7 @@ name = "Removals"
|
|
|
135
135
|
showcontent = true
|
|
136
136
|
|
|
137
137
|
[tool.bumpversion]
|
|
138
|
-
current_version = "0.0.
|
|
138
|
+
current_version = "0.0.12"
|
|
139
139
|
parse = """
|
|
140
140
|
(?P<major>\\d+)
|
|
141
141
|
\\.(?P<minor>\\d+)
|