multiaddr 0.0.11__tar.gz → 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.
- {multiaddr-0.0.11 → multiaddr-0.1.0}/HISTORY.rst +36 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/PKG-INFO +4 -2
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/__init__.py +1 -1
- multiaddr-0.1.0/multiaddr/codecs/certhash.py +85 -0
- multiaddr-0.1.0/multiaddr/codecs/garlic32.py +93 -0
- multiaddr-0.1.0/multiaddr/codecs/garlic64.py +86 -0
- multiaddr-0.1.0/multiaddr/codecs/http_path.py +60 -0
- multiaddr-0.1.0/multiaddr/codecs/ipcidr.py +44 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/multiaddr.py +33 -33
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/protocols.py +15 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/transforms.py +3 -2
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr.egg-info/PKG-INFO +4 -2
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr.egg-info/SOURCES.txt +5 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr.egg-info/requires.txt +2 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/pyproject.toml +5 -3
- {multiaddr-0.0.11 → multiaddr-0.1.0}/tests/test_multiaddr.py +197 -0
- multiaddr-0.1.0/tests/test_protocols.py +625 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/tests/test_thin_waist_addresses.py +0 -9
- multiaddr-0.0.11/tests/test_protocols.py +0 -271
- {multiaddr-0.0.11 → multiaddr-0.1.0}/AUTHORS +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/CONTRIBUTING.rst +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/LICENSE-APACHE2 +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/LICENSE-MIT +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/MANIFEST.in +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/README.rst +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/__init__.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/cid.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/domain.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/fspath.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/ip4.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/ip6.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/memory.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/onion.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/onion3.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/uint16be.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/codecs/utf8.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/exceptions.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/resolvers/__init__.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/resolvers/base.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/resolvers/dns.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr/utils.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr.egg-info/dependency_links.txt +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr.egg-info/not-zip-safe +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/multiaddr.egg-info/top_level.txt +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/setup.cfg +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/tests/__init__.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/tests/test_resolvers.py +0 -0
- {multiaddr-0.0.11 → multiaddr-0.1.0}/tests/test_transforms.py +0 -0
|
@@ -3,6 +3,42 @@ History
|
|
|
3
3
|
|
|
4
4
|
.. towncrier release notes start
|
|
5
5
|
|
|
6
|
+
py-multiaddr v0.1.0 (2025-10-27)
|
|
7
|
+
--------------------------------
|
|
8
|
+
|
|
9
|
+
Features
|
|
10
|
+
~~~~~~~~
|
|
11
|
+
|
|
12
|
+
- Added the following protocols in reference with go-multiaddr
|
|
13
|
+
|
|
14
|
+
- SNI: 0x01C1
|
|
15
|
+
- NOISE: 0x01C6
|
|
16
|
+
- CERTHASH:
|
|
17
|
+
- WEBRTC:
|
|
18
|
+
- WEBRTC-DIRECT: (`#181 <https://github.com/multiformats/py-multiaddr/issues/181>`__)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
py-multiaddr v0.0.12 (2025-10-21)
|
|
22
|
+
---------------------------------
|
|
23
|
+
|
|
24
|
+
Features
|
|
25
|
+
~~~~~~~~
|
|
26
|
+
|
|
27
|
+
- Added the http-path protocol in reference with go-multiaddr. (`#94 <https://github.com/multiformats/py-multiaddr/issues/94>`__)
|
|
28
|
+
- Added ipcidr protocol support to py-multiaddr
|
|
29
|
+
|
|
30
|
+
- Implements protocol code 43 (0x2B) for CIDR notation support
|
|
31
|
+
- Full compatibility with Go multiaddr implementation
|
|
32
|
+
- Comprehensive test coverage including edge cases (`#95 <https://github.com/multiformats/py-multiaddr/issues/95>`__)
|
|
33
|
+
- Added garlic32 and garlic64 protocol support to py-multiaddr
|
|
34
|
+
|
|
35
|
+
- Implements protocol code 446 and 447.
|
|
36
|
+
- Full compatibility with Go multiaddr implementation
|
|
37
|
+
- Comprehensive test coverage including edge cases
|
|
38
|
+
- Complete documentation and examples in examples/garlic/garlic_examples.py
|
|
39
|
+
- Integration with multiaddr documentation system (`#96 <https://github.com/multiformats/py-multiaddr/issues/96>`__)
|
|
40
|
+
|
|
41
|
+
|
|
6
42
|
py-multiaddr v0.0.11 (2025-09-15)
|
|
7
43
|
---------------------------------
|
|
8
44
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multiaddr
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.1.0
|
|
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.1.0
|
|
11
11
|
Keywords: multiaddr
|
|
12
12
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -30,6 +30,8 @@ Requires-Dist: netaddr
|
|
|
30
30
|
Requires-Dist: psutil
|
|
31
31
|
Requires-Dist: py-cid>=0.3.1
|
|
32
32
|
Requires-Dist: py-multicodec>=0.2.0
|
|
33
|
+
Requires-Dist: py-multibase
|
|
34
|
+
Requires-Dist: py-multihash
|
|
33
35
|
Requires-Dist: trio-typing>=0.0.4
|
|
34
36
|
Requires-Dist: trio>=0.26.0
|
|
35
37
|
Requires-Dist: varint
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import multibase
|
|
4
|
+
import multihash
|
|
5
|
+
|
|
6
|
+
from ..codecs import CodecBase
|
|
7
|
+
|
|
8
|
+
SIZE = -1
|
|
9
|
+
IS_PATH = False
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Codec(CodecBase):
|
|
13
|
+
"""
|
|
14
|
+
Codec for certificate hashes (certhash).
|
|
15
|
+
|
|
16
|
+
A certhash is a multihash of a certificate, encoded as a multibase string
|
|
17
|
+
using the 'base64url' encoding.
|
|
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 is a valid multihash.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
b: The bytes to validate.
|
|
29
|
+
|
|
30
|
+
Raises:
|
|
31
|
+
ValueError: If the bytes cannot be decoded as a multihash.
|
|
32
|
+
"""
|
|
33
|
+
try:
|
|
34
|
+
multihash.decode(b)
|
|
35
|
+
except Exception as e:
|
|
36
|
+
raise ValueError("Invalid certhash: not a valid multihash") from e
|
|
37
|
+
|
|
38
|
+
def to_bytes(self, proto: Any, string: str) -> bytes:
|
|
39
|
+
"""
|
|
40
|
+
Converts the multibase string representation of a certhash to bytes.
|
|
41
|
+
|
|
42
|
+
This involves decoding the multibase string and then validating that
|
|
43
|
+
the resulting bytes are a valid multihash.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
proto: The multiaddr protocol code (unused).
|
|
47
|
+
string: The string representation of the certhash.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
The raw multihash bytes.
|
|
51
|
+
|
|
52
|
+
Raises:
|
|
53
|
+
ValueError: If the string is not valid multibase or not a multihash.
|
|
54
|
+
"""
|
|
55
|
+
try:
|
|
56
|
+
# Decode the multibase string to get the raw multihash bytes.
|
|
57
|
+
decoded_bytes = multibase.decode(string)
|
|
58
|
+
except Exception as e:
|
|
59
|
+
raise ValueError(f"Failed to decode multibase string: {string}") from e
|
|
60
|
+
|
|
61
|
+
# Validate that the decoded bytes are a valid multihash.
|
|
62
|
+
self.validate(decoded_bytes)
|
|
63
|
+
return decoded_bytes
|
|
64
|
+
|
|
65
|
+
def to_string(self, proto: Any, buf: bytes) -> str:
|
|
66
|
+
"""
|
|
67
|
+
Converts the raw multihash bytes of a certhash to its string form.
|
|
68
|
+
|
|
69
|
+
This involves validating the bytes first and then encoding them as a
|
|
70
|
+
'base64url' multibase string.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
proto: The multiaddr protocol code (unused).
|
|
74
|
+
buf: The raw multihash bytes.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
The multibase string representation of the certhash.
|
|
78
|
+
"""
|
|
79
|
+
# Validate the bytes before encoding.
|
|
80
|
+
self.validate(buf)
|
|
81
|
+
|
|
82
|
+
# Encode the bytes using base64url, which is standard for certhash.
|
|
83
|
+
# The result from `multibase.encode` is bytes, so we decode to a string.
|
|
84
|
+
encoded_string = multibase.encode("base64url", buf)
|
|
85
|
+
return encoded_string.decode("utf-8")
|
|
@@ -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
|
|
@@ -78,7 +81,10 @@ P_HTTP_PATH = 0x01E1
|
|
|
78
81
|
P_SNI = 0x01C1
|
|
79
82
|
P_NOISE = 0x01C6
|
|
80
83
|
P_WEBTRANSPORT = 0x01D1
|
|
84
|
+
P_WEBRTC_DIRECT = 0x118
|
|
85
|
+
P_WEBRTC = 0x119
|
|
81
86
|
P_MEMORY = 0x309
|
|
87
|
+
P_CERTHASH = 0x1D2
|
|
82
88
|
|
|
83
89
|
|
|
84
90
|
class Protocol:
|
|
@@ -144,20 +150,26 @@ PROTOCOLS = [
|
|
|
144
150
|
Protocol(P_DCCP, "dccp", "uint16be"),
|
|
145
151
|
Protocol(P_IP6, "ip6", "ip6"),
|
|
146
152
|
Protocol(P_IP6ZONE, "ip6zone", "utf8"),
|
|
153
|
+
Protocol(P_IPCIDR, "ipcidr", "ipcidr"),
|
|
147
154
|
Protocol(P_DNS, "dns", "domain"),
|
|
148
155
|
Protocol(P_DNS4, "dns4", "domain"),
|
|
149
156
|
Protocol(P_DNS6, "dns6", "domain"),
|
|
150
157
|
Protocol(P_DNSADDR, "dnsaddr", "domain"),
|
|
158
|
+
Protocol(P_SNI, "sni", "domain"),
|
|
159
|
+
Protocol(P_NOISE, "noise", None),
|
|
151
160
|
Protocol(P_SCTP, "sctp", "uint16be"),
|
|
152
161
|
Protocol(P_UDT, "udt", None),
|
|
153
162
|
Protocol(P_UTP, "utp", None),
|
|
154
163
|
Protocol(P_P2P, "p2p", "cid"),
|
|
155
164
|
Protocol(P_ONION, "onion", "onion"),
|
|
156
165
|
Protocol(P_ONION3, "onion3", "onion3"),
|
|
166
|
+
Protocol(P_GARLIC64, "garlic64", "garlic64"),
|
|
167
|
+
Protocol(P_GARLIC32, "garlic32", "garlic32"),
|
|
157
168
|
Protocol(P_QUIC, "quic", None),
|
|
158
169
|
Protocol(P_QUIC1, "quic-v1", None),
|
|
159
170
|
Protocol(P_HTTP, "http", None),
|
|
160
171
|
Protocol(P_HTTPS, "https", None),
|
|
172
|
+
Protocol(P_HTTP_PATH, "http-path", "http_path"),
|
|
161
173
|
Protocol(P_TLS, "tls", None),
|
|
162
174
|
Protocol(P_WS, "ws", None),
|
|
163
175
|
Protocol(P_WSS, "wss", None),
|
|
@@ -167,7 +179,10 @@ PROTOCOLS = [
|
|
|
167
179
|
Protocol(P_P2P_CIRCUIT, "p2p-circuit", None),
|
|
168
180
|
Protocol(P_WEBTRANSPORT, "webtransport", None),
|
|
169
181
|
Protocol(P_UNIX, "unix", "fspath"),
|
|
182
|
+
Protocol(P_WEBRTC_DIRECT, "webrtc-direct", None),
|
|
183
|
+
Protocol(P_WEBRTC, "webrtc", None),
|
|
170
184
|
Protocol(P_MEMORY, "memory", "memory"),
|
|
185
|
+
Protocol(P_CERTHASH, "certhash", "certhash"),
|
|
171
186
|
]
|
|
172
187
|
|
|
173
188
|
|
|
@@ -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.1.0
|
|
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.1.0
|
|
11
11
|
Keywords: multiaddr
|
|
12
12
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -30,6 +30,8 @@ Requires-Dist: netaddr
|
|
|
30
30
|
Requires-Dist: psutil
|
|
31
31
|
Requires-Dist: py-cid>=0.3.1
|
|
32
32
|
Requires-Dist: py-multicodec>=0.2.0
|
|
33
|
+
Requires-Dist: py-multibase
|
|
34
|
+
Requires-Dist: py-multihash
|
|
33
35
|
Requires-Dist: trio-typing>=0.0.4
|
|
34
36
|
Requires-Dist: trio>=0.26.0
|
|
35
37
|
Requires-Dist: varint
|