use 'self.data is None' to test if data is already read or not

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3631 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2007-12-03 14:09:20 +00:00
parent 5591bbe052
commit 41bc0b2b32
4 changed files with 5 additions and 11 deletions

View file

@ -159,7 +159,7 @@ class FileUrl (urlbase.UrlBase):
"""
if not self.valid:
return ""
if self.has_content:
if self.data is not None:
return self.data
elif self.is_directory():
return self.get_directory_content()
@ -179,7 +179,6 @@ class FileUrl (urlbase.UrlBase):
self.data = data.encode("iso8859-1", "ignore")
self.dltime = time.time() - t
self.dlsize = len(self.data)
self.has_content = True
return self.data
def is_html (self):

View file

@ -219,7 +219,7 @@ class FtpUrl (internpaturl.InternPatternUrl, proxysupport.ProxySupport):
"""
if not self.valid:
return ""
if self.has_content:
if self.data is not None:
return self.data
t = time.time()
if self.is_directory():
@ -238,7 +238,6 @@ class FtpUrl (internpaturl.InternPatternUrl, proxysupport.ProxySupport):
buf.close()
self.dltime = time.time() - t
self.dlsize = len(self.data)
self.has_content = True
return self.data
def close_connection (self):

View file

@ -548,7 +548,7 @@ class HttpUrl (internpaturl.InternPatternUrl, proxysupport.ProxySupport):
@return: URL content, decompressed and decoded
@rtype: string
"""
if not self.has_content:
if self.data is None:
self.method = "GET"
response = self._get_http_response()
tries, response = self.follow_redirections(response,
@ -575,7 +575,6 @@ class HttpUrl (internpaturl.InternPatternUrl, proxysupport.ProxySupport):
f = StringIO.StringIO(self.data)
self.data = f.read()
self.dltime = time.time() - t
self.has_content = True
def is_html (self):
"""

View file

@ -149,10 +149,8 @@ class UrlBase (object):
self.checktime = 0
# connection object
self.url_connection = None
# data of url content
# data of url content, (data == None) means no data is available
self.data = None
# if data is filled
self.has_content = False
# cache keys, are set by build_url() calling set_cache_keys()
self.cache_url_key = None
self.cache_content_key = None
@ -597,12 +595,11 @@ class UrlBase (object):
"""
Precondition: url_connection is an opened URL.
"""
if not self.has_content:
if self.data is None:
t = time.time()
self.data = self.url_connection.read()
self.dltime = time.time() - t
self.dlsize = len(self.data)
self.has_content = True
return self.data
def check_content (self, warningregex):