aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dl/socks.py
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2016-12-05 00:31:02 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2016-12-05 00:43:37 +0800
commit4bd7d9d4ae05319ebf6eb2aeffce7bde4fa7b6cf (patch)
tree2e1a113e863207d1773d22f6098b0ed2e47de5e7 /youtube_dl/socks.py
parent9b5288c92ae43436a5d48775bbe1ee537588625f (diff)
downloadyoutube-dl-4bd7d9d4ae05319ebf6eb2aeffce7bde4fa7b6cf.zip
youtube-dl-4bd7d9d4ae05319ebf6eb2aeffce7bde4fa7b6cf.tar.gz
youtube-dl-4bd7d9d4ae05319ebf6eb2aeffce7bde4fa7b6cf.tar.bz2
[socks] Refine exception model for better error handling
1. ProxyError now inherits from socket.error instead of IOError The only functions socks.py overrides are connect and connect_ex. In Python 2.x and Python <= 3.2, socket functions raises socket.error. In newer Python versions, those functions raises OSError instead. The name socket.error is preserved as an alias of OSError for backward compability. To keep socks.py compatible with Python's standard library, it should raise the same exception as raw sockets. See PEP 3151 (https://www.python.org/dev/peps/pep-3151/) for more information about the change in Python 3.3. 2. Raise EOFError instead of IOError when the socket receives less data than it expects There's no common convention, but both ftplib and telnetlib raises EOFError for similar situations. socks.py follows them. Closes #11355 In #11355, only Python 2 is affected. In Python 3, both socket.error and IOError are alias of OSError, so AbstractHTTPHandler.do_open correctly catches the error and thus InfoExtractor._is_valid_url works fine.
Diffstat (limited to 'youtube_dl/socks.py')
-rw-r--r--youtube_dl/socks.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/youtube_dl/socks.py b/youtube_dl/socks.py
index fece280..0f5d7bd 100644
--- a/youtube_dl/socks.py
+++ b/youtube_dl/socks.py
@@ -55,7 +55,7 @@ class Socks5AddressType(object):
ATYP_IPV6 = 0x04
-class ProxyError(IOError):
+class ProxyError(socket.error):
ERR_SUCCESS = 0x00
def __init__(self, code=None, msg=None):
@@ -123,7 +123,7 @@ class sockssocket(socket.socket):
while len(data) < cnt:
cur = self.recv(cnt - len(data))
if not cur:
- raise IOError('{0} bytes missing'.format(cnt - len(data)))
+ raise EOFError('{0} bytes missing'.format(cnt - len(data)))
data += cur
return data