handle confirmation, do error checking

This commit is contained in:
Christophe Benz 2010-11-19 15:30:55 +01:00 committed by Romain Bignon
commit ce7bdff246
3 changed files with 30 additions and 4 deletions

View file

@ -18,7 +18,8 @@
import sys
from weboob.capabilities.messages import ICapMessagesPost, Message
from weboob.core import CallErrors
from weboob.capabilities.messages import CantSendMessage, ICapMessagesPost, Message
from weboob.tools.application.repl import ReplApplication
from weboob.tools.application.formatters.iformatter import IFormatter
@ -37,6 +38,7 @@ class Boobmsg(ReplApplication):
post TO
Post a message to the specified receiver.
The receiver can have multiple comma-separated values.
The content of message is read on stdin.
"""
if not line:
@ -48,6 +50,13 @@ class Boobmsg(ReplApplication):
print 'Reading message content from stdin... Type ctrl-D from an empty line to post message.'
content = sys.stdin.read()
message = Message(thread=None, id=None, content=content, receiver=receiver)
self.do('post_message', message, backends=names)
try:
self.do('post_message', message, backends=names).wait()
except CallErrors, errors:
for backend, error, backtrace in errors:
if isinstance(error, CantSendMessage):
print >>sys.stderr, 'Error: %s' % error
else:
self.bcall_error_handler(backend, error, backtrace)
if self.interactive:
print 'Message sucessfully sent.'

View file

@ -18,9 +18,10 @@
import urllib
from .pages.compose import ComposePage, ConfirmPage
from .pages.compose import ClosePage, ComposePage, ConfirmPage, SentPage
from .pages.login import LoginPage
from weboob.capabilities.messages import CantSendMessage
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
@ -30,9 +31,11 @@ __all__ = ['SfrBrowser']
class SfrBrowser(BaseBrowser):
DOMAIN = 'www.sfr.fr'
PAGES = {
'http://messagerie-.+.sfr.fr/webmail/close_xms_tab.html': ClosePage,
'http://www.sfr.fr/xmscomposer/index.html\?todo=compose': ComposePage,
'http://www.sfr.fr/xmscomposer/mc/envoyer-texto-mms/confirm.html': ConfirmPage,
'https://www.sfr.fr/cas/login\?service=.*': LoginPage,
'http://www.sfr.fr/xmscomposer/mc/envoyer-texto-mms/send.html': SentPage,
}
def home(self):
@ -52,3 +55,7 @@ class SfrBrowser(BaseBrowser):
if not self.is_on_page(ComposePage):
self.location('http://www.sfr.fr/xmscomposer/index.html\?todo=compose')
self.page.post_message(message)
if self.is_on_page(ConfirmPage):
self.page.confirm()
if self.is_on_page(ClosePage):
raise CantSendMessage('Invalid receiver.')

View file

@ -19,7 +19,11 @@
from weboob.tools.browser import BasePage
__all__ = ['ComposePage', 'ConfirmPage']
__all__ = ['ClosePage', 'ComposePage', 'ConfirmPage', 'SentPage']
class ClosePage(BasePage):
pass
class ComposePage(BasePage):
@ -31,4 +35,10 @@ class ComposePage(BasePage):
class ConfirmPage(BasePage):
def confirm(self):
self.browser.select_form(nr=0)
self.browser.submit()
class SentPage(BasePage):
pass