This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author HansM
Recipients HansM
Date 2012-11-10.14:42:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1352558532.09.0.890578567494.issue16450@psf.upfronthosting.co.za>
In-reply-to
Content
Due to a misconfiguration, urllib.thishost() raises an IOError
on my laptop.  This causes urllib.urlopen to raise an exception.
A flaw in test_missing_localfile causes this exception to not be
reported.  The problem happens at line 230-235:

        try:
            self.assertTrue(os.path.exists(tmp_file))
            fp = urllib.urlopen(tmp_fileurl)
        finally:
            os.close(fd)
            fp.close()

On my laptop, urllib.urlopen raises a socket.gaierror.  This
means that the variable fp is never set, and the fp.close() at
line 235 raises an UnboundLoccalError, masking the socket error.

A quick fix would be:

        try:
            self.assertTrue(os.path.exists(tmp_file))
            fp = urllib.urlopen(tmp_fileurl)
            fp.close()
        finally:
            os.close(fd)

That way, the .close is only attempted if the open succeeds.
History
Date User Action Args
2012-11-10 14:42:12HansMsetrecipients: + HansM
2012-11-10 14:42:12HansMsetmessageid: <1352558532.09.0.890578567494.issue16450@psf.upfronthosting.co.za>
2012-11-10 14:42:12HansMlinkissue16450 messages
2012-11-10 14:42:11HansMcreate