本文整理汇总了Python中weboob.tools.misc.to_unicode函数的典型用法代码示例。如果您正苦于以下问题:Python to_unicode函数的具体用法?Python to_unicode怎么用?Python to_unicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_unicode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_stream_info
def get_stream_info(self, radio, url):
stream = BaseAudioStream(0)
current = StreamInfo(0)
r = self.browser.open(url, stream=True, headers={'Icy-Metadata':'1'})
stream.bitrate = int(r.headers['icy-br'].split(',')[0])
r.raw.read(int(r.headers['icy-metaint']))
size = ord(r.raw.read(1))
content = r.raw.read(size*16)
r.close()
for s in content.split("\x00")[0].split(";"):
a = s.split("=")
if a[0] == "StreamTitle":
stream.title = to_unicode(a[1].split("'")[1])
res = stream.title.split(" - ")
current.who = to_unicode(res[0])
if(len(res) == 1):
current.what = ""
else:
current.what = to_unicode(res[1])
stream.format=u'mp3'
stream.url = url
return [stream], current
示例2: get_steps
def get_steps(self):
errors = []
for p in self.parser.select(self.document.getroot(), 'p.errors'):
if p.text:
errors.append(p.text.strip())
if len(errors) > 0:
raise RoadmapError('Unable to establish a roadmap: %s' % ', '.join(errors))
current_step = None
i = 0
for tr in self.parser.select(self.document.getroot(), 'table.horaires2 tbody tr'):
if not 'class' in tr.attrib:
continue
elif tr.attrib['class'] == 'trHautTroncon':
current_step = {}
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'] = 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':
current_step['end_time'] = self.parse_time(self.parser.select(tr, 'td.formattedHeureArrivee p', 1).text.strip())
current_step['arrival'] = to_unicode(self.parser.select(tr, 'td.descArrivee p strong', 1).text.strip())
yield current_step
示例3: get_video
def get_video(self, _id):
video = QuviVideo(_id)
parser = LibQuvi()
if not parser.load():
raise UserError('Make sure libquvi 0.4 is installed')
try:
info = parser.get_info(video.page_url)
except QuviError as qerror:
raise UserError(qerror.message)
video.url = to_unicode(info.get('url'))
if not video.url:
raise NotImplementedError()
video.ext = to_unicode(info.get('suffix'))
video.title = to_unicode(info.get('title'))
video.page = to_unicode(info.get('page'))
duration = int(info.get('duration', 0))
if duration:
video.duration = datetime.timedelta(milliseconds=duration)
if info.get('thumbnail'):
video.thumbnail = Thumbnail(info.get('thumbnail'))
video.thumbnail.url = video.thumbnail.id
return video
示例4: get_video
def get_video(self, video=None):
_id = to_unicode(self.group_dict['id'])
if video is None:
video = YoujizzVideo(_id)
title_el = self.parser.select(self.document.getroot(), 'title', 1)
video.title = to_unicode(title_el.text.strip())
# youjizz HTML is crap, we must parse it with regexps
data = lxml.html.tostring(self.document.getroot())
m = re.search(r'<strong>.*?Runtime.*?</strong> (.+?)</div>', data)
if m:
txt = m.group(1).strip()
if txt == 'Unknown':
video.duration = NotAvailable
else:
minutes, seconds = (int(v) for v in to_unicode(txt).split(':'))
video.duration = datetime.timedelta(minutes=minutes, seconds=seconds)
else:
raise BrokenPageError('Unable to retrieve video duration')
real_id = int(_id.split('-')[-1])
data = self.browser.readurl('http://www.youjizz.com/videos/embed/%s' % real_id)
video_file_urls = re.findall(r'"(http://[^",]+\.youjizz\.com[^",]+\.flv(?:\?[^"]*)?)"', data)
if len(video_file_urls) == 0:
raise BrokenPageError('Video URL not found')
elif len(video_file_urls) > 1:
raise BrokenPageError('Many video file URL found')
else:
video.url = to_unicode(video_file_urls[0])
return video
示例5: _postReply_eb
def _postReply_eb(self, backend, error, backtrace):
content = unicode(self.tr('Unable to send message:\n%s\n')) % to_unicode(error)
if logging.root.level == logging.DEBUG:
content += '\n%s\n' % to_unicode(backtrace)
QMessageBox.critical(self, self.tr('Error while posting reply'),
content, QMessageBox.Ok)
self.process_reply = None
示例6: iter_routes
def iter_routes(self):
try:
table = self.parser.select(self.document.getroot(), 'table.horaires3', 1)
except BrokenPageError:
raise StationNotFound('Station not found')
departure = self.parser.select(table, 'td.caption strong', 1).text
for tr in table.findall('tr'):
if len(tr.findall('td')) != 4:
continue
code_mission = self.parser.select(tr, 'td[headers=Code_de_mission] a', 1).text.strip()
time_s = self.parser.select(tr, 'td[headers=Heure_de_passage]', 1).text.strip().rstrip(u'\xa0*')
destination = self.parser.select(tr, 'td[headers=Destination]', 1).text.strip()
plateform = self.parser.select(tr, 'td[headers=Voie]', 1).text.strip()
late_reason = None
time = None
try :
time = datetime.datetime.combine(datetime.date.today(), datetime.time(*[int(x) for x in time_s.split(':')]))
except ValueError:
late_reason = time_s
self.logger.warning('Unable to parse datetime "%s"' % time_s)
yield {'type': to_unicode(code_mission),
'time': time,
'departure': to_unicode(departure),
'arrival': to_unicode(destination),
'late': datetime.time(),
'late_reason': late_reason,
'plateform': to_unicode(plateform)}
示例7: get_video
def get_video(self, video=None):
_id = to_unicode(self.group_dict["id"])
if video is None:
video = YoujizzVideo(_id)
title_el = select(self.document.getroot(), "title", 1)
video.title = to_unicode(title_el.text.strip())
# youjizz HTML is crap, we must parse it with regexps
data = lxml.html.tostring(self.document.getroot())
m = re.search(r"<strong>.*?Runtime.*?</strong> (.+?)<br.*>", data)
try:
if m:
minutes, seconds = (int(v) for v in to_unicode(m.group(1).strip()).split(":"))
video.duration = datetime.timedelta(minutes=minutes, seconds=seconds)
else:
raise Exception()
except Exception:
raise SelectElementException("Could not retrieve video duration")
video_file_urls = re.findall(r'"(http://media[^ ,]+\.flv)"', data)
if len(video_file_urls) == 0:
raise SelectElementException("Video URL not found")
elif len(video_file_urls) > 1:
raise SelectElementException("Many video file URL found")
else:
video.url = video_file_urls[0]
return video
示例8: add_cookie
def add_cookie(self, name, value):
# httplib/cookielib don't seem to like unicode cookies...
if sys.version_info.major < 3:
name = to_unicode(name).encode('utf-8')
value = to_unicode(value).encode('utf-8')
self.browser.logger.debug('adding cookie %r=%r', name, value)
self.browser.session.cookies.set(name, value, domain=urlsplit(self.url).hostname)
示例9: get_list
def get_list(self):
table = self.find_table()
for tr in self.parser.select(table, 'tr', 'many'):
tds = self.parser.select(tr, 'td')
if len(tds) != 6:
continue
tdlabel, tdid, tdcur, tdupdated, tdbal, tdbalcur = tds
account = Account()
account.label = to_unicode(tdlabel.text_content().strip())
# this is important - and is also the last part of the id (considering spaces)
# we can't use only the link as it does not goes where we want
try:
link = self.parser.select(tdlabel, 'a', 1)
except BrokenPageError:
# probably an account we can't display the history
account._link_id = None
else:
account._link_id = parse_qs(link.attrib['href'])['ch4'][0]
account.id = to_unicode(tdid.text.strip().replace(' ', ''))
account.iban = 'FR76' + account.id
# just in case we are showing the converted balances
account._main_currency = Account.get_currency(tdcur.text)
# we have to ignore those accounts, because using NotAvailable
# makes boobank and probably many others crash
if tdbal.text_content().strip() == 'indisponible':
continue
account.balance = Decimal(Transaction.clean_amount(tdbal.text_content()))
account.currency = Account.get_currency(tdbalcur.text)
account._updated = datetime.strptime(tdupdated.text, '%d/%m/%Y')
yield account
示例10: bcall_error_handler
def bcall_error_handler(self, backend, error, backtrace):
"""
Handler for an exception inside the CallErrors exception.
This method can be overrided to support more exceptions types.
"""
if isinstance(error, BrowserQuestion):
for field in error.fields:
v = self.ask(field)
if v:
backend.config[field.id].set(v)
elif isinstance(error, BrowserIncorrectPassword):
msg = unicode(error)
if not msg:
msg = 'invalid login/password.'
print('Error(%s): %s' % (backend.name, msg), file=self.stderr)
if self.ask('Do you want to reconfigure this backend?', default=True):
self.unload_backends(names=[backend.name])
self.edit_backend(backend.name)
self.load_backends(names=[backend.name])
elif isinstance(error, BrowserSSLError):
print(u'FATAL(%s): ' % backend.name + self.BOLD + '/!\ SERVER CERTIFICATE IS INVALID /!\\' + self.NC, file=self.stderr)
elif isinstance(error, BrowserForbidden):
msg = unicode(error)
if not msg:
msg = 'access denied'
print(u'Error(%s): %s' % (backend.name, msg or 'Forbidden'), file=self.stderr)
elif isinstance(error, BrowserUnavailable):
msg = unicode(error)
if not msg:
msg = 'website is unavailable.'
print(u'Error(%s): %s' % (backend.name, msg), file=self.stderr)
elif isinstance(error, NotImplementedError):
print(u'Error(%s): this feature is not supported yet by this backend.' % backend.name, file=self.stderr)
print(u' %s To help the maintainer of this backend implement this feature,' % (' ' * len(backend.name)), file=self.stderr)
print(u' %s please contact: %s <%[email protected]>' % (' ' * len(backend.name), backend.MAINTAINER, backend.NAME), file=self.stderr)
elif isinstance(error, UserError):
print(u'Error(%s): %s' % (backend.name, to_unicode(error)), file=self.stderr)
elif isinstance(error, MoreResultsAvailable):
print(u'Hint: There are more results for backend %s' % (backend.name), file=self.stderr)
else:
print(u'Bug(%s): %s' % (backend.name, to_unicode(error)), file=self.stderr)
minfo = self.weboob.repositories.get_module_info(backend.NAME)
if minfo and not minfo.is_local():
self.weboob.repositories.update_repositories(ConsoleProgress(self))
# minfo of the new available module
minfo = self.weboob.repositories.get_module_info(backend.NAME)
if minfo and minfo.version > self.weboob.repositories.versions.get(minfo.name) and \
self.ask('A new version of %s is available. Do you want to install it?' % minfo.name, default=True) and \
self.install_module(minfo):
print('New version of module %s has been installed. Retry to call the command.' % minfo.name)
return
if logging.root.level <= logging.DEBUG:
print(backtrace, file=self.stderr)
else:
return True
示例11: load
def load(self, items):
self.version = int(items["version"])
self.capabilities = items["capabilities"].split()
self.description = to_unicode(items["description"])
self.maintainer = to_unicode(items["maintainer"])
self.license = to_unicode(items["license"])
self.icon = items["icon"].strip() or None
self.urls = items["urls"]
示例12: _saveNotes_eb
def _saveNotes_eb(self, backend, error, backtrace):
self.ui.saveButton.setEnabled(True)
self.ui.textEdit.setEnabled(True)
content = unicode(self.tr('Unable to save notes:\n%s\n')) % to_unicode(error)
if logging.root.level == logging.DEBUG:
content += '\n%s\n' % to_unicode(backtrace)
QMessageBox.critical(self, self.tr('Error while saving notes'),
content, QMessageBox.Ok)
示例13: _errorLoadPage
def _errorLoadPage(self, backend, error, backtrace):
""" Error callback for loadPage """
content = unicode(self.tr('Unable to load page:\n%s\n')) % to_unicode(error)
if logging.root.level == logging.DEBUG:
content += '\n%s\n' % to_unicode(backtrace)
QMessageBox.critical(self, self.tr('Error while loading page'),
content, QMessageBox.Ok)
self.ui.loadButton.setEnabled(True)
self.ui.loadButton.setText("Load")
示例14: _errorSavePage
def _errorSavePage(self, backend, error, backtrace):
""" """
content = unicode(self.tr('Unable to save page:\n%s\n')) % to_unicode(error)
if logging.root.level == logging.DEBUG:
content += '\n%s\n' % to_unicode(backtrace)
QMessageBox.critical(self, self.tr('Error while saving page'),
content, QMessageBox.Ok)
self.ui.saveButton.setEnabled(True)
self.ui.saveButton.setText("Save")
示例15: write_dict
def write_dict(self, item, fp):
writer = csv.writer(fp, delimiter=self.field_separator)
if not self.started:
writer.writerow([to_unicode(v) for v in item.keys()])
self.started = True
if sys.version_info.major >= 3:
writer.writerow([str(v) for v in item.values()])
else:
writer.writerow([to_unicode(v).encode('utf-8') for v in item.values()])