mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-06-20 22:20:53 +10:00
network_handler.py: Implement get() wrapper
This commit is contained in:
@@ -13,6 +13,8 @@
|
|||||||
- Credit to [Ausdauersportler](https://github.com/Ausdauersportler) for implementation
|
- Credit to [Ausdauersportler](https://github.com/Ausdauersportler) for implementation
|
||||||
- Backend changes:
|
- Backend changes:
|
||||||
- Use `.AppleSystemUIFont` for wxPython text rendering (thanks [jazzzny](https://github.com/Jazzzny))
|
- Use `.AppleSystemUIFont` for wxPython text rendering (thanks [jazzzny](https://github.com/Jazzzny))
|
||||||
|
- Add extra error handling for network errors
|
||||||
|
- Handles `RemoteDisconnected('Remote end closed connection without response')` exceptions
|
||||||
- Increment Binaries:
|
- Increment Binaries:
|
||||||
- PatcherSupportPkg 0.9.2 - release
|
- PatcherSupportPkg 0.9.2 - release
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class KernelDebugKitObject:
|
|||||||
return KDK_ASSET_LIST
|
return KDK_ASSET_LIST
|
||||||
|
|
||||||
try:
|
try:
|
||||||
results = network_handler.SESSION.get(
|
results = network_handler.NetworkUtilities().get(
|
||||||
KDK_API_LINK,
|
KDK_API_LINK,
|
||||||
headers={
|
headers={
|
||||||
"User-Agent": f"OCLP/{self.constants.patcher_version}"
|
"User-Agent": f"OCLP/{self.constants.patcher_version}"
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ class RemoteInstallerCatalog:
|
|||||||
return catalog
|
return catalog
|
||||||
|
|
||||||
try:
|
try:
|
||||||
catalog = plistlib.loads(network_handler.SESSION.get(self.catalog_url).content)
|
catalog = plistlib.loads(network_handler.NetworkUtilities().get(self.catalog_url).content)
|
||||||
except plistlib.InvalidFileException:
|
except plistlib.InvalidFileException:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@@ -311,7 +311,7 @@ class RemoteInstallerCatalog:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
build_plist = plistlib.loads(network_handler.SESSION.get(bm_package["URL"]).content)
|
build_plist = plistlib.loads(network_handler.NetworkUtilities().get(bm_package["URL"]).content)
|
||||||
except plistlib.InvalidFileException:
|
except plistlib.InvalidFileException:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,36 @@ class NetworkUtilities:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get(self, url: str, **kwargs) -> requests.Response:
|
||||||
|
"""
|
||||||
|
Wrapper for requests's get method
|
||||||
|
Implement additional error handling
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
url (str): URL to get
|
||||||
|
**kwargs: Additional parameters for requests.get
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
requests.Response: Response object from requests.get
|
||||||
|
"""
|
||||||
|
|
||||||
|
result: requests.Response = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = SESSION.get(url, **kwargs)
|
||||||
|
except (
|
||||||
|
requests.exceptions.Timeout,
|
||||||
|
requests.exceptions.TooManyRedirects,
|
||||||
|
requests.exceptions.ConnectionError,
|
||||||
|
requests.exceptions.HTTPError
|
||||||
|
) as error:
|
||||||
|
logging.warn(f"Error calling requests.get: {error}")
|
||||||
|
# Return empty response object
|
||||||
|
return requests.Response()
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class DownloadObject:
|
class DownloadObject:
|
||||||
"""
|
"""
|
||||||
Object for downloading files from the network
|
Object for downloading files from the network
|
||||||
@@ -278,7 +308,7 @@ class DownloadObject:
|
|||||||
if self._prepare_working_directory(self.filepath) is False:
|
if self._prepare_working_directory(self.filepath) is False:
|
||||||
raise Exception(self.error_msg)
|
raise Exception(self.error_msg)
|
||||||
|
|
||||||
response = SESSION.get(self.url, stream=True, timeout=10)
|
response = NetworkUtilities().get(self.url, stream=True, timeout=10)
|
||||||
|
|
||||||
with open(self.filepath, 'wb') as file:
|
with open(self.filepath, 'wb') as file:
|
||||||
for i, chunk in enumerate(response.iter_content(1024 * 1024 * 4)):
|
for i, chunk in enumerate(response.iter_content(1024 * 1024 * 4)):
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class CheckBinaryUpdates:
|
|||||||
if not network_handler.NetworkUtilities(REPO_LATEST_RELEASE_URL).verify_network_connection():
|
if not network_handler.NetworkUtilities(REPO_LATEST_RELEASE_URL).verify_network_connection():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
response = requests.get(REPO_LATEST_RELEASE_URL)
|
response = network_handler.NetworkUtilities().get(REPO_LATEST_RELEASE_URL)
|
||||||
data_set = response.json()
|
data_set = response.json()
|
||||||
|
|
||||||
self.remote_version = data_set["tag_name"]
|
self.remote_version = data_set["tag_name"]
|
||||||
|
|||||||
Reference in New Issue
Block a user