def open_page(self, parent_window=None, url=None):
if url is None:
url_to_fetch = self.url
else:
url_to_fetch = url
if parent_window is not None:
self.parent_window = parent_window
self.progress.set_data(parent_window, _("Fetching data"), _("Wait a moment"), False)
retriever = Retriever(url_to_fetch, self.parent_window, self.progress, useurllib2=self.useurllib2)
retriever.start()
while retriever.isAlive():
self.progress.pulse()
if self.progress.status:
retriever.join()
while gtk.events_pending():
gtk.main_iteration()
data = None
try:
if retriever.exception is None:
if retriever.html:
ifile = file(retriever.html[0], "rb")
try:
data = ifile.read()
finally:
ifile.close()
# check for gzip compressed pages before decoding to unicode
if len(data) > 2 and data[0:2] == '\037\213':
data = gutils.decompress(data)
try:
# try to decode it strictly
if self.encode:
data = data.decode(self.encode)
except UnicodeDecodeError, exc:
# something is wrong, perhaps a wrong character set
# or some pages are not as strict as they should be
# (like OFDb, mixes utf8 with iso8859-1)
# I want to log the error here so that I can find it
# but the program should not terminate
log.error(exc)
data = data.decode(self.encode, 'ignore')
else:
gutils.urllib_error(_("Connection error"), self.parent_window)
except IOError:
log.exception('')
if url is None:
self.page = data
urlcleanup()
return data
评论列表
文章目录