Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __init__(self, url=None, _session_id=None):
"""
if not url:
url = os.environ.get('DEVICE_URL', 'http://localhost:8100')
assert re.match(r"^(http\+usbmux|https?)://", url), "Invalid URL: %r" % url
assert re.match(r"^(http\+usbmux|http\+usbmux\+remote|https?)://", url), "Invalid URL: %r" % url

# Session variable
self.__wda_url = url
Expand Down
9 changes: 9 additions & 0 deletions wda/usbmux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def http_create(url: str) -> HTTPConnection:
udid, device_wda_port = u.netloc.split(":")
device = select_device(udid)
return device.make_http_connection(int(device_wda_port))
elif u.scheme == "http+usbmux+remote":
device_info, usbmux_address = u.netloc.split("@")
udid, device_wda_port = device_info.split(":")
device = select_device(udid, usbmux_address=usbmux_address)
return device.make_http_connection(int(device_wda_port), usbmux_address=usbmux_address)
elif u.scheme == "http":
return HTTPConnection(u.netloc)
elif u.scheme == "https":
Expand Down Expand Up @@ -50,6 +55,7 @@ def fetch(url: str, method="GET", data=None, timeout=None, chunk_size: int = _DE
Raises:
HTTPError
"""
conn = None
try:
method = method.upper()
conn = http_create(url)
Expand All @@ -67,6 +73,9 @@ def fetch(url: str, method="GET", data=None, timeout=None, chunk_size: int = _DE
return resp
except Exception as e:
raise HTTPError(e)
finally:
if conn:
conn.close()


def _read_response(response:HTTPResponse, chunk_size: int = _DEFAULT_CHUNK_SIZE) -> bytearray:
Expand Down
9 changes: 5 additions & 4 deletions wda/usbmux/pyusbmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def is_network(self) -> bool:
def matches_udid(self, udid: str) -> bool:
return self.serial.replace('-', '') == udid.replace('-', '')

def make_http_connection(self, port: int) -> HTTPConnection:
return USBMuxHTTPConnection(self, port)
def make_http_connection(self, port: int, usbmux_address: Optional[str] = None) -> HTTPConnection:
return USBMuxHTTPConnection(self, port, usbmux_address=usbmux_address)


class SafeStreamSocket:
Expand Down Expand Up @@ -470,13 +470,14 @@ def select_devices_by_connection_type(connection_type: str, usbmux_address: Opti


class USBMuxHTTPConnection(HTTPConnection):
def __init__(self, device: MuxDevice, port=8100):
def __init__(self, device: MuxDevice, port=8100, usbmux_address: Optional[str] = None):
super().__init__("localhost", port)
self.__device = device
self.__port = port
self.__usbmux_address = usbmux_address

def connect(self):
self.sock = self.__device.connect(self.__port)
self.sock = self.__device.connect(self.__port, self.__usbmux_address)

def __enter__(self) -> HTTPConnection:
return self
Expand Down