mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Replace with_traceback() with exception chaining and reraising (GH-32074)
This commit is contained in:
parent
f08a191882
commit
a03a09e068
6 changed files with 16 additions and 12 deletions
|
@ -1579,8 +1579,7 @@ class FTPHandler(BaseHandler):
|
|||
headers = email.message_from_string(headers)
|
||||
return addinfourl(fp, headers, req.full_url)
|
||||
except ftplib.all_errors as exp:
|
||||
exc = URLError('ftp error: %r' % exp)
|
||||
raise exc.with_traceback(sys.exc_info()[2])
|
||||
raise URLError(f'ftp error: {exp}') from exp
|
||||
|
||||
def connect_ftp(self, user, passwd, host, port, dirs, timeout):
|
||||
return ftpwrapper(user, passwd, host, port, dirs, timeout,
|
||||
|
@ -1791,7 +1790,7 @@ class URLopener:
|
|||
except (HTTPError, URLError):
|
||||
raise
|
||||
except OSError as msg:
|
||||
raise OSError('socket error', msg).with_traceback(sys.exc_info()[2])
|
||||
raise OSError('socket error', msg) from msg
|
||||
|
||||
def open_unknown(self, fullurl, data=None):
|
||||
"""Overridable interface to open unknown URL type."""
|
||||
|
@ -2093,7 +2092,7 @@ class URLopener:
|
|||
headers = email.message_from_string(headers)
|
||||
return addinfourl(fp, headers, "ftp:" + url)
|
||||
except ftperrors() as exp:
|
||||
raise URLError('ftp error %r' % exp).with_traceback(sys.exc_info()[2])
|
||||
raise URLError(f'ftp error: {exp}') from exp
|
||||
|
||||
def open_data(self, url, data=None):
|
||||
"""Use "data" URL."""
|
||||
|
@ -2443,8 +2442,7 @@ class ftpwrapper:
|
|||
conn, retrlen = self.ftp.ntransfercmd(cmd)
|
||||
except ftplib.error_perm as reason:
|
||||
if str(reason)[:3] != '550':
|
||||
raise URLError('ftp error: %r' % reason).with_traceback(
|
||||
sys.exc_info()[2])
|
||||
raise URLError(f'ftp error: {reason}') from reason
|
||||
if not conn:
|
||||
# Set transfer mode to ASCII!
|
||||
self.ftp.voidcmd('TYPE A')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue