aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/networking
diff options
context:
space:
mode:
Diffstat (limited to 'yt_dlp/networking')
-rw-r--r--yt_dlp/networking/common.py6
-rw-r--r--yt_dlp/networking/exceptions.py22
2 files changed, 27 insertions, 1 deletions
diff --git a/yt_dlp/networking/common.py b/yt_dlp/networking/common.py
index e4b362827..458eca39f 100644
--- a/yt_dlp/networking/common.py
+++ b/yt_dlp/networking/common.py
@@ -24,6 +24,7 @@ from .exceptions import (
from ..utils import (
bug_reports_message,
classproperty,
+ deprecation_warning,
error_to_str,
escape_url,
update_url_query,
@@ -507,16 +508,21 @@ class Response(io.IOBase):
# The following methods are for compatability reasons and are deprecated
@property
def code(self):
+ deprecation_warning('Response.code is deprecated, use Response.status', stacklevel=2)
return self.status
def getcode(self):
+ deprecation_warning('Response.getcode() is deprecated, use Response.status', stacklevel=2)
return self.status
def geturl(self):
+ deprecation_warning('Response.geturl() is deprecated, use Response.url', stacklevel=2)
return self.url
def info(self):
+ deprecation_warning('Response.info() is deprecated, use Response.headers', stacklevel=2)
return self.headers
def getheader(self, name, default=None):
+ deprecation_warning('Response.getheader() is deprecated, use Response.get_header', stacklevel=2)
return self.get_header(name, default)
diff --git a/yt_dlp/networking/exceptions.py b/yt_dlp/networking/exceptions.py
index 6fe8afb92..10afc9ccb 100644
--- a/yt_dlp/networking/exceptions.py
+++ b/yt_dlp/networking/exceptions.py
@@ -3,7 +3,7 @@ from __future__ import annotations
import typing
import urllib.error
-from ..utils import YoutubeDLError
+from ..utils import YoutubeDLError, deprecation_warning
if typing.TYPE_CHECKING:
from .common import RequestHandler, Response
@@ -137,6 +137,7 @@ class _CompatHTTPError(urllib.error.HTTPError, HTTPError):
@property
def headers(self):
+ deprecation_warning('HTTPError.headers is deprecated, use HTTPError.response.headers instead')
return self._http_error.response.headers
@headers.setter
@@ -144,16 +145,20 @@ class _CompatHTTPError(urllib.error.HTTPError, HTTPError):
return
def info(self):
+ deprecation_warning('HTTPError.info() is deprecated, use HTTPError.response.headers instead')
return self.response.headers
def getcode(self):
+ deprecation_warning('HTTPError.getcode is deprecated, use HTTPError.status instead')
return self.status
def geturl(self):
+ deprecation_warning('HTTPError.geturl is deprecated, use HTTPError.response.url instead')
return self.response.url
@property
def code(self):
+ deprecation_warning('HTTPError.code is deprecated, use HTTPError.status instead')
return self.status
@code.setter
@@ -162,6 +167,7 @@ class _CompatHTTPError(urllib.error.HTTPError, HTTPError):
@property
def url(self):
+ deprecation_warning('HTTPError.url is deprecated, use HTTPError.response.url instead')
return self.response.url
@url.setter
@@ -170,6 +176,7 @@ class _CompatHTTPError(urllib.error.HTTPError, HTTPError):
@property
def hdrs(self):
+ deprecation_warning('HTTPError.hdrs is deprecated, use HTTPError.response.headers instead')
return self.response.headers
@hdrs.setter
@@ -178,6 +185,7 @@ class _CompatHTTPError(urllib.error.HTTPError, HTTPError):
@property
def filename(self):
+ deprecation_warning('HTTPError.filename is deprecated, use HTTPError.response.url instead')
return self.response.url
@filename.setter
@@ -185,6 +193,18 @@ class _CompatHTTPError(urllib.error.HTTPError, HTTPError):
return
def __getattr__(self, name):
+ # File operations are passed through the response.
+ # Warn for some commonly used ones
+ passthrough_warnings = {
+ 'read': 'response.read()',
+ # technically possibly due to passthrough, but we should discourage this
+ 'get_header': 'response.get_header()',
+ 'readable': 'response.readable()',
+ 'closed': 'response.closed',
+ 'tell': 'response.tell()',
+ }
+ if name in passthrough_warnings:
+ deprecation_warning(f'HTTPError.{name} is deprecated, use HTTPError.{passthrough_warnings[name]} instead')
return super().__getattr__(name)
def __str__(self):