mirror of https://gitlab.com/bashrc2/epicyon
Get port from yggdrasil address
parent
eedf1b08f6
commit
035ad379dc
6
tests.py
6
tests.py
|
|
@ -67,6 +67,8 @@ from flags import is_right_to_left_text
|
||||||
from status import actor_status_expired
|
from status import actor_status_expired
|
||||||
from status import get_actor_status
|
from status import get_actor_status
|
||||||
from unicodetext import uninvert_text
|
from unicodetext import uninvert_text
|
||||||
|
from utils import remove_domain_port
|
||||||
|
from utils import get_port_from_domain
|
||||||
from utils import is_yggdrasil_url
|
from utils import is_yggdrasil_url
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
from utils import valid_content_warning
|
from utils import valid_content_warning
|
||||||
|
|
@ -9653,8 +9655,12 @@ def _test_yggdrasil_addresses() -> None:
|
||||||
assert is_yggdrasil_url(text)
|
assert is_yggdrasil_url(text)
|
||||||
text = 'http://[200:abcd:abcd:abcd:abcd:abcd:abcd:abcd]:5026/something'
|
text = 'http://[200:abcd:abcd:abcd:abcd:abcd:abcd:abcd]:5026/something'
|
||||||
assert is_yggdrasil_url(text)
|
assert is_yggdrasil_url(text)
|
||||||
|
assert get_port_from_domain(text) == 5026
|
||||||
|
assert remove_domain_port(text) == \
|
||||||
|
'http://[200:abcd:abcd:abcd:abcd:abcd:abcd:abcd]'
|
||||||
text = 'http://[203:abcd:abcd:abcd:abcd:abcd:abcd]/something'
|
text = 'http://[203:abcd:abcd:abcd:abcd:abcd:abcd]/something'
|
||||||
assert not is_yggdrasil_url(text)
|
assert not is_yggdrasil_url(text)
|
||||||
|
assert get_port_from_domain(text) is None
|
||||||
|
|
||||||
|
|
||||||
def run_all_tests():
|
def run_all_tests():
|
||||||
|
|
|
||||||
14
utils.py
14
utils.py
|
|
@ -2964,7 +2964,8 @@ def remove_domain_port(domain: str) -> str:
|
||||||
if domain.startswith('did:'):
|
if domain.startswith('did:'):
|
||||||
return domain
|
return domain
|
||||||
if ']:' not in domain:
|
if ']:' not in domain:
|
||||||
domain = domain.split(':')[0]
|
if '[' not in domain:
|
||||||
|
domain = domain.split(':')[0]
|
||||||
else:
|
else:
|
||||||
domain = domain.split(']:')[0] + ']'
|
domain = domain.split(']:')[0] + ']'
|
||||||
return domain
|
return domain
|
||||||
|
|
@ -2977,12 +2978,17 @@ def get_port_from_domain(domain: str) -> int:
|
||||||
if ':' in domain:
|
if ':' in domain:
|
||||||
if domain.startswith('did:'):
|
if domain.startswith('did:'):
|
||||||
return None
|
return None
|
||||||
|
port_str = ''
|
||||||
if ']:' not in domain:
|
if ']:' not in domain:
|
||||||
port_str = domain.split(':')[1]
|
if '[' not in domain:
|
||||||
|
port_str = domain.split(':')[1]
|
||||||
else:
|
else:
|
||||||
port_str = domain.split(']:')[1]
|
port_str = domain.split(']:')[1]
|
||||||
if port_str.isdigit():
|
if port_str:
|
||||||
return int(port_str)
|
if '/' in port_str:
|
||||||
|
port_str = port_str.split('/')[0]
|
||||||
|
if port_str.isdigit():
|
||||||
|
return int(port_str)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue