summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-02-12 21:11:07 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-02-24 10:39:04 +0100
commitb20d2b8924245c4dde985c15832f30e253aeeaa9 (patch)
tree2a6de7377f273e2e54b0786b9b357a5817114718
parentfc2e9544c472d6ab49982a875bd775d1493db64f (diff)
downloadurlgrabber-b20d2b8924245c4dde985c15832f30e253aeeaa9.tar.gz
py3: avoid "unbound variable" issue
Under python3, the variable defined in "except ... as ..." is only valid until the end of the block. In this case it would undefine the variable that was defined above, not reassign it as under python2, leading to the following tb: Traceback (most recent call last): File "test/test_mirror.py", line 379, in test_retry_no_cache urlgrabber.grabber.parallel_wait() File "test/../urlgrabber/grabber.py", line 2374, in parallel_wait perform() File "test/../urlgrabber/grabber.py", line 2313, in perform if ug_err is None: UnboundLocalError: local variable 'ug_err' referenced before assignment
-rw-r--r--urlgrabber/grabber.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index b696472..0a26fb4 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -2289,8 +2289,10 @@ def parallel_wait(meter=None):
if ug_err is None:
if opts.checkfunc:
- try: _run_callback(opts.checkfunc, opts)
- except URLGrabError as ug_err: pass
+ try:
+ _run_callback(opts.checkfunc, opts)
+ except URLGrabError as e:
+ ug_err = e
if opts.progress_obj:
if opts.multi_progress_obj:
@@ -2320,8 +2322,10 @@ def parallel_wait(meter=None):
retry = opts.retry or 0
if opts.failure_callback:
opts.exception = ug_err
- try: _run_callback(opts.failure_callback, opts)
- except URLGrabError as ug_err:
+ try:
+ _run_callback(opts.failure_callback, opts)
+ except URLGrabError as e:
+ ug_err = e
retry = 0 # no retries
if opts.tries < retry and ug_err.errno in opts.retrycodes:
if ug_err.errno < 0 and opts.retry_no_cache: