1
- from dataclasses import dataclass , field , fields
1
+ from dataclasses import asdict , dataclass , field , fields
2
2
from functools import cached_property
3
3
from json import loads
4
4
from os import PathLike
5
+ from platform import system
5
6
from re import split
6
7
from subprocess import CompletedProcess
7
8
from subprocess import run as subprocess_run
@@ -38,6 +39,14 @@ class PublishedPort:
38
39
PublishedPort : Optional [str ] = None
39
40
Protocol : Optional [str ] = None
40
41
42
+ def normalize (self ):
43
+ url_not_usable = system () == "Windows" and self .URL == "0.0.0.0"
44
+ if url_not_usable :
45
+ self_dict = asdict (self )
46
+ self_dict .update ({"URL" : "127.0.0.1" })
47
+ return PublishedPort (** self_dict )
48
+ return self
49
+
41
50
42
51
OT = TypeVar ("OT" )
43
52
@@ -357,7 +366,7 @@ def get_service_port(
357
366
str:
358
367
The mapped port on the host
359
368
"""
360
- return self .get_container (service_name ).get_publisher (by_port = port ).PublishedPort
369
+ return self .get_container (service_name ).get_publisher (by_port = port ).normalize (). PublishedPort
361
370
362
371
def get_service_host (
363
372
self ,
@@ -379,14 +388,14 @@ def get_service_host(
379
388
str:
380
389
The hostname for the service
381
390
"""
382
- return self .get_container (service_name ).get_publisher (by_port = port ).URL
391
+ return self .get_container (service_name ).get_publisher (by_port = port ).normalize (). URL
383
392
384
393
def get_service_host_and_port (
385
394
self ,
386
395
service_name : Optional [str ] = None ,
387
396
port : Optional [int ] = None ,
388
397
):
389
- publisher = self .get_container (service_name ).get_publisher (by_port = port )
398
+ publisher = self .get_container (service_name ).get_publisher (by_port = port ). normalize ()
390
399
return publisher .URL , publisher .PublishedPort
391
400
392
401
@wait_container_is_ready (HTTPError , URLError )
0 commit comments