import with_statement

This commit is contained in:
Romain Bignon 2010-06-09 12:09:18 +02:00
commit 70c10e69a9
2 changed files with 11 additions and 3 deletions

View file

@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from __future__ import with_statement
from weboob.backend import BaseBackend
from weboob.tools.browser import BrowserUnavailable
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply, Message
@ -72,7 +74,8 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesReply):
new = False
try:
thread = self.browser.get_content(article.id)
with self.browser:
thread = self.browser.get_content(article.id)
except BrowserUnavailable:
continue
@ -111,4 +114,5 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesReply):
self.storage.save()
def post_reply(self, thread_id, reply_id, title, message):
return self.browser.post_reply(thread_id, reply_id, title, message)
with self.browser:
return self.browser.post_reply(thread_id, reply_id, title, message)

View file

@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from __future__ import with_statement
from logging import warning
from weboob.backend import BaseBackend
@ -60,7 +62,9 @@ class FourChanBackend(BaseBackend, ICapMessages):
for message in self._iter_thread_messages(board, thread_wanted, only_new):
yield message
else:
for thread in self.browser.get_threads(board):
with self.browser:
threads = self.browser.get_threads(board)
for thread in threads:
for message in self._iter_thread_messages(board, thread.id, only_new):
yield message