From dfc4e973710a5e085a2b2ffce359e42813e5aca9 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sun, 3 Oct 2010 12:11:59 +0200 Subject: [PATCH] Fix content reading function. --- linkcheck/robotparser2.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/linkcheck/robotparser2.py b/linkcheck/robotparser2.py index 1dfc40a7..2c29dc5f 100755 --- a/linkcheck/robotparser2.py +++ b/linkcheck/robotparser2.py @@ -125,15 +125,17 @@ class RobotFileParser (object): @raise: ValueError on bad digest auth (a bug) """ f = urlutil.get_opener(self.user, self.password, self.proxy) + res = None try: - f.open(req) - ct = f.info().get("Content-Type") + res = f.open(req) + ct = res.info().get("Content-Type") if ct and ct.lower().startswith("text/plain"): - self.parse([line.strip() for line in f]) + self.parse([line.strip() for line in res]) else: self.allow_all = True finally: - f.close() + if res is not None: + res.close() def _add_entry (self, entry): """Add a parsed entry to entry list.