• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python misc.to_unicode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中weboob.tools.misc.to_unicode函数的典型用法代码示例。如果您正苦于以下问题:Python to_unicode函数的具体用法?Python to_unicode怎么用?Python to_unicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了to_unicode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:P4ncake,项目名称:weboob,代码行数:27,代码来源:module.py


示例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
开发者ID:eirmag,项目名称:weboob,代码行数:26,代码来源:roadmap.py


示例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
开发者ID:dasimon,项目名称:weboob,代码行数:26,代码来源:module.py


示例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
开发者ID:blckshrk,项目名称:Weboob,代码行数:32,代码来源:video.py


示例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
开发者ID:Boussadia,项目名称:weboob,代码行数:7,代码来源:contacts.py


示例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)}
开发者ID:Boussadia,项目名称:weboob,代码行数:31,代码来源:departures.py


示例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
开发者ID:jocelynj,项目名称:weboob,代码行数:28,代码来源:video.py


示例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)
开发者ID:laurentb,项目名称:weboob,代码行数:7,代码来源:pages.py


示例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
开发者ID:nojhan,项目名称:weboob-devel,代码行数:31,代码来源:pages.py


示例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
开发者ID:nojhan,项目名称:weboob-devel,代码行数:59,代码来源:console.py


示例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"]
开发者ID:kyrre,项目名称:weboob,代码行数:8,代码来源:repositories.py


示例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)
开发者ID:Boussadia,项目名称:weboob,代码行数:8,代码来源:contacts.py


示例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")
开发者ID:eirmag,项目名称:weboob,代码行数:9,代码来源:main_window.py


示例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")
开发者ID:eirmag,项目名称:weboob,代码行数:9,代码来源:main_window.py


示例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()])
开发者ID:P4ncake,项目名称:weboob,代码行数:10,代码来源:csv.py


示例16: _errorHistory

 def _errorHistory(self, backend, error, backtrace):
     """ Loading the history has failed """
     content = unicode(self.tr('Unable to load history:\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 history'),
                          content, QMessageBox.Ok)
     
     self.ui.loadHistoryButton.setEnabled(True)
     self.ui.loadHistoryButton.setText("Reload")
开发者ID:eirmag,项目名称:weboob,代码行数:10,代码来源:main_window.py


示例17: get_profile

 def get_profile(self):
     from weboob.tools.misc import to_unicode
     profile = Profile()
     if len([k for k in self.session.cookies.keys() if k == 'CTX']) > 1:
         del self.session.cookies['CTX']
     elif 'username=' in self.session.cookies.get('CTX', ''):
         profile.name = to_unicode(re.search('username=([^&]+)', self.session.cookies['CTX']).group(1))
     elif 'nomusager=' in self.session.cookies.get('headerdei'):
         profile.name = to_unicode(re.search('nomusager=(?:[^&]+/ )?([^&]+)', self.session.cookies['headerdei']).group(1))
     return profile
开发者ID:laurentb,项目名称:weboob,代码行数:10,代码来源:browser.py


示例18: get_current

    def get_current(self, radio):
        document = self.browser.location('http://rock.ouifm.fr/dynamic-menu.json')
        suffix = ''
        if radio != 'general':
            suffix = '_%s' % radio

        last = document['last%s' % suffix][0]

        artist = to_unicode(last.get('artiste%s' % suffix, '').strip())
        title = to_unicode(last.get('titre%s' % suffix, '').strip())
        return artist, title
开发者ID:eirmag,项目名称:weboob,代码行数:11,代码来源:backend.py


示例19: _entry2video

 def _entry2video(self, entry):
     """
     Parse an entry returned by googleapi and return a Video object.
     """
     snippet = entry['snippet']
     video = YoutubeVideo(to_unicode(entry['id']['videoId']))
     video.title = to_unicode(snippet['title'].strip())
     # duration does not seem to be available with api
     video.thumbnail = Thumbnail(snippet['thumbnails']['default']['url'])
     video.author = to_unicode(snippet['channelTitle'].strip())
     return video
开发者ID:dasimon,项目名称:weboob,代码行数:11,代码来源:module.py


示例20: _getNotes_eb

    def _getNotes_eb(self, backend, error, backtrace):
        if isinstance(error, NotImplementedError):
            return

        self.ui.textEdit.setEnabled(True)
        self.ui.saveButton.setEnabled(True)
        content = unicode(self.tr('Unable to load 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 loading notes'),
            content, QMessageBox.Ok)
开发者ID:Boussadia,项目名称:weboob,代码行数:11,代码来源:contacts.py



注:本文中的weboob.tools.misc.to_unicode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ordereddict.OrderedDict类代码示例发布时间:2022-05-26
下一篇:
Python log.getLogger函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap