From f2157c4cfb098eae6af361c8c8dee36455487d53 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Tue, 3 Apr 2012 22:40:49 +0200 Subject: [PATCH] fix some conversion warnings --- modules/arte/pages.py | 8 ++++---- modules/aum/backend.py | 10 +++++----- modules/canalplus/pages.py | 2 +- modules/prixcarburants/pages.py | 18 +++++++++++------- modules/transilien/pages/roadmap.py | 2 +- modules/youtube/backend.py | 2 +- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/modules/arte/pages.py b/modules/arte/pages.py index 43b88e08..03a44515 100644 --- a/modules/arte/pages.py +++ b/modules/arte/pages.py @@ -50,12 +50,12 @@ class IndexPage(BasePage): rating_max += 1 video = ArteVideo(_id) - video.title = title + video.title = unicode(title) video.rating = rating video.rating_max = rating_max thumb = self.parser.select(div, 'img[class=thumbnail]', 1) - video.thumbnail = Thumbnail('http://videos.arte.tv' + thumb.attrib['src']) + video.thumbnail = Thumbnail(u'http://videos.arte.tv' + thumb.attrib['src']) try: parts = self.parser.select(div, 'div.duration_thumbnail', 1).text.split(':') @@ -79,8 +79,8 @@ class VideoPage(BasePage): def get_video(self, video=None, lang='fr', quality='hd'): if not video: video = ArteVideo(self.group_dict['id']) - video.title = self.get_title() - video.url = self.get_url(lang, quality) + video.title = unicode(self.get_title()) + video.url = unicode(self.get_url(lang, quality)) video.set_empty_fields(NotAvailable) return video diff --git a/modules/aum/backend.py b/modules/aum/backend.py index a1309199..42752b5e 100644 --- a/modules/aum/backend.py +++ b/modules/aum/backend.py @@ -37,7 +37,7 @@ from weboob.tools.backend import BaseBackend, BackendConfig from weboob.tools.browser import BrowserUnavailable from weboob.tools.value import Value, ValuesDict, ValueBool, ValueBackendPassword from weboob.tools.log import getLogger -from weboob.tools.misc import local2utc +from weboob.tools.misc import local2utc, to_unicode from .contact import Contact from .captcha import CaptchaError @@ -144,7 +144,7 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh continue t = Thread(int(thread['member']['id'])) t.flags = Thread.IS_DISCUSSION - t.title = 'Discussion with %s' % thread['member']['pseudo'] + t.title = u'Discussion with %s' % to_unicode(thread['member']['pseudo']) yield t def get_thread(self, id, contacts=None, get_profiles=False): @@ -215,10 +215,10 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh msg = Message(thread=thread, id=int(time.strftime('%Y%m%d%H%M%S', parse_dt(mail['date']).timetuple())), title=thread.title, - sender=my_name if int(mail['id_from']) == self.browser.my_id else mails['member']['pseudo'], - receivers=[my_name if int(mail['id_from']) != self.browser.my_id else mails['member']['pseudo']], + sender=to_unicode(my_name if int(mail['id_from']) == self.browser.my_id else mails['member']['pseudo']), + receivers=[to_unicode(my_name if int(mail['id_from']) != self.browser.my_id else mails['member']['pseudo'])], date=parse_dt(mail['date']), - content=unescape(mail['message'] or '').strip(), + content=to_unicode(unescape(mail['message'] or '').strip()), signature=signature, children=[], flags=flags) diff --git a/modules/canalplus/pages.py b/modules/canalplus/pages.py index c66c555d..6f0a7141 100644 --- a/modules/canalplus/pages.py +++ b/modules/canalplus/pages.py @@ -92,7 +92,7 @@ class VideoPage(BasePage): break lastest_format = format if not video.url and lastest_format is not None: - video.url = lastest_format.text + video.url = unicode(lastest_format.text) day, month, year = map(int, infos.find('PUBLICATION').find('DATE').text.split('/')) hour, minute, second = map(int, infos.find('PUBLICATION').find('HEURE').text.split(':')) diff --git a/modules/prixcarburants/pages.py b/modules/prixcarburants/pages.py index d1336402..f8037f2c 100644 --- a/modules/prixcarburants/pages.py +++ b/modules/prixcarburants/pages.py @@ -21,7 +21,7 @@ from decimal import Decimal import re -from weboob.tools.browser import BasePage +from weboob.tools.browser import BasePage, BrokenPageError from weboob.capabilities import NotAvailable from weboob.capabilities.pricecomparison import Product, Shop, Price @@ -36,7 +36,7 @@ class IndexPage(BasePage): label = li.find('label') product = Product(input.attrib['value']) - product.name = label.text.strip() + product.name = unicode(label.text.strip()) if '&' in product.name: # "E10 & SP95" produces a non-supported table. @@ -46,9 +46,13 @@ class IndexPage(BasePage): class ComparisonResultsPage(BasePage): def get_product_name(self): - div = self.parser.select(self.document.getroot(), 'div#moins_plus_ariane', 1) - m = re.match('Carburant : (\w+) | .*', div.text) - return m.group(1) + try: + div = self.parser.select(self.document.getroot(), 'div#moins_plus_ariane', 1) + except BrokenPageError: + return NotAvailable + else: + m = re.match('Carburant : (\w+) | .*', div.text) + return m.group(1) def iter_results(self, product=None): price = None @@ -64,8 +68,8 @@ class ComparisonResultsPage(BasePage): price.currency = u'€' shop = Shop(price.id) - shop.name = tds[2].text.strip() - shop.location = tds[0].text.strip() + shop.name = unicode(tds[2].text.strip()) + shop.location = unicode(tds[0].text.strip()) price.shop = shop price.set_empty_fields(NotAvailable) diff --git a/modules/transilien/pages/roadmap.py b/modules/transilien/pages/roadmap.py index 85452197..32232f8d 100644 --- a/modules/transilien/pages/roadmap.py +++ b/modules/transilien/pages/roadmap.py @@ -93,7 +93,7 @@ class RoadmapPage(BasePage): current_step['id'] = i i += 1 current_step['start_time'] = self.parse_time(self.parser.select(tr, 'td.formattedHeureDepart p', 1).text.strip()) - current_step['line'] = self.parser.select(tr, 'td.rechercheResultatColumnMode img')[-1].attrib['alt'] + current_step['line'] = to_unicode(self.parser.select(tr, 'td.rechercheResultatColumnMode img')[-1].attrib['alt']) current_step['departure'] = to_unicode(self.parser.select(tr, 'td.descDepart p strong', 1).text.strip()) current_step['duration'] = self.parse_duration(self.parser.select(tr, 'td.rechercheResultatVertAlign', 1).text.strip()) elif tr.attrib['class'] == 'trBasTroncon': diff --git a/modules/youtube/backend.py b/modules/youtube/backend.py index 18961c45..8f26142a 100644 --- a/modules/youtube/backend.py +++ b/modules/youtube/backend.py @@ -70,7 +70,7 @@ class YoutubeBackend(BaseBackend, ICapVideo, ICapCollection): video.thumbnail = Thumbnail(to_unicode(entry.media.thumbnail[0].url.strip())) if entry.author[0].name.text: - video.author = entry.author[0].name.text.strip() + video.author = to_unicode(entry.author[0].name.text.strip()) if entry.media.name: video.author = to_unicode(entry.media.name.text.strip()) return video