Skip to content

Commit

Permalink
remove requests import
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed May 29, 2024
1 parent a5e477b commit 57a2bf3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 31 deletions.
3 changes: 1 addition & 2 deletions wdapy/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import logging
import typing

import requests
import json
from retry import retry
from urllib.parse import urlparse
Expand Down Expand Up @@ -153,7 +152,7 @@ def request(self, method: RequestMethod, urlpath: str, payload: dict = None) ->
return resp.json()

@retry(RequestError, tries=2, delay=0.2, jitter=0.1, logger=logging)
def _request_http(self, method: RequestMethod, url: str, payload: dict, **kwargs) -> requests.Response:
def _request_http(self, method: RequestMethod, url: str, payload: dict, **kwargs) -> HTTPResponseWrapper:
"""
Raises:
RequestError, WDAFatalError
Expand Down
30 changes: 1 addition & 29 deletions wdapy/_wdapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import atexit
import base64
import io
import json
import logging
import queue
import subprocess
Expand All @@ -14,7 +13,6 @@
import time
import typing

import requests
from functools import cached_property
from logzero import setup_logger
from PIL import Image
Expand All @@ -25,35 +23,9 @@
from wdapy._types import *
from wdapy.exceptions import *
from wdapy._utils import omit_empty
from wdapy.usbmux.pyusbmux import list_devices, select_device
from wdapy.usbmux.pyusbmux import list_devices


class HTTPResponse:
def __init__(self, resp: requests.Response, err: requests.RequestException):
self._resp = resp
self._err = err

def is_success(self) -> bool:
return self._err is None and self._resp.status_code == 200

def json(self) -> dict:
assert self._resp is not None
try:
return self._resp.json()
except json.JSONDecodeError:
return RequestError("JSON decode error", self._resp.text)

def get_error_message(self) -> str:
if self._resp:
return self._resp.text
return str(self._err)

def raise_if_failed(self):
if self._err:
raise RequestError("HTTP request error", self._err)
if self._resp.status_code != 200:
raise RequestError(self._resp.status_code, self._resp.text)


class CommonClient(BaseClient):
def __init__(self, wda_url: str):
Expand Down

0 comments on commit 57a2bf3

Please sign in to comment.