Use newer form of catching exceptions
autopep8 -i --select=W602 Also some other minor deprecated syntax changes, like "while 1". I did not commit the less obvious changes.
This commit is contained in:
parent
fb1b8bc5b8
commit
a6ad7e83ff
72 changed files with 151 additions and 154 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sqlite3 as sqlite
|
import sqlite3 as sqlite
|
||||||
except ImportError, e:
|
except ImportError as e:
|
||||||
from pysqlite2 import dbapi2 as sqlite
|
from pysqlite2 import dbapi2 as sqlite
|
||||||
|
|
||||||
from weboob.core import Weboob
|
from weboob.core import Weboob
|
||||||
|
|
@ -35,13 +35,13 @@ def main(filename):
|
||||||
weboob = Weboob()
|
weboob = Weboob()
|
||||||
try:
|
try:
|
||||||
hds = weboob.build_backend('hds')
|
hds = weboob.build_backend('hds')
|
||||||
except ModuleLoadError, e:
|
except ModuleLoadError as e:
|
||||||
print >>sys.stderr, 'Unable to load "hds" module: %s' % e
|
print >>sys.stderr, 'Unable to load "hds" module: %s' % e
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
db = sqlite.connect(database=filename, timeout=10.0)
|
db = sqlite.connect(database=filename, timeout=10.0)
|
||||||
except sqlite.OperationalError, err:
|
except sqlite.OperationalError as err:
|
||||||
print >>sys.stderr, 'Unable to open %s database: %s' % (filename, err)
|
print >>sys.stderr, 'Unable to open %s database: %s' % (filename, err)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ def main(filename):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
try:
|
try:
|
||||||
results = db.execute('SELECT id, author FROM stories')
|
results = db.execute('SELECT id, author FROM stories')
|
||||||
except sqlite.OperationalError, err:
|
except sqlite.OperationalError as err:
|
||||||
print >>sys.stderr, 'fail!\nUnable to read database: %s' % err
|
print >>sys.stderr, 'fail!\nUnable to read database: %s' % err
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh
|
||||||
children=[],
|
children=[],
|
||||||
flags=Message.IS_UNREAD)
|
flags=Message.IS_UNREAD)
|
||||||
yield thread.root
|
yield thread.root
|
||||||
except BrowserUnavailable, e:
|
except BrowserUnavailable as e:
|
||||||
self.logger.debug('No messages, browser is unavailable: %s' % e)
|
self.logger.debug('No messages, browser is unavailable: %s' % e)
|
||||||
pass # don't care about waiting
|
pass # don't care about waiting
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ class Decoder(object):
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
try:
|
try:
|
||||||
while 1:
|
while True:
|
||||||
self.process()
|
self.process()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print ''
|
print ''
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ class PriorityConnection(Optimization):
|
||||||
zipcode= 75001,
|
zipcode= 75001,
|
||||||
country= 'fr',
|
country= 'fr',
|
||||||
godfather= my_id)
|
godfather= my_id)
|
||||||
except AccountRegisterError, e:
|
except AccountRegisterError as e:
|
||||||
self.logger.warning('Unable to register account: %s' % e)
|
self.logger.warning('Unable to register account: %s' % e)
|
||||||
except CaptchaError:
|
except CaptchaError:
|
||||||
self.logger.warning('Unable to solve captcha... Retrying')
|
self.logger.warning('Unable to solve captcha... Retrying')
|
||||||
|
|
@ -156,12 +156,12 @@ class PriorityConnection(Optimization):
|
||||||
fakes = self.storage.get('priority_connection', 'fakes', default={})
|
fakes = self.storage.get('priority_connection', 'fakes', default={})
|
||||||
if len(fakes) == 0:
|
if len(fakes) == 0:
|
||||||
return
|
return
|
||||||
while 1:
|
while True:
|
||||||
name = random.choice(fakes.keys())
|
name = random.choice(fakes.keys())
|
||||||
fake = fakes[name]
|
fake = fakes[name]
|
||||||
try:
|
try:
|
||||||
browser = AuMBrowser(fake['username'], fake['password'], proxy=self.browser.proxy)
|
browser = AuMBrowser(fake['username'], fake['password'], proxy=self.browser.proxy)
|
||||||
except (AdopteBanned,BrowserIncorrectPassword), e:
|
except (AdopteBanned,BrowserIncorrectPassword) as e:
|
||||||
self.logger.warning('Fake %s can\'t login: %s' % (name, e))
|
self.logger.warning('Fake %s can\'t login: %s' % (name, e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ class ProfilesWalker(Optimization):
|
||||||
# We consider this profil hasn't been [correctly] analysed
|
# We consider this profil hasn't been [correctly] analysed
|
||||||
self.profiles_queue.add(id)
|
self.profiles_queue.add(id)
|
||||||
return
|
return
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
finally:
|
finally:
|
||||||
if self.view_cron is not None:
|
if self.view_cron is not None:
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,6 @@ class Visibility(Optimization):
|
||||||
try:
|
try:
|
||||||
with self.browser:
|
with self.browser:
|
||||||
self.browser.login()
|
self.browser.login()
|
||||||
except BrowserUnavailable, e:
|
except BrowserUnavailable as e:
|
||||||
print str(e)
|
print str(e)
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ class BanquePopulaire(BaseBrowser):
|
||||||
account = self.get_account(account.id)
|
account = self.get_account(account.id)
|
||||||
self.location('/cyber/internet/ContinueTask.do', urllib.urlencode(account._params))
|
self.location('/cyber/internet/ContinueTask.do', urllib.urlencode(account._params))
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
assert self.is_on_page(TransactionsPage)
|
assert self.is_on_page(TransactionsPage)
|
||||||
|
|
||||||
for tr in self.page.get_history():
|
for tr in self.page.get_history():
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ class LoginPage(BEPage):
|
||||||
def login(self, login, password):
|
def login(self, login, password):
|
||||||
try:
|
try:
|
||||||
vk = BNPVirtKeyboard(self)
|
vk = BNPVirtKeyboard(self)
|
||||||
except VirtKeyboardError, err:
|
except VirtKeyboardError as err:
|
||||||
self.logger.error("Error: %s" % err)
|
self.logger.error("Error: %s" % err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ class LoginPage(BasePage):
|
||||||
def login(self, login, password):
|
def login(self, login, password):
|
||||||
try:
|
try:
|
||||||
vk=BNPVirtKeyboard(self)
|
vk=BNPVirtKeyboard(self)
|
||||||
except VirtKeyboardError, err:
|
except VirtKeyboardError as err:
|
||||||
self.logger.error("Error: %s"%err)
|
self.logger.error("Error: %s"%err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -111,7 +111,7 @@ class ChangePasswordPage(BasePage):
|
||||||
def change_password(self, current, new):
|
def change_password(self, current, new):
|
||||||
try:
|
try:
|
||||||
vk=BNPVirtKeyboard(self)
|
vk=BNPVirtKeyboard(self)
|
||||||
except VirtKeyboardError, err:
|
except VirtKeyboardError as err:
|
||||||
self.logger.error("Error: %s"%err)
|
self.logger.error("Error: %s"%err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ class BPBrowser(BaseBrowser):
|
||||||
"""
|
"""
|
||||||
ops = self.page.get_history(deferred=True)
|
ops = self.page.get_history(deferred=True)
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
for tr in ops:
|
for tr in ops:
|
||||||
yield tr
|
yield tr
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class TransferSummary(BasePage):
|
||||||
#HACK for deal with bad encoding ...
|
#HACK for deal with bad encoding ...
|
||||||
try:
|
try:
|
||||||
text = p.text
|
text = p.text
|
||||||
except UnicodeDecodeError, error:
|
except UnicodeDecodeError as error:
|
||||||
text = error.object.strip()
|
text = error.object.strip()
|
||||||
|
|
||||||
match = re.search("Votre virement N.+ ([0-9]+) ", text)
|
match = re.search("Votre virement N.+ ([0-9]+) ", text)
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ class CaisseEpargne(BaseBrowser):
|
||||||
|
|
||||||
self.page.go_history(info)
|
self.page.go_history(info)
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
assert self.is_on_page(IndexPage)
|
assert self.is_on_page(IndexPage)
|
||||||
|
|
||||||
for tr in self.page.get_history():
|
for tr in self.page.get_history():
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class CreditCooperatif(BaseBrowser):
|
||||||
def get_history(self, account):
|
def get_history(self, account):
|
||||||
self.location('/banque/cpt/cpt/situationcomptes.do?lnkReleveAction=X&numeroExterne='+ account.id)
|
self.location('/banque/cpt/cpt/situationcomptes.do?lnkReleveAction=X&numeroExterne='+ account.id)
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
assert self.is_on_page(TransactionsPage)
|
assert self.is_on_page(TransactionsPage)
|
||||||
|
|
||||||
for tr in self.page.get_history():
|
for tr in self.page.get_history():
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class CDNBasePage(BasePage):
|
||||||
if start < 0:
|
if start < 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
if value is None:
|
if value is None:
|
||||||
value = ''
|
value = ''
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ class DLFP(BaseBrowser):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.submit()
|
self.submit()
|
||||||
except BrowserHTTPError, e:
|
except BrowserHTTPError as e:
|
||||||
raise CantSendMessage('Unable to send message to %s.%s: %s' % (thread, reply_id, e))
|
raise CantSendMessage('Unable to send message to %s.%s: %s' % (thread, reply_id, e))
|
||||||
|
|
||||||
if self.is_on_page(NodePage):
|
if self.is_on_page(NodePage):
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ class GDCVaultBrowser(BaseBrowser):
|
||||||
try:
|
try:
|
||||||
self.open_novisit(url)
|
self.open_novisit(url)
|
||||||
#headers = req.info()
|
#headers = req.info()
|
||||||
except HTTPError, e:
|
except HTTPError as e:
|
||||||
# print e.getcode()
|
# print e.getcode()
|
||||||
if e.getcode() == 302 and hasattr(e, 'hdrs'):
|
if e.getcode() == 302 and hasattr(e, 'hdrs'):
|
||||||
#print e.hdrs['Location']
|
#print e.hdrs['Location']
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ class VideoPage(BasePage):
|
||||||
if len(obj) > 0:
|
if len(obj) > 0:
|
||||||
try:
|
try:
|
||||||
title = unicode(obj[0].text)
|
title = unicode(obj[0].text)
|
||||||
except UnicodeDecodeError, e:
|
except UnicodeDecodeError as e:
|
||||||
title = None
|
title = None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -125,7 +125,7 @@ class VideoPage(BasePage):
|
||||||
# FIXME: 1013483 has buggus title (latin1)
|
# FIXME: 1013483 has buggus title (latin1)
|
||||||
# for now we just pass it as-is
|
# for now we just pass it as-is
|
||||||
title = obj[0].attrib['content']
|
title = obj[0].attrib['content']
|
||||||
except UnicodeDecodeError, e:
|
except UnicodeDecodeError as e:
|
||||||
# XXX: this doesn't even works!?
|
# XXX: this doesn't even works!?
|
||||||
title = obj[0].attrib['content'].decode('iso-5589-15')
|
title = obj[0].attrib['content'].decode('iso-5589-15')
|
||||||
|
|
||||||
|
|
@ -172,7 +172,7 @@ class VideoPage(BasePage):
|
||||||
|
|
||||||
|
|
||||||
#print req.code
|
#print req.code
|
||||||
except HTTPError, e:
|
except HTTPError as e:
|
||||||
#print e.getcode()
|
#print e.getcode()
|
||||||
if e.getcode() == 302 and hasattr(e, 'hdrs'):
|
if e.getcode() == 302 and hasattr(e, 'hdrs'):
|
||||||
#print e.hdrs['Location']
|
#print e.hdrs['Location']
|
||||||
|
|
@ -218,7 +218,7 @@ class VideoPage(BasePage):
|
||||||
self.browser.set_handle_redirect(False)
|
self.browser.set_handle_redirect(False)
|
||||||
try:
|
try:
|
||||||
self.browser.open_novisit(video.url)
|
self.browser.open_novisit(video.url)
|
||||||
except HTTPError, e:
|
except HTTPError as e:
|
||||||
if e.getcode() == 302 and hasattr(e, 'hdrs'):
|
if e.getcode() == 302 and hasattr(e, 'hdrs'):
|
||||||
video.url = unicode(e.hdrs['Location'])
|
video.url = unicode(e.hdrs['Location'])
|
||||||
self.browser.set_handle_redirect(True)
|
self.browser.set_handle_redirect(True)
|
||||||
|
|
@ -298,7 +298,7 @@ class VideoPage(BasePage):
|
||||||
# 1016634 has "Invalid Date"
|
# 1016634 has "Invalid Date"
|
||||||
try:
|
try:
|
||||||
video.date = parse_dt(obj.text)
|
video.date = parse_dt(obj.text)
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
video.date = NotAvailable
|
video.date = NotAvailable
|
||||||
|
|
||||||
obj = self.parser.select(config.getroot(), 'duration', 1)
|
obj = self.parser.select(config.getroot(), 'duration', 1)
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class LoginPage(BasePage):
|
||||||
def login(self, login, password):
|
def login(self, login, password):
|
||||||
try:
|
try:
|
||||||
vk=HelloBankVirtKeyboard(self)
|
vk=HelloBankVirtKeyboard(self)
|
||||||
except VirtKeyboardError,err:
|
except VirtKeyboardError as err:
|
||||||
self.logger.error("Error: %s"%err)
|
self.logger.error("Error: %s"%err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ class Ing(BaseBrowser):
|
||||||
|
|
||||||
index = 0 # index, we get always the same page, but with more informations
|
index = 0 # index, we get always the same page, but with more informations
|
||||||
hashlist = []
|
hashlist = []
|
||||||
while 1:
|
while True:
|
||||||
i = index
|
i = index
|
||||||
for transaction in self.page.get_transactions(index):
|
for transaction in self.page.get_transactions(index):
|
||||||
while transaction.id in hashlist:
|
while transaction.id in hashlist:
|
||||||
|
|
@ -227,7 +227,7 @@ class Ing(BaseBrowser):
|
||||||
"transfer_issuer_radio": subscription.id
|
"transfer_issuer_radio": subscription.id
|
||||||
}
|
}
|
||||||
self.location(self.billpage, urllib.urlencode(data))
|
self.location(self.billpage, urllib.urlencode(data))
|
||||||
while 1:
|
while True:
|
||||||
for bill in self.page.iter_bills(subscription.id):
|
for bill in self.page.iter_bills(subscription.id):
|
||||||
yield bill
|
yield bill
|
||||||
if self.page.islast():
|
if self.page.islast():
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class LoginPage(BasePage):
|
||||||
# 2) And now, the virtual Keyboard
|
# 2) And now, the virtual Keyboard
|
||||||
try:
|
try:
|
||||||
vk = INGVirtKeyboard(self)
|
vk = INGVirtKeyboard(self)
|
||||||
except VirtKeyboardError, err:
|
except VirtKeyboardError as err:
|
||||||
error("Error: %s" % err)
|
error("Error: %s" % err)
|
||||||
return False
|
return False
|
||||||
realpasswd = ""
|
realpasswd = ""
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ class TransferConfirmPage(BasePage):
|
||||||
def confirm(self, password):
|
def confirm(self, password):
|
||||||
try:
|
try:
|
||||||
vk = INGVirtKeyboard(self)
|
vk = INGVirtKeyboard(self)
|
||||||
except VirtKeyboardError, err:
|
except VirtKeyboardError as err:
|
||||||
error("Error: %s" % err)
|
error("Error: %s" % err)
|
||||||
return
|
return
|
||||||
realpasswd = ""
|
realpasswd = ""
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ class LoginPage(BasePage):
|
||||||
def login(self, login, passwd, agency):
|
def login(self, login, passwd, agency):
|
||||||
try:
|
try:
|
||||||
vk=LCLVirtKeyboard(self)
|
vk=LCLVirtKeyboard(self)
|
||||||
except VirtKeyboardError,err:
|
except VirtKeyboardError as err:
|
||||||
error("Error: %s"%err)
|
error("Error: %s"%err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ class OkCBackend(BaseBackend, ICapMessages, ICapContact, ICapMessagesPost):
|
||||||
# if m.flags & m.IS_UNREAD:
|
# if m.flags & m.IS_UNREAD:
|
||||||
# yield m
|
# yield m
|
||||||
|
|
||||||
# except BrowserUnavailable, e:
|
# except BrowserUnavailable as e:
|
||||||
# self.logger.debug('No messages, browser is unavailable: %s' % e)
|
# self.logger.debug('No messages, browser is unavailable: %s' % e)
|
||||||
# pass # don't care about waiting
|
# pass # don't care about waiting
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ class PastebinBrowser(BaseBrowser):
|
||||||
urllib.urlencode(data)).decode(self.ENCODING)
|
urllib.urlencode(data)).decode(self.ENCODING)
|
||||||
try:
|
try:
|
||||||
self._validate_api_response(res)
|
self._validate_api_response(res)
|
||||||
except BadAPIRequest, e:
|
except BadAPIRequest as e:
|
||||||
if str(e) == 'invalid login':
|
if str(e) == 'invalid login':
|
||||||
raise BrowserIncorrectPassword()
|
raise BrowserIncorrectPassword()
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ class PhpBB(BaseBrowser):
|
||||||
assert self.is_on_page(TopicPage)
|
assert self.is_on_page(TopicPage)
|
||||||
|
|
||||||
parent = 0
|
parent = 0
|
||||||
while 1:
|
while True:
|
||||||
for post in self.page.iter_posts():
|
for post in self.page.iter_posts():
|
||||||
if stop_id and post.id >= stop_id:
|
if stop_id and post.id >= stop_id:
|
||||||
return
|
return
|
||||||
|
|
@ -117,7 +117,7 @@ class PhpBB(BaseBrowser):
|
||||||
assert self.is_on_page(TopicPage)
|
assert self.is_on_page(TopicPage)
|
||||||
|
|
||||||
child = None
|
child = None
|
||||||
while 1:
|
while True:
|
||||||
for post in self.page.riter_posts():
|
for post in self.page.riter_posts():
|
||||||
if child:
|
if child:
|
||||||
child.parent = post.id
|
child.parent = post.id
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,6 @@ class PiratebayTest(BackendTest):
|
||||||
assert isinstance(full_torrent.description, basestring)
|
assert isinstance(full_torrent.description, basestring)
|
||||||
try:
|
try:
|
||||||
assert self.backend.get_torrent_file(torrent.id)
|
assert self.backend.get_torrent_file(torrent.id)
|
||||||
except MagnetOnly, e:
|
except MagnetOnly as e:
|
||||||
assert e.magnet.startswith('magnet:')
|
assert e.magnet.startswith('magnet:')
|
||||||
assert e.magnet == full_torrent.magnet
|
assert e.magnet == full_torrent.magnet
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ class SeLogerBrowser(BaseBrowser):
|
||||||
|
|
||||||
self.location(self.buildurl('http://ws.seloger.com/search.xml', **data))
|
self.location(self.buildurl('http://ws.seloger.com/search.xml', **data))
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
assert self.is_on_page(SearchResultsPage)
|
assert self.is_on_page(SearchResultsPage)
|
||||||
|
|
||||||
for housing in self.page.iter_housings():
|
for housing in self.page.iter_housings():
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ class AccountHistory(BasePage):
|
||||||
# There are no transactions in this kind of account
|
# There are no transactions in this kind of account
|
||||||
return
|
return
|
||||||
|
|
||||||
while 1:
|
while True:
|
||||||
d = XML(self.browser.readurl(url))
|
d = XML(self.browser.readurl(url))
|
||||||
try:
|
try:
|
||||||
el = self.parser.select(d, '//dataBody', 1, 'xpath')
|
el = self.parser.select(d, '//dataBody', 1, 'xpath')
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class LoginPage(BasePage):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
img.build_tiles()
|
img.build_tiles()
|
||||||
except TileError, err:
|
except TileError as err:
|
||||||
error("Error: %s" % err)
|
error("Error: %s" % err)
|
||||||
if err.tile:
|
if err.tile:
|
||||||
err.tile.display()
|
err.tile.display()
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ class LoginPage(SGPEPage):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
img.build_tiles()
|
img.build_tiles()
|
||||||
except TileError, err:
|
except TileError as err:
|
||||||
error("Error: %s" % err)
|
error("Error: %s" % err)
|
||||||
if err.tile:
|
if err.tile:
|
||||||
err.tile.display()
|
err.tile.display()
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ class VideoPage(BasePage):
|
||||||
self.browser.set_handle_redirect(False)
|
self.browser.set_handle_redirect(False)
|
||||||
try:
|
try:
|
||||||
self.browser.open_novisit(v.url)
|
self.browser.open_novisit(v.url)
|
||||||
except HTTPError, e:
|
except HTTPError as e:
|
||||||
if e.getcode() == 302 and hasattr(e, 'hdrs'):
|
if e.getcode() == 302 and hasattr(e, 'hdrs'):
|
||||||
#print e.hdrs['Location']
|
#print e.hdrs['Location']
|
||||||
v.url = unicode(e.hdrs['Location'])
|
v.url = unicode(e.hdrs['Location'])
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ class YoutubeBackend(BaseBackend, ICapVideo, ICapCollection):
|
||||||
yt_service.ssl = True
|
yt_service.ssl = True
|
||||||
try:
|
try:
|
||||||
entry = yt_service.GetYouTubeVideoEntry(video_id=_id)
|
entry = yt_service.GetYouTubeVideoEntry(video_id=_id)
|
||||||
except gdata.service.Error, e:
|
except gdata.service.Error as e:
|
||||||
if e.args[0]['status'] == 400:
|
if e.args[0]['status'] == 400:
|
||||||
return None
|
return None
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ for root, dirs, files in os.walk(sys.argv[1]):
|
||||||
s = "from %s import %s" % (root.strip('/').replace('/', '.'), f[:-3])
|
s = "from %s import %s" % (root.strip('/').replace('/', '.'), f[:-3])
|
||||||
try:
|
try:
|
||||||
exec s
|
exec s
|
||||||
except ImportError, e:
|
except ImportError as e:
|
||||||
print >>sys.stderr, str(e)
|
print >>sys.stderr, str(e)
|
||||||
else:
|
else:
|
||||||
m = eval(f[:-3])
|
m = eval(f[:-3])
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ def main():
|
||||||
desc = ("", "U", imp.PY_SOURCE)
|
desc = ("", "U", imp.PY_SOURCE)
|
||||||
try:
|
try:
|
||||||
script = imp.load_module("scripts.%s" % fname, f, tmpfile, desc)
|
script = imp.load_module("scripts.%s" % fname, f, tmpfile, desc)
|
||||||
except ImportError, e:
|
except ImportError as e:
|
||||||
print >>sys.stderr, "Unable to load the %s script (%s)" \
|
print >>sys.stderr, "Unable to load the %s script (%s)" \
|
||||||
% (fname, e)
|
% (fname, e)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ class Boobill(ReplApplication):
|
||||||
try:
|
try:
|
||||||
with open(dest, 'w') as f:
|
with open(dest, 'w') as f:
|
||||||
f.write(buf)
|
f.write(buf)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write bill in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write bill in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
return
|
return
|
||||||
|
|
@ -210,7 +210,7 @@ class Boobill(ReplApplication):
|
||||||
try:
|
try:
|
||||||
with open(dest, 'w') as f:
|
with open(dest, 'w') as f:
|
||||||
f.write(buf)
|
f.write(buf)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write bill in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write bill in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -373,7 +373,7 @@ class Boobmsg(ReplApplication):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.do('post_message', message, backends=backend_name).wait()
|
self.do('post_message', message, backends=backend_name).wait()
|
||||||
except CallErrors, errors:
|
except CallErrors as errors:
|
||||||
self.bcall_errors_handler(errors)
|
self.bcall_errors_handler(errors)
|
||||||
else:
|
else:
|
||||||
if self.interactive:
|
if self.interactive:
|
||||||
|
|
|
||||||
|
|
@ -490,11 +490,11 @@ class Cineoob(ReplApplication):
|
||||||
try:
|
try:
|
||||||
with open(dest, 'w') as f:
|
with open(dest, 'w') as f:
|
||||||
f.write(buf)
|
f.write(buf)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
return
|
return
|
||||||
except CallErrors, errors:
|
except CallErrors as errors:
|
||||||
for backend, error, backtrace in errors:
|
for backend, error, backtrace in errors:
|
||||||
if isinstance(error, MagnetOnly):
|
if isinstance(error, MagnetOnly):
|
||||||
print >>sys.stderr, u'Error(%s): No direct URL available, ' \
|
print >>sys.stderr, u'Error(%s): No direct URL available, ' \
|
||||||
|
|
@ -598,11 +598,11 @@ class Cineoob(ReplApplication):
|
||||||
try:
|
try:
|
||||||
with open(dest, 'w') as f:
|
with open(dest, 'w') as f:
|
||||||
f.write(buf)
|
f.write(buf)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write file in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write file in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
return
|
return
|
||||||
except CallErrors, errors:
|
except CallErrors as errors:
|
||||||
for backend, error, backtrace in errors:
|
for backend, error, backtrace in errors:
|
||||||
self.bcall_error_handler(backend, error, backtrace)
|
self.bcall_error_handler(backend, error, backtrace)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ class Cookboob(ReplApplication):
|
||||||
try:
|
try:
|
||||||
with codecs.open(dest, 'w', 'utf-8') as f:
|
with codecs.open(dest, 'w', 'utf-8') as f:
|
||||||
f.write(xmlstring)
|
f.write(xmlstring)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write .kreml in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write .kreml in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ class HaveDate(Boobmsg):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.do('init_optimizations').wait()
|
self.do('init_optimizations').wait()
|
||||||
except CallErrors, e:
|
except CallErrors as e:
|
||||||
self.bcall_errors_handler(e)
|
self.bcall_errors_handler(e)
|
||||||
|
|
||||||
optimizations = self.storage.get('optims')
|
optimizations = self.storage.get('optims')
|
||||||
|
|
@ -157,7 +157,7 @@ class HaveDate(Boobmsg):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
sys.stdout.write('.\n')
|
sys.stdout.write('.\n')
|
||||||
except CallErrors, errors:
|
except CallErrors as errors:
|
||||||
for backend, error, backtrace in errors:
|
for backend, error, backtrace in errors:
|
||||||
if isinstance(error, OptimizationNotFound):
|
if isinstance(error, OptimizationNotFound):
|
||||||
self.logger.error(u'Error(%s): Optimization "%s" not found' % (backend.name, optim_name))
|
self.logger.error(u'Error(%s): Optimization "%s" not found' % (backend.name, optim_name))
|
||||||
|
|
|
||||||
|
|
@ -66,14 +66,14 @@ class MonboobScheduler(Scheduler):
|
||||||
port = self.app.options.smtpd
|
port = self.app.options.smtpd
|
||||||
try:
|
try:
|
||||||
FakeSMTPD(self.app, host, int(port))
|
FakeSMTPD(self.app, host, int(port))
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
self.logger.error('Unable to start the SMTP daemon: %s' % e)
|
self.logger.error('Unable to start the SMTP daemon: %s' % e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# XXX Fuck, we shouldn't copy this piece of code from
|
# XXX Fuck, we shouldn't copy this piece of code from
|
||||||
# weboob.scheduler.Scheduler.run().
|
# weboob.scheduler.Scheduler.run().
|
||||||
try:
|
try:
|
||||||
while 1:
|
while True:
|
||||||
self.stop_event.wait(0.1)
|
self.stop_event.wait(0.1)
|
||||||
if self.app.options.smtpd:
|
if self.app.options.smtpd:
|
||||||
asyncore.loop(timeout=0.1, count=1)
|
asyncore.loop(timeout=0.1, count=1)
|
||||||
|
|
@ -178,10 +178,10 @@ class Monboob(ReplApplication):
|
||||||
content += unicode(s, charset)
|
content += unicode(s, charset)
|
||||||
else:
|
else:
|
||||||
content += unicode(s)
|
content += unicode(s)
|
||||||
except UnicodeError, e:
|
except UnicodeError as e:
|
||||||
self.logger.warning('Unicode error: %s' % e)
|
self.logger.warning('Unicode error: %s' % e)
|
||||||
continue
|
continue
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.logger.exception(e)
|
self.logger.exception(e)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
|
@ -235,7 +235,7 @@ class Monboob(ReplApplication):
|
||||||
content=content)
|
content=content)
|
||||||
try:
|
try:
|
||||||
backend.post_message(message)
|
backend.post_message(message)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
content = u'Unable to send message to %s:\n' % thread_id
|
content = u'Unable to send message to %s:\n' % thread_id
|
||||||
content += u'\n\t%s\n' % to_unicode(e)
|
content += u'\n\t%s\n' % to_unicode(e)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level == logging.DEBUG:
|
||||||
|
|
@ -269,7 +269,7 @@ class Monboob(ReplApplication):
|
||||||
for backend, message in self.weboob.do('iter_unread_messages'):
|
for backend, message in self.weboob.do('iter_unread_messages'):
|
||||||
if self.send_email(backend, message):
|
if self.send_email(backend, message):
|
||||||
backend.set_message_read(message)
|
backend.set_message_read(message)
|
||||||
except CallErrors, e:
|
except CallErrors as e:
|
||||||
self.bcall_errors_handler(e)
|
self.bcall_errors_handler(e)
|
||||||
|
|
||||||
def send_email(self, backend, mail):
|
def send_email(self, backend, mail):
|
||||||
|
|
@ -363,7 +363,7 @@ class Monboob(ReplApplication):
|
||||||
try:
|
try:
|
||||||
smtp = SMTP(self.config.get('smtp'))
|
smtp = SMTP(self.config.get('smtp'))
|
||||||
smtp.sendmail(sender, recipient, msg.as_string())
|
smtp.sendmail(sender, recipient, msg.as_string())
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.logger.error('Unable to deliver mail: %s' % e)
|
self.logger.error('Unable to deliver mail: %s' % e)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ class Pastoob(ReplApplication):
|
||||||
try:
|
try:
|
||||||
with codecs.open(filename, encoding=locale.getpreferredencoding()) as fp:
|
with codecs.open(filename, encoding=locale.getpreferredencoding()) as fp:
|
||||||
contents = fp.read()
|
contents = fp.read()
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to open file "%s": %s' % (filename, e.strerror)
|
print >>sys.stderr, 'Unable to open file "%s": %s' % (filename, e.strerror)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -382,8 +382,7 @@ class MainWindow(QtMainWindow):
|
||||||
if self.ui.backendEdit.count() == 0:
|
if self.ui.backendEdit.count() == 0:
|
||||||
self.backendsConfig()
|
self.backendsConfig()
|
||||||
|
|
||||||
langs = LANGUAGE_CONV.keys()
|
langs = sorted(LANGUAGE_CONV.keys())
|
||||||
langs.sort()
|
|
||||||
for lang in langs:
|
for lang in langs:
|
||||||
self.ui.langCombo.addItem(lang)
|
self.ui.langCombo.addItem(lang)
|
||||||
self.ui.langCombo.hide()
|
self.ui.langCombo.hide()
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,7 @@ class Movie(QFrame):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.ui = Ui_Movie()
|
self.ui = Ui_Movie()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
langs = LANGUAGE_CONV.keys()
|
langs = sorted(LANGUAGE_CONV.keys())
|
||||||
langs.sort()
|
|
||||||
for lang in langs:
|
for lang in langs:
|
||||||
self.ui.langCombo.addItem(lang)
|
self.ui.langCombo.addItem(lang)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ class Subtitle(QFrame):
|
||||||
try:
|
try:
|
||||||
with open(dest, 'w') as f:
|
with open(dest, 'w') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write subtitle file in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write subtitle file in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class Torrent(QFrame):
|
||||||
try:
|
try:
|
||||||
with open(unicode(dest), 'w') as f:
|
with open(unicode(dest), 'w') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ class Recipe(QFrame):
|
||||||
try:
|
try:
|
||||||
with codecs.open(dest, 'w', 'utf-8') as f:
|
with codecs.open(dest, 'w', 'utf-8') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write Krecipe file in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write Krecipe file in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ class Radioob(ReplApplication):
|
||||||
self.logger.debug(u'You can set the media_player key to the player you prefer in the radioob '
|
self.logger.debug(u'You can set the media_player key to the player you prefer in the radioob '
|
||||||
'configuration file.')
|
'configuration file.')
|
||||||
self.player.play(radio.streams[0], player_name=player_name, player_args=media_player_args)
|
self.player.play(radio.streams[0], player_name=player_name, player_args=media_player_args)
|
||||||
except (InvalidMediaPlayer, MediaPlayerNotFound), e:
|
except (InvalidMediaPlayer, MediaPlayerNotFound) as e:
|
||||||
print '%s\nRadio URL: %s' % (e, radio.streams[0].url)
|
print '%s\nRadio URL: %s' % (e, radio.streams[0].url)
|
||||||
|
|
||||||
def complete_info(self, text, line, *ignored):
|
def complete_info(self, text, line, *ignored):
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ class Suboob(ReplApplication):
|
||||||
try:
|
try:
|
||||||
with open(dest, 'w') as f:
|
with open(dest, 'w') as f:
|
||||||
f.write(buf)
|
f.write(buf)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write file in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write file in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ class Traveloob(ReplApplication):
|
||||||
try:
|
try:
|
||||||
filters.departure_time = self.parse_datetime(self.options.departure_time)
|
filters.departure_time = self.parse_datetime(self.options.departure_time)
|
||||||
filters.arrival_time = self.parse_datetime(self.options.arrival_time)
|
filters.arrival_time = self.parse_datetime(self.options.arrival_time)
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
print >>sys.stderr, 'Invalid datetime value: %s' % e
|
print >>sys.stderr, 'Invalid datetime value: %s' % e
|
||||||
print >>sys.stderr, 'Please enter a datetime in form "yyyy-mm-dd HH:MM" or "HH:MM".'
|
print >>sys.stderr, 'Please enter a datetime in form "yyyy-mm-dd HH:MM" or "HH:MM".'
|
||||||
return 1
|
return 1
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ class Videoob(ReplApplication):
|
||||||
self.logger.info(u'You can set the media_player key to the player you prefer in the videoob '
|
self.logger.info(u'You can set the media_player key to the player you prefer in the videoob '
|
||||||
'configuration file.')
|
'configuration file.')
|
||||||
self.player.play(video, player_name=player_name, player_args=media_player_args)
|
self.player.play(video, player_name=player_name, player_args=media_player_args)
|
||||||
except (InvalidMediaPlayer, MediaPlayerNotFound), e:
|
except (InvalidMediaPlayer, MediaPlayerNotFound) as e:
|
||||||
print '%s\nVideo URL: %s' % (e, video.url)
|
print '%s\nVideo URL: %s' % (e, video.url)
|
||||||
|
|
||||||
def complete_info(self, text, line, *ignored):
|
def complete_info(self, text, line, *ignored):
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ class WebContentEdit(ReplApplication):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
try:
|
try:
|
||||||
self.do('push_content', content, message, minor=minor, backends=[content.backend]).wait()
|
self.do('push_content', content, message, minor=minor, backends=[content.backend]).wait()
|
||||||
except CallErrors, e:
|
except CallErrors as e:
|
||||||
errors.errors += e.errors
|
errors.errors += e.errors
|
||||||
sys.stdout.write(' error (content saved in %s)\n' % path)
|
sys.stdout.write(' error (content saved in %s)\n' % path)
|
||||||
else:
|
else:
|
||||||
|
|
@ -136,7 +136,7 @@ class WebContentEdit(ReplApplication):
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
try:
|
try:
|
||||||
self.do('push_content', content, message, minor=minor, backends=[content.backend]).wait()
|
self.do('push_content', content, message, minor=minor, backends=[content.backend]).wait()
|
||||||
except CallErrors, e:
|
except CallErrors as e:
|
||||||
errors.errors += e.errors
|
errors.errors += e.errors
|
||||||
sys.stdout.write(' error\n')
|
sys.stdout.write(' error\n')
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ class WeboobCfg(ReplApplication):
|
||||||
for instance_name, name, params in sorted(self.weboob.backends_config.iter_backends()):
|
for instance_name, name, params in sorted(self.weboob.backends_config.iter_backends()):
|
||||||
try:
|
try:
|
||||||
module = self.weboob.modules_loader.get_or_load_module(name)
|
module = self.weboob.modules_loader.get_or_load_module(name)
|
||||||
except ModuleLoadError, e:
|
except ModuleLoadError as e:
|
||||||
self.logger.warning('Unable to load module %r: %s' % (name, e))
|
self.logger.warning('Unable to load module %r: %s' % (name, e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ class WeboobRepos(ReplApplication):
|
||||||
try:
|
try:
|
||||||
with open(index_file, 'r') as fp:
|
with open(index_file, 'r') as fp:
|
||||||
r.parse_index(fp)
|
r.parse_index(fp)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to open repository: %s' % e
|
print >>sys.stderr, 'Unable to open repository: %s' % e
|
||||||
print >>sys.stderr, 'Use the "create" command before.'
|
print >>sys.stderr, 'Use the "create" command before.'
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -131,7 +131,7 @@ class WeboobRepos(ReplApplication):
|
||||||
if not os.path.exists(krname):
|
if not os.path.exists(krname):
|
||||||
raise Exception('No valid key file found.')
|
raise Exception('No valid key file found.')
|
||||||
kr_mtime = mktime(strptime(str(r.key_update), '%Y%m%d%H%M'))
|
kr_mtime = mktime(strptime(str(r.key_update), '%Y%m%d%H%M'))
|
||||||
os.chmod(krname, 0644)
|
os.chmod(krname, 0o644)
|
||||||
os.utime(krname, (kr_mtime, kr_mtime))
|
os.utime(krname, (kr_mtime, kr_mtime))
|
||||||
else:
|
else:
|
||||||
print 'Keyring is up to date'
|
print 'Keyring is up to date'
|
||||||
|
|
|
||||||
|
|
@ -137,11 +137,11 @@ class Weboorrents(ReplApplication):
|
||||||
try:
|
try:
|
||||||
with open(dest, 'w') as f:
|
with open(dest, 'w') as f:
|
||||||
f.write(buf)
|
f.write(buf)
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
|
print >>sys.stderr, 'Unable to write .torrent in "%s": %s' % (dest, e)
|
||||||
return 1
|
return 1
|
||||||
return
|
return
|
||||||
except CallErrors, errors:
|
except CallErrors as errors:
|
||||||
for backend, error, backtrace in errors:
|
for backend, error, backtrace in errors:
|
||||||
if isinstance(error, MagnetOnly):
|
if isinstance(error, MagnetOnly):
|
||||||
print >>sys.stderr, u'Error(%s): No direct URL available, ' \
|
print >>sys.stderr, u'Error(%s): No direct URL available, ' \
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,11 @@ class BackendsConfig(object):
|
||||||
fptr.close()
|
fptr.close()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
os.mknod(confpath, 0600)
|
os.mknod(confpath, 0o600)
|
||||||
except OSError:
|
except OSError:
|
||||||
fptr = open(confpath, 'w')
|
fptr = open(confpath, 'w')
|
||||||
fptr.close()
|
fptr.close()
|
||||||
os.chmod(confpath, 0600)
|
os.chmod(confpath, 0o600)
|
||||||
else:
|
else:
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
if mode & stat.S_IRGRP or mode & stat.S_IROTH:
|
if mode & stat.S_IRGRP or mode & stat.S_IROTH:
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ class BackendsCall(object):
|
||||||
result = function(backend, *args, **kwargs)
|
result = function(backend, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
result = getattr(backend, function)(*args, **kwargs)
|
result = getattr(backend, function)(*args, **kwargs)
|
||||||
except Exception, error:
|
except Exception as error:
|
||||||
self.logger.debug('%s: Called function %s raised an error: %r' % (backend, function, error))
|
self.logger.debug('%s: Called function %s raised an error: %r' % (backend, function, error))
|
||||||
self._store_error(backend, error)
|
self._store_error(backend, error)
|
||||||
else:
|
else:
|
||||||
|
|
@ -125,7 +125,7 @@ class BackendsCall(object):
|
||||||
# Lock mutex only in loop in case the iterator is slow
|
# Lock mutex only in loop in case the iterator is slow
|
||||||
# (for example if backend do some parsing operations)
|
# (for example if backend do some parsing operations)
|
||||||
self._store_result(backend, subresult)
|
self._store_result(backend, subresult)
|
||||||
except Exception, error:
|
except Exception as error:
|
||||||
self._store_error(backend, error)
|
self._store_error(backend, error)
|
||||||
else:
|
else:
|
||||||
self._store_result(backend, result)
|
self._store_result(backend, result)
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ class ModulesLoader(object):
|
||||||
for existing_module_name in self.iter_existing_module_names():
|
for existing_module_name in self.iter_existing_module_names():
|
||||||
try:
|
try:
|
||||||
self.load_module(existing_module_name)
|
self.load_module(existing_module_name)
|
||||||
except ModuleLoadError, e:
|
except ModuleLoadError as e:
|
||||||
self.logger.warning(e)
|
self.logger.warning(e)
|
||||||
|
|
||||||
def load_module(self, module_name):
|
def load_module(self, module_name):
|
||||||
|
|
@ -139,7 +139,7 @@ class ModulesLoader(object):
|
||||||
finally:
|
finally:
|
||||||
if fp:
|
if fp:
|
||||||
fp.close()
|
fp.close()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level == logging.DEBUG:
|
||||||
self.logger.exception(e)
|
self.logger.exception(e)
|
||||||
raise ModuleLoadError(module_name, e)
|
raise ModuleLoadError(module_name, e)
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ class Weboob(object):
|
||||||
module = None
|
module = None
|
||||||
try:
|
try:
|
||||||
module = self.modules_loader.get_or_load_module(module_name)
|
module = self.modules_loader.get_or_load_module(module_name)
|
||||||
except ModuleLoadError, e:
|
except ModuleLoadError as e:
|
||||||
self.logger.error(u'Unable to load module "%s": %s' % (module_name, e))
|
self.logger.error(u'Unable to load module "%s": %s' % (module_name, e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -233,7 +233,7 @@ class Weboob(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
backend_instance = module.create_instance(self, instance_name, params, storage)
|
backend_instance = module.create_instance(self, instance_name, params, storage)
|
||||||
except BaseBackend.ConfigError, e:
|
except BaseBackend.ConfigError as e:
|
||||||
if errors is not None:
|
if errors is not None:
|
||||||
errors.append(self.LoadError(instance_name, e))
|
errors.append(self.LoadError(instance_name, e))
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ class Repository(object):
|
||||||
filename = os.path.join(self.localurl2path(), self.INDEX)
|
filename = os.path.join(self.localurl2path(), self.INDEX)
|
||||||
try:
|
try:
|
||||||
fp = open(filename, 'r')
|
fp = open(filename, 'r')
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
# This local repository doesn't contain a built modules.list index.
|
# This local repository doesn't contain a built modules.list index.
|
||||||
self.name = Repositories.url2filename(self.url)
|
self.name = Repositories.url2filename(self.url)
|
||||||
self.build_index(self.localurl2path(), filename)
|
self.build_index(self.localurl2path(), filename)
|
||||||
|
|
@ -182,7 +182,7 @@ class Repository(object):
|
||||||
browser = WeboobBrowser()
|
browser = WeboobBrowser()
|
||||||
try:
|
try:
|
||||||
fp = browser.openurl(posixpath.join(self.url, self.INDEX))
|
fp = browser.openurl(posixpath.join(self.url, self.INDEX))
|
||||||
except BrowserUnavailable, e:
|
except BrowserUnavailable as e:
|
||||||
raise RepositoryUnavailable(unicode(e))
|
raise RepositoryUnavailable(unicode(e))
|
||||||
|
|
||||||
self.parse_index(fp)
|
self.parse_index(fp)
|
||||||
|
|
@ -212,7 +212,7 @@ class Repository(object):
|
||||||
try:
|
try:
|
||||||
keyring_data = browser.readurl(posixpath.join(self.url, self.KEYRING))
|
keyring_data = browser.readurl(posixpath.join(self.url, self.KEYRING))
|
||||||
sig_data = browser.readurl(posixpath.join(self.url, self.KEYRING + '.sig'))
|
sig_data = browser.readurl(posixpath.join(self.url, self.KEYRING + '.sig'))
|
||||||
except BrowserUnavailable, e:
|
except BrowserUnavailable as e:
|
||||||
raise RepositoryUnavailable(unicode(e))
|
raise RepositoryUnavailable(unicode(e))
|
||||||
if keyring.exists():
|
if keyring.exists():
|
||||||
if not keyring.is_valid(keyring_data, sig_data):
|
if not keyring.is_valid(keyring_data, sig_data):
|
||||||
|
|
@ -241,9 +241,9 @@ class Repository(object):
|
||||||
self.maintainer = items['maintainer']
|
self.maintainer = items['maintainer']
|
||||||
self.signed = bool(int(items.get('signed', '0')))
|
self.signed = bool(int(items.get('signed', '0')))
|
||||||
self.key_update = int(items.get('key_update', '0'))
|
self.key_update = int(items.get('key_update', '0'))
|
||||||
except KeyError, e:
|
except KeyError as e:
|
||||||
raise RepositoryUnavailable('Missing global parameters in repository: %s' % e)
|
raise RepositoryUnavailable('Missing global parameters in repository: %s' % e)
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
raise RepositoryUnavailable('Incorrect value in repository parameters: %s' % e)
|
raise RepositoryUnavailable('Incorrect value in repository parameters: %s' % e)
|
||||||
|
|
||||||
if len(self.name) == 0:
|
if len(self.name) == 0:
|
||||||
|
|
@ -297,7 +297,7 @@ class Repository(object):
|
||||||
finally:
|
finally:
|
||||||
if fp:
|
if fp:
|
||||||
fp.close()
|
fp.close()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print >>sys.stderr, 'Unable to build module %s: [%s] %s' % (name, type(e).__name__, e)
|
print >>sys.stderr, 'Unable to build module %s: [%s] %s' % (name, type(e).__name__, e)
|
||||||
else:
|
else:
|
||||||
m = ModuleInfo(module.name)
|
m = ModuleInfo(module.name)
|
||||||
|
|
@ -538,7 +538,7 @@ class Repositories(object):
|
||||||
def _parse_source_list(self):
|
def _parse_source_list(self):
|
||||||
l = []
|
l = []
|
||||||
with open(self.sources_list, 'r') as f:
|
with open(self.sources_list, 'r') as f:
|
||||||
for line in f.xreadlines():
|
for line in f:
|
||||||
line = line.strip() % {'version': self.version}
|
line = line.strip() % {'version': self.version}
|
||||||
m = re.match('(file|https?)://.*', line)
|
m = re.match('(file|https?)://.*', line)
|
||||||
if m:
|
if m:
|
||||||
|
|
@ -572,7 +572,7 @@ class Repositories(object):
|
||||||
else:
|
else:
|
||||||
progress.error('Cannot find gpgv to check for repository authenticity.\n'
|
progress.error('Cannot find gpgv to check for repository authenticity.\n'
|
||||||
'You should install GPG for better security.')
|
'You should install GPG for better security.')
|
||||||
except RepositoryUnavailable, e:
|
except RepositoryUnavailable as e:
|
||||||
progress.error('Unable to load repository: %s' % e)
|
progress.error('Unable to load repository: %s' % e)
|
||||||
else:
|
else:
|
||||||
self.repositories.append(repository)
|
self.repositories.append(repository)
|
||||||
|
|
@ -617,7 +617,7 @@ class Repositories(object):
|
||||||
inst_progress = InstallProgress(n)
|
inst_progress = InstallProgress(n)
|
||||||
try:
|
try:
|
||||||
self.install(info, inst_progress)
|
self.install(info, inst_progress)
|
||||||
except ModuleInstallError, e:
|
except ModuleInstallError as e:
|
||||||
inst_progress.progress(1.0, unicode(e))
|
inst_progress.progress(1.0, unicode(e))
|
||||||
|
|
||||||
def install(self, module, progress=IProgress()):
|
def install(self, module, progress=IProgress()):
|
||||||
|
|
@ -657,7 +657,7 @@ class Repositories(object):
|
||||||
progress.progress(0.2, 'Downloading module...')
|
progress.progress(0.2, 'Downloading module...')
|
||||||
try:
|
try:
|
||||||
tardata = browser.readurl(module.url)
|
tardata = browser.readurl(module.url)
|
||||||
except BrowserUnavailable, e:
|
except BrowserUnavailable as e:
|
||||||
raise ModuleInstallError('Unable to fetch module: %s' % e)
|
raise ModuleInstallError('Unable to fetch module: %s' % e)
|
||||||
|
|
||||||
# Check signature
|
# Check signature
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ class Scheduler(IScheduler):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
while 1:
|
while True:
|
||||||
self.stop_event.wait(0.1)
|
self.stop_event.wait(0.1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self._wait_to_stop()
|
self._wait_to_stop()
|
||||||
|
|
|
||||||
|
|
@ -351,7 +351,7 @@ class BaseApplication(object):
|
||||||
def create_logging_file_handler(self, filename):
|
def create_logging_file_handler(self, filename):
|
||||||
try:
|
try:
|
||||||
stream = open(filename, 'w')
|
stream = open(filename, 'w')
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
self.logger.error('Unable to create the logging file: %s' % e)
|
self.logger.error('Unable to create the logging file: %s' % e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
|
|
@ -383,7 +383,7 @@ class BaseApplication(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
app = klass()
|
app = klass()
|
||||||
except BackendsConfig.WrongPermissions, e:
|
except BackendsConfig.WrongPermissions as e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
@ -396,10 +396,10 @@ class BaseApplication(object):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except EOFError:
|
except EOFError:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except ConfigError, e:
|
except ConfigError as e:
|
||||||
print >>sys.stderr, 'Configuration error: %s' % e
|
print >>sys.stderr, 'Configuration error: %s' % e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except CallErrors, e:
|
except CallErrors as e:
|
||||||
app.bcall_errors_handler(e)
|
app.bcall_errors_handler(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ class ConsoleApplication(BaseApplication):
|
||||||
def run(klass, args=None):
|
def run(klass, args=None):
|
||||||
try:
|
try:
|
||||||
super(ConsoleApplication, klass).run(args)
|
super(ConsoleApplication, klass).run(args)
|
||||||
except BackendNotFound, e:
|
except BackendNotFound as e:
|
||||||
print 'Error: Backend "%s" not found.' % e
|
print 'Error: Backend "%s" not found.' % e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
@ -223,7 +223,7 @@ class ConsoleApplication(BaseApplication):
|
||||||
def register_backend(self, name, ask_add=True):
|
def register_backend(self, name, ask_add=True):
|
||||||
try:
|
try:
|
||||||
backend = self.weboob.modules_loader.get_or_load_module(name)
|
backend = self.weboob.modules_loader.get_or_load_module(name)
|
||||||
except ModuleLoadError, e:
|
except ModuleLoadError as e:
|
||||||
backend = None
|
backend = None
|
||||||
|
|
||||||
if not backend:
|
if not backend:
|
||||||
|
|
@ -240,7 +240,7 @@ class ConsoleApplication(BaseApplication):
|
||||||
website = 'on website %s' % backend.website
|
website = 'on website %s' % backend.website
|
||||||
else:
|
else:
|
||||||
website = 'with backend %s' % backend.name
|
website = 'with backend %s' % backend.name
|
||||||
while 1:
|
while True:
|
||||||
asked_config = False
|
asked_config = False
|
||||||
for key, prop in backend.klass.ACCOUNT_REGISTER_PROPERTIES.iteritems():
|
for key, prop in backend.klass.ACCOUNT_REGISTER_PROPERTIES.iteritems():
|
||||||
if not asked_config:
|
if not asked_config:
|
||||||
|
|
@ -254,7 +254,7 @@ class ConsoleApplication(BaseApplication):
|
||||||
print '-----------------------------%s' % ('-' * len(website))
|
print '-----------------------------%s' % ('-' * len(website))
|
||||||
try:
|
try:
|
||||||
backend.klass.register_account(account)
|
backend.klass.register_account(account)
|
||||||
except AccountRegisterError, e:
|
except AccountRegisterError as e:
|
||||||
print u'%s' % e
|
print u'%s' % e
|
||||||
if self.ask('Do you want to try again?', default=True):
|
if self.ask('Do you want to try again?', default=True):
|
||||||
continue
|
continue
|
||||||
|
|
@ -275,7 +275,7 @@ class ConsoleApplication(BaseApplication):
|
||||||
def install_module(self, name):
|
def install_module(self, name):
|
||||||
try:
|
try:
|
||||||
self.weboob.repositories.install(name)
|
self.weboob.repositories.install(name)
|
||||||
except ModuleInstallError, e:
|
except ModuleInstallError as e:
|
||||||
print >>sys.stderr, 'Unable to install module "%s": %s' % (name, e)
|
print >>sys.stderr, 'Unable to install module "%s": %s' % (name, e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -307,7 +307,7 @@ class ConsoleApplication(BaseApplication):
|
||||||
items.update(params)
|
items.update(params)
|
||||||
params = items
|
params = items
|
||||||
config = module.config.load(self.weboob, bname, name, params, nofail=True)
|
config = module.config.load(self.weboob, bname, name, params, nofail=True)
|
||||||
except ModuleLoadError, e:
|
except ModuleLoadError as e:
|
||||||
print >>sys.stderr, 'Unable to load module "%s": %s' % (name, e)
|
print >>sys.stderr, 'Unable to load module "%s": %s' % (name, e)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
@ -441,7 +441,7 @@ class ConsoleApplication(BaseApplication):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
v.set(line)
|
v.set(line)
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
print >>sys.stderr, u'Error: %s' % e
|
print >>sys.stderr, u'Error: %s' % e
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -37,15 +37,14 @@ class FormattersLoader(object):
|
||||||
def get_available_formatters(self):
|
def get_available_formatters(self):
|
||||||
l = set(self.formatters.iterkeys())
|
l = set(self.formatters.iterkeys())
|
||||||
l = l.union(self.BUILTINS)
|
l = l.union(self.BUILTINS)
|
||||||
l = list(l)
|
l = sorted(l)
|
||||||
l.sort()
|
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def build_formatter(self, name):
|
def build_formatter(self, name):
|
||||||
if not name in self.formatters:
|
if not name in self.formatters:
|
||||||
try:
|
try:
|
||||||
self.formatters[name] = self.load_builtin_formatter(name)
|
self.formatters[name] = self.load_builtin_formatter(name)
|
||||||
except ImportError, e:
|
except ImportError as e:
|
||||||
FormattersLoader.BUILTINS.remove(name)
|
FormattersLoader.BUILTINS.remove(name)
|
||||||
raise FormatterLoadError('Unable to load formatter "%s": %s' % (name, e))
|
raise FormatterLoadError('Unable to load formatter "%s": %s' % (name, e))
|
||||||
return self.formatters[name]()
|
return self.formatters[name]()
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ class BackendCfg(QDialog):
|
||||||
pd.setWindowModality(Qt.WindowModal)
|
pd.setWindowModality(Qt.WindowModal)
|
||||||
try:
|
try:
|
||||||
self.weboob.repositories.update(pd)
|
self.weboob.repositories.update(pd)
|
||||||
except ModuleInstallError, err:
|
except ModuleInstallError as err:
|
||||||
QMessageBox.critical(self, self.tr('Update error'),
|
QMessageBox.critical(self, self.tr('Update error'),
|
||||||
unicode(self.tr('Unable to update modules: %s' % (err))),
|
unicode(self.tr('Unable to update modules: %s' % (err))),
|
||||||
QMessageBox.Ok)
|
QMessageBox.Ok)
|
||||||
|
|
@ -206,7 +206,7 @@ class BackendCfg(QDialog):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.weboob.repositories.install(minfo, pd)
|
self.weboob.repositories.install(minfo, pd)
|
||||||
except ModuleInstallError, err:
|
except ModuleInstallError as err:
|
||||||
QMessageBox.critical(self, self.tr('Install error'),
|
QMessageBox.critical(self, self.tr('Install error'),
|
||||||
unicode(self.tr('Unable to install module %s: %s' % (minfo.name, err))),
|
unicode(self.tr('Unable to install module %s: %s' % (minfo.name, err))),
|
||||||
QMessageBox.Ok)
|
QMessageBox.Ok)
|
||||||
|
|
@ -442,7 +442,7 @@ class BackendCfg(QDialog):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
value = qtvalue.get_value()
|
value = qtvalue.get_value()
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
QMessageBox.critical(self, self.tr('Invalid value'),
|
QMessageBox.critical(self, self.tr('Invalid value'),
|
||||||
unicode(self.tr('Invalid value for field "%s":<br /><br />%s')) % (field.label, e))
|
unicode(self.tr('Invalid value for field "%s":<br /><br />%s')) % (field.label, e))
|
||||||
return
|
return
|
||||||
|
|
@ -507,7 +507,7 @@ class BackendCfg(QDialog):
|
||||||
for key, widget in props_widgets.iteritems():
|
for key, widget in props_widgets.iteritems():
|
||||||
try:
|
try:
|
||||||
v = widget.get_value()
|
v = widget.get_value()
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
QMessageBox.critical(self, self.tr('Invalid value'),
|
QMessageBox.critical(self, self.tr('Invalid value'),
|
||||||
unicode(self.tr('Invalid value for field "%s":<br /><br />%s')) % (key, e))
|
unicode(self.tr('Invalid value for field "%s":<br /><br />%s')) % (key, e))
|
||||||
end = False
|
end = False
|
||||||
|
|
@ -517,7 +517,7 @@ class BackendCfg(QDialog):
|
||||||
if end:
|
if end:
|
||||||
try:
|
try:
|
||||||
module.klass.register_account(account)
|
module.klass.register_account(account)
|
||||||
except AccountRegisterError, e:
|
except AccountRegisterError as e:
|
||||||
QMessageBox.critical(self, self.tr('Error during register'),
|
QMessageBox.critical(self, self.tr('Error during register'),
|
||||||
unicode(self.tr('Unable to register account %s:<br /><br />%s')) % (website, e))
|
unicode(self.tr('Unable to register account %s:<br /><br />%s')) % (website, e))
|
||||||
end = False
|
end = False
|
||||||
|
|
|
||||||
|
|
@ -150,12 +150,12 @@ class QtApplication(QApplication, BaseApplication):
|
||||||
return Weboob(scheduler=QtScheduler(self))
|
return Weboob(scheduler=QtScheduler(self))
|
||||||
|
|
||||||
def load_backends(self, *args, **kwargs):
|
def load_backends(self, *args, **kwargs):
|
||||||
while 1:
|
while True:
|
||||||
try:
|
try:
|
||||||
return BaseApplication.load_backends(self, *args, **kwargs)
|
return BaseApplication.load_backends(self, *args, **kwargs)
|
||||||
except VersionsMismatchError, e:
|
except VersionsMismatchError as e:
|
||||||
msg = 'Versions of modules mismatch with version of weboob.'
|
msg = 'Versions of modules mismatch with version of weboob.'
|
||||||
except ConfigError, e:
|
except ConfigError as e:
|
||||||
msg = unicode(e)
|
msg = unicode(e)
|
||||||
|
|
||||||
res = QMessageBox.question(None, 'Configuration error', u'%s\n\nDo you want to update repositories?' % msg, QMessageBox.Yes|QMessageBox.No)
|
res = QMessageBox.question(None, 'Configuration error', u'%s\n\nDo you want to update repositories?' % msg, QMessageBox.Yes|QMessageBox.No)
|
||||||
|
|
@ -168,7 +168,7 @@ class QtApplication(QApplication, BaseApplication):
|
||||||
pd.setWindowModality(Qt.WindowModal)
|
pd.setWindowModality(Qt.WindowModal)
|
||||||
try:
|
try:
|
||||||
self.weboob.update(pd)
|
self.weboob.update(pd)
|
||||||
except ModuleInstallError, err:
|
except ModuleInstallError as err:
|
||||||
QMessageBox.critical(None, self.tr('Update error'),
|
QMessageBox.critical(None, self.tr('Update error'),
|
||||||
unicode(self.tr('Unable to update repositories: %s' % err)),
|
unicode(self.tr('Unable to update repositories: %s' % err)),
|
||||||
QMessageBox.Ok)
|
QMessageBox.Ok)
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
id = '%s@%s' % (obj.id, obj.backend)
|
id = '%s@%s' % (obj.id, obj.backend)
|
||||||
try:
|
try:
|
||||||
return ConsoleApplication.parse_id(self, id, unique_backend)
|
return ConsoleApplication.parse_id(self, id, unique_backend)
|
||||||
except BackendNotGiven, e:
|
except BackendNotGiven as e:
|
||||||
backend_name = None
|
backend_name = None
|
||||||
while not backend_name:
|
while not backend_name:
|
||||||
print 'This command works with an unique backend. Availables:'
|
print 'This command works with an unique backend. Availables:'
|
||||||
|
|
@ -206,7 +206,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
try:
|
try:
|
||||||
backend = self.weboob.get_backend(obj.backend)
|
backend = self.weboob.get_backend(obj.backend)
|
||||||
return backend.fillobj(obj, fields)
|
return backend.fillobj(obj, fields)
|
||||||
except UserError, e:
|
except UserError as e:
|
||||||
self.bcall_error_handler(backend, e, '')
|
self.bcall_error_handler(backend, e, '')
|
||||||
|
|
||||||
_id, backend_name = self.parse_id(_id)
|
_id, backend_name = self.parse_id(_id)
|
||||||
|
|
@ -355,11 +355,11 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
return super(ReplApplication, self).onecmd(line)
|
return super(ReplApplication, self).onecmd(line)
|
||||||
except CallErrors, e:
|
except CallErrors as e:
|
||||||
self.bcall_errors_handler(e)
|
self.bcall_errors_handler(e)
|
||||||
except BackendNotGiven, e:
|
except BackendNotGiven as e:
|
||||||
print >>sys.stderr, 'Error: %s' % str(e)
|
print >>sys.stderr, 'Error: %s' % str(e)
|
||||||
except NotEnoughArguments, e:
|
except NotEnoughArguments as e:
|
||||||
print >>sys.stderr, 'Error: not enough arguments. %s' % str(e)
|
print >>sys.stderr, 'Error: not enough arguments. %s' % str(e)
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (KeyboardInterrupt, EOFError):
|
||||||
# ^C during a command process doesn't exit application.
|
# ^C during a command process doesn't exit application.
|
||||||
|
|
@ -739,7 +739,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.condition = ResultsCondition(line)
|
self.condition = ResultsCondition(line)
|
||||||
except ResultsConditionError, e:
|
except ResultsConditionError as e:
|
||||||
print >>sys.stderr, '%s' % e
|
print >>sys.stderr, '%s' % e
|
||||||
return 2
|
return 2
|
||||||
else:
|
else:
|
||||||
|
|
@ -977,7 +977,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
caps=ICapCollection):
|
caps=ICapCollection):
|
||||||
if res:
|
if res:
|
||||||
collections.append(res)
|
collections.append(res)
|
||||||
except CallErrors, errors:
|
except CallErrors as errors:
|
||||||
for backend, error, backtrace in errors.errors:
|
for backend, error, backtrace in errors.errors:
|
||||||
if isinstance(error, CollectionNotFound):
|
if isinstance(error, CollectionNotFound):
|
||||||
pass
|
pass
|
||||||
|
|
@ -1006,7 +1006,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
collections.append(res)
|
collections.append(res)
|
||||||
else:
|
else:
|
||||||
objects.append(res)
|
objects.append(res)
|
||||||
except CallErrors, errors:
|
except CallErrors as errors:
|
||||||
for backend, error, backtrace in errors.errors:
|
for backend, error, backtrace in errors.errors:
|
||||||
if isinstance(error, CollectionNotFound):
|
if isinstance(error, CollectionNotFound):
|
||||||
pass
|
pass
|
||||||
|
|
@ -1034,7 +1034,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
if len(self.objects) == 0 and len(self.collections) == 0:
|
if len(self.objects) == 0 and len(self.collections) == 0:
|
||||||
try:
|
try:
|
||||||
self.objects, self.collections = self._fetch_objects(objs=self.COLLECTION_OBJECTS)
|
self.objects, self.collections = self._fetch_objects(objs=self.COLLECTION_OBJECTS)
|
||||||
except CallErrors, errors:
|
except CallErrors as errors:
|
||||||
for backend, error, backtrace in errors.errors:
|
for backend, error, backtrace in errors.errors:
|
||||||
if isinstance(error, CollectionNotFound):
|
if isinstance(error, CollectionNotFound):
|
||||||
pass
|
pass
|
||||||
|
|
@ -1062,7 +1062,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.formatter = self.formatters_loader.build_formatter(name)
|
self.formatter = self.formatters_loader.build_formatter(name)
|
||||||
except FormatterLoadError, e:
|
except FormatterLoadError as e:
|
||||||
print >>sys.stderr, '%s' % e
|
print >>sys.stderr, '%s' % e
|
||||||
if self.DEFAULT_FORMATTER == name:
|
if self.DEFAULT_FORMATTER == name:
|
||||||
self.DEFAULT_FORMATTER = ReplApplication.DEFAULT_FORMATTER
|
self.DEFAULT_FORMATTER = ReplApplication.DEFAULT_FORMATTER
|
||||||
|
|
@ -1098,9 +1098,9 @@ class ReplApplication(Cmd, ConsoleApplication):
|
||||||
fields = None
|
fields = None
|
||||||
try:
|
try:
|
||||||
self.formatter.format(obj=result, selected_fields=fields, alias=alias)
|
self.formatter.format(obj=result, selected_fields=fields, alias=alias)
|
||||||
except FieldNotFound, e:
|
except FieldNotFound as e:
|
||||||
print >>sys.stderr, e
|
print >>sys.stderr, e
|
||||||
except MandatoryFieldsNotFound, e:
|
except MandatoryFieldsNotFound as e:
|
||||||
print >>sys.stderr, '%s Hint: select missing fields or use another formatter (ex: multiline).' % e
|
print >>sys.stderr, '%s Hint: select missing fields or use another formatter (ex: multiline).' % e
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ class BackendConfig(ValuesDict):
|
||||||
field = copy(field)
|
field = copy(field)
|
||||||
try:
|
try:
|
||||||
field.load(cfg.instname, value, cfg.weboob.callbacks)
|
field.load(cfg.instname, value, cfg.weboob.callbacks)
|
||||||
except ValueError, v:
|
except ValueError as v:
|
||||||
if not nofail:
|
if not nofail:
|
||||||
raise BaseBackend.ConfigError(
|
raise BaseBackend.ConfigError(
|
||||||
'Backend(%s): Configuration error for field "%s": %s' % (cfg.instname, name, v))
|
'Backend(%s): Configuration error for field "%s": %s' % (cfg.instname, name, v))
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ from weboob.tools.parsers import get_parser
|
||||||
# Try to load cookies
|
# Try to load cookies
|
||||||
try:
|
try:
|
||||||
from .firefox_cookies import FirefoxCookieJar
|
from .firefox_cookies import FirefoxCookieJar
|
||||||
except ImportError, e:
|
except ImportError as e:
|
||||||
warning("Unable to store cookies: %s" % e)
|
warning("Unable to store cookies: %s" % e)
|
||||||
HAVE_COOKIES = False
|
HAVE_COOKIES = False
|
||||||
else:
|
else:
|
||||||
|
|
@ -281,7 +281,7 @@ class StandardBrowser(mechanize.Browser):
|
||||||
try:
|
try:
|
||||||
return self._openurl(*args, **kwargs)
|
return self._openurl(*args, **kwargs)
|
||||||
except (mechanize.BrowserStateError, mechanize.response_seek_wrapper,
|
except (mechanize.BrowserStateError, mechanize.response_seek_wrapper,
|
||||||
urllib2.HTTPError, urllib2.URLError, BadStatusLine, ssl.SSLError), e:
|
urllib2.HTTPError, urllib2.URLError, BadStatusLine, ssl.SSLError) as e:
|
||||||
if isinstance(e, mechanize.BrowserStateError) and hasattr(self, 'home'):
|
if isinstance(e, mechanize.BrowserStateError) and hasattr(self, 'home'):
|
||||||
self.home()
|
self.home()
|
||||||
return self._openurl(*args, **kwargs)
|
return self._openurl(*args, **kwargs)
|
||||||
|
|
@ -289,7 +289,7 @@ class StandardBrowser(mechanize.Browser):
|
||||||
raise self.get_exception(e)('%s (url="%s")' % (e, args and args[0] or 'None'))
|
raise self.get_exception(e)('%s (url="%s")' % (e, args and args[0] or 'None'))
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
except BrowserRetry, e:
|
except BrowserRetry as e:
|
||||||
return self._openurl(*args, **kwargs)
|
return self._openurl(*args, **kwargs)
|
||||||
|
|
||||||
def get_exception(self, e):
|
def get_exception(self, e):
|
||||||
|
|
@ -426,7 +426,7 @@ class StandardBrowser(mechanize.Browser):
|
||||||
if isinstance(is_list, (list, tuple)):
|
if isinstance(is_list, (list, tuple)):
|
||||||
try:
|
try:
|
||||||
value = [self.str(is_list.index(args[label]))]
|
value = [self.str(is_list.index(args[label]))]
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
if args[label]:
|
if args[label]:
|
||||||
print >>sys.stderr, '[%s] %s: %s' % (label, args[label], e)
|
print >>sys.stderr, '[%s] %s: %s' % (label, args[label], e)
|
||||||
return
|
return
|
||||||
|
|
@ -555,10 +555,10 @@ class BaseBrowser(StandardBrowser):
|
||||||
nologin = kwargs.pop('nologin', False)
|
nologin = kwargs.pop('nologin', False)
|
||||||
try:
|
try:
|
||||||
self._change_location(mechanize.Browser.submit(self, *args, **kwargs), no_login=nologin)
|
self._change_location(mechanize.Browser.submit(self, *args, **kwargs), no_login=nologin)
|
||||||
except (mechanize.response_seek_wrapper, urllib2.HTTPError, urllib2.URLError, BadStatusLine, ssl.SSLError), e:
|
except (mechanize.response_seek_wrapper, urllib2.HTTPError, urllib2.URLError, BadStatusLine, ssl.SSLError) as e:
|
||||||
self.page = None
|
self.page = None
|
||||||
raise self.get_exception(e)(e)
|
raise self.get_exception(e)(e)
|
||||||
except (mechanize.BrowserStateError, BrowserRetry), e:
|
except (mechanize.BrowserStateError, BrowserRetry) as e:
|
||||||
raise BrowserUnavailable(e)
|
raise BrowserUnavailable(e)
|
||||||
|
|
||||||
def is_on_page(self, pageCls):
|
def is_on_page(self, pageCls):
|
||||||
|
|
@ -587,10 +587,10 @@ class BaseBrowser(StandardBrowser):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self._change_location(mechanize.Browser.follow_link(self, *args, **kwargs))
|
self._change_location(mechanize.Browser.follow_link(self, *args, **kwargs))
|
||||||
except (mechanize.response_seek_wrapper, urllib2.HTTPError, urllib2.URLError, BadStatusLine, ssl.SSLError), e:
|
except (mechanize.response_seek_wrapper, urllib2.HTTPError, urllib2.URLError, BadStatusLine, ssl.SSLError) as e:
|
||||||
self.page = None
|
self.page = None
|
||||||
raise self.get_exception(e)('%s (url="%s")' % (e, args and args[0] or 'None'))
|
raise self.get_exception(e)('%s (url="%s")' % (e, args and args[0] or 'None'))
|
||||||
except (mechanize.BrowserStateError, BrowserRetry), e:
|
except (mechanize.BrowserStateError, BrowserRetry) as e:
|
||||||
self.home()
|
self.home()
|
||||||
raise BrowserUnavailable(e)
|
raise BrowserUnavailable(e)
|
||||||
|
|
||||||
|
|
@ -622,7 +622,7 @@ class BaseBrowser(StandardBrowser):
|
||||||
if not self.page or not args or self.page.url != args[0]:
|
if not self.page or not args or self.page.url != args[0]:
|
||||||
keep_kwargs['no_login'] = True
|
keep_kwargs['no_login'] = True
|
||||||
self.location(*keep_args, **keep_kwargs)
|
self.location(*keep_args, **keep_kwargs)
|
||||||
except (mechanize.response_seek_wrapper, urllib2.HTTPError, urllib2.URLError, BadStatusLine, ssl.SSLError), e:
|
except (mechanize.response_seek_wrapper, urllib2.HTTPError, urllib2.URLError, BadStatusLine, ssl.SSLError) as e:
|
||||||
self.page = None
|
self.page = None
|
||||||
raise self.get_exception(e)('%s (url="%s")' % (e, args and args[0] or 'None'))
|
raise self.get_exception(e)('%s (url="%s")' % (e, args and args[0] or 'None'))
|
||||||
except mechanize.BrowserStateError:
|
except mechanize.BrowserStateError:
|
||||||
|
|
@ -758,7 +758,7 @@ class HTTPSConnection2(httplib.HTTPSConnection):
|
||||||
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=proto)
|
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=proto)
|
||||||
self._HOSTS['%s:%s' % (self.host, self.port)] = [proto]
|
self._HOSTS['%s:%s' % (self.host, self.port)] = [proto]
|
||||||
return
|
return
|
||||||
except ssl.SSLError, e:
|
except ssl.SSLError as e:
|
||||||
sock.close()
|
sock.close()
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sqlite3 as sqlite
|
import sqlite3 as sqlite
|
||||||
except ImportError, e:
|
except ImportError as e:
|
||||||
from pysqlite2 import dbapi2 as sqlite
|
from pysqlite2 import dbapi2 as sqlite
|
||||||
|
|
||||||
from mechanize import CookieJar, Cookie
|
from mechanize import CookieJar, Cookie
|
||||||
|
|
@ -39,7 +39,7 @@ class FirefoxCookieJar(CookieJar):
|
||||||
def __connect(self):
|
def __connect(self):
|
||||||
try:
|
try:
|
||||||
db = sqlite.connect(database=self.sqlite_file, timeout=10.0)
|
db = sqlite.connect(database=self.sqlite_file, timeout=10.0)
|
||||||
except sqlite.OperationalError, err:
|
except sqlite.OperationalError as err:
|
||||||
print 'Unable to open %s database: %s' % (self.sqlite_file, err)
|
print 'Unable to open %s database: %s' % (self.sqlite_file, err)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ class FrenchTransaction(Transaction):
|
||||||
self.rdate = datetime.datetime(yy, mm, dd, int(args['HH']), int(args['MM']))
|
self.rdate = datetime.datetime(yy, mm, dd, int(args['HH']), int(args['MM']))
|
||||||
else:
|
else:
|
||||||
self.rdate = datetime.date(yy, mm, dd)
|
self.rdate = datetime.date(yy, mm, dd)
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
self._logger.warning('Unable to date in label %r: %s' % (self.raw, e))
|
self._logger.warning('Unable to date in label %r: %s' % (self.raw, e))
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ def _findall(text, substr):
|
||||||
# Also finds overlaps
|
# Also finds overlaps
|
||||||
sites = []
|
sites = []
|
||||||
i = 0
|
i = 0
|
||||||
while 1:
|
while True:
|
||||||
j = text.find(substr, i)
|
j = text.find(substr, i)
|
||||||
if j == -1:
|
if j == -1:
|
||||||
break
|
break
|
||||||
|
|
@ -153,10 +153,10 @@ class LinearDateGuesser(object):
|
||||||
In case initialization still fails with max_year, this function raises
|
In case initialization still fails with max_year, this function raises
|
||||||
a ValueError.
|
a ValueError.
|
||||||
"""
|
"""
|
||||||
while 1:
|
while True:
|
||||||
try:
|
try:
|
||||||
return date(start_year, month, day)
|
return date(start_year, month, day)
|
||||||
except ValueError, e:
|
except ValueError as e:
|
||||||
if start_year == max_year:
|
if start_year == max_year:
|
||||||
raise e
|
raise e
|
||||||
start_year += cmp(max_year, start_year)
|
start_year += cmp(max_year, start_year)
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ def retry(ExceptionToCheck, tries=4, delay=3, backoff=2):
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
try_one_last_time = False
|
try_one_last_time = False
|
||||||
break
|
break
|
||||||
except ExceptionToCheck, e:
|
except ExceptionToCheck as e:
|
||||||
logging.debug(u'%s, Retrying in %d seconds...' % (e, mdelay))
|
logging.debug(u'%s, Retrying in %d seconds...' % (e, mdelay))
|
||||||
time.sleep(mdelay)
|
time.sleep(mdelay)
|
||||||
mtries -= 1
|
mtries -= 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue