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

Python utils.unicode_to_filename函数代码示例

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

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



在下文中一共展示了unicode_to_filename函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: filename_from_url

def filename_from_url(url, clean=False):
    """Returns a reasonable filename for saving the given url.
    """
    check_u(url)
    try:
        match = URI_PATTERN.match(url)
        if match is None:
            # This code path will never be executed.
            return unicode_to_filename(url)
        filename = match.group(2)
        query = match.group(4)
        if not filename:
            ret = query
        elif not query:
            ret = filename
        else:
            root, ext = os.path.splitext(filename)
            ret = u"%s-%s%s" % (root, query, ext)
        ret = unquote(ret)
        if ret is None:
            ret = u'unknown'
        if clean:
            return clean_filename(ret)
        else:
            return unicode_to_filename(ret)
    except (SystemExit, KeyboardInterrupt):
        raise
    except:
        return unicode_to_filename(u'unknown')
开发者ID:cool-RR,项目名称:Miro,代码行数:29,代码来源:download_utils.py


示例2: __init__

 def __init__(self, name, **kwargs):
     self.name = name
     self.__dict__.update(kwargs)
     if 'audio_path' in kwargs:
         self.audio_path = unicode_to_filename(self.audio_path)
     if 'video_path' in kwargs:
         self.video_path = unicode_to_filename(self.video_path)
开发者ID:cool-RR,项目名称:Miro,代码行数:7,代码来源:devices.py


示例3: get_downloader_for_item

def get_downloader_for_item(item):
    existing = get_existing_downloader(item)
    if existing:
        return existing
    url = item.get_url()
    existing = get_existing_downloader_by_url(url)
    if existing:
        return existing
    channel_name = unicode_to_filename(item.get_channel_title(True))
    if not channel_name:
        channel_name = None
    if url.startswith(u'file://'):
        path = get_file_url_path(url)
        try:
            get_torrent_info_hash(path)
        except ValueError:
            raise ValueError("Don't know how to handle %s" % url)
        except (OSError, IOError):
            return None
        else:
            return RemoteDownloader(url, item, u'application/x-bittorrent',
                                    channel_name=channel_name)
    elif is_magnet_uri(url):
        return RemoteDownloader(url, item, u'application/x-magnet')
    else:
        return RemoteDownloader(url, item, channel_name=channel_name)
开发者ID:dankamongmen,项目名称:miro,代码行数:26,代码来源:downloader.py


示例4: build_output_paths

def build_output_paths(item_info, target_folder, converter_info):
    """Returns final_output_path and temp_output_path.

    We base the temp path on temp filenames.
    We base the final path on the item title.
    """
    if target_folder is None:
        use_temp_dir = True
        target_folder = get_conversions_folder()
    else:
        use_temp_dir = False
    input_path = item_info.video_path
    basename = os.path.basename(input_path)

    title = utils.unicode_to_filename(item_info.name, target_folder).strip()
    if not title:
        title = basename

    if converter_info:
        target_name = "%s.%s.%s" % (title, converter_info.identifier,
                                    converter_info.extension)
    else:
        target_name = basename
    final_path = FilenameType(os.path.join(target_folder, target_name))

    if not use_temp_dir:
        # convert directly onto the device
        temp_path = final_path + '.tmp'
    else:
        temp_dir = FilenameType(tempfile.mkdtemp("miro-conversion"))
        temp_path = os.path.join(temp_dir, basename)

    return (final_path, temp_path)
开发者ID:kmshi,项目名称:miro,代码行数:33,代码来源:conversions.py


示例5: get_filename

 def get_filename(self):
     self.dbItem.confirm_db_thread()
     if self.url and self.url.startswith(u"file://"):
         return get_file_url_path(self.url)
     elif self.url and self.url.startswith(u"/"):
         return unicode_to_filename(self.url)
     else:
         return self.filename
开发者ID:CodeforEvolution,项目名称:miro,代码行数:8,代码来源:iconcache.py


示例6: clean_filename

def clean_filename(filename):
    """Given either a filename or a unicode "filename" return a valid
    clean version of it.
    """
    for char in (':', '?', '<', '>', '|', '*', '\\', '/', '"', '\'', '%'):
        filename = filename.replace(char, '')
    if len(filename) == 0:
        return unicode_to_filename(u'_')
    if len(filename) > MAX_FILENAME_LENGTH:
        base, ext = os.path.splitext(filename)
        ext = ext[:MAX_FILENAME_EXTENSION_LENGTH]
        base = base[:MAX_FILENAME_LENGTH-len(ext)]
        filename = base + ext
    if type(filename) == str:
        return unicode_to_filename(filename.decode('ascii', 'replace'))
    else:
        return unicode_to_filename(filename)
开发者ID:cool-RR,项目名称:Miro,代码行数:17,代码来源:download_utils.py


示例7: add_fake_media_files_to_device

 def add_fake_media_files_to_device(self):
     self.device_item_filenames = [
         unicode_to_filename(f.decode('utf-8')) for f in
         ['foo.mp3', 'bar.mp3', 'foo.avi', 'bar.ogg']
     ]
     for filename in self.device_item_filenames:
         path = os.path.join(self.device.mount, filename)
         with open(path, 'w') as f:
             f.write("fake-data")
开发者ID:devcult,项目名称:miro,代码行数:9,代码来源:devicestest.py


示例8: _add_item

    def _add_item(self, final_path, item_info):
        dirname, basename = os.path.split(final_path)
        _, extension = os.path.splitext(basename)
        new_basename = "%s%s" % (unicode_to_filename(item_info.name,
                                                     self.device.mount),
                                 extension)
        new_path = os.path.join(dirname, new_basename)
        if os.path.exists(new_path):
            logging.debug('final destination %r exists, making a new one',
                          new_path)
            new_path, fp = next_free_filename(new_path)

        def callback():
            if not os.path.exists(new_path):
                return # copy failed, just give up

            device_item = item.DeviceItem(
                device=self.device,
                file_type=item_info.file_type,
                video_path=new_path[len(self.device.mount):],
                title=item_info.name,
                feed_name=item_info.feed_name,
                feed_url=item_info.feed_url,
                description=item_info.description,
                release_date=time.mktime(item_info.release_date.timetuple()),
                duration=(item_info.duration and item_info.duration * 1000 or
                          None),
                permalink=item_info.permalink,
                commentslink=item_info.commentslink,
                payment_link=item_info.payment_link,
                screenshot=item_info.thumbnail,
                thumbnail_url=item_info.thumbnail_url,
                file_format=item_info.file_format,
                license=item_info.license,
                url=item_info.file_url,
                media_type_checked=item_info.media_type_checked,
                mime_type=item_info.mime_type,
                creation_time=time.mktime(item_info.date_added.timetuple()),
                title_tag=item_info.title_tag,
                artist=item_info.artist,
                album=item_info.album,
                track=item_info.track,
                year=item_info.year,
                genre=item_info.genre,
                metadata_version=item_info.metadata_version,
                mdp_state=item_info.mdp_state,
                auto_sync=getattr(item_info, 'auto_sync', False)
                )
            device_item._migrate_thumbnail()
            database = self.device.database
            database.setdefault(device_item.file_type, {})
            database[device_item.file_type][device_item.id] = \
                device_item.to_dict()
            database.emit('item-added', device_item)
            self.device.remaining -= device_item.size

        fileutil.migrate_file(final_path, new_path, callback)
开发者ID:codito,项目名称:miro,代码行数:57,代码来源:devices.py


示例9: test_file_urlize_with_unicode

 def test_file_urlize_with_unicode(self):
     # contrived way of getting unicode characters in a filename
     basename = unicode_to_filename(u'b\u0103r')
     directory = fileobject.FilenameType('/foo/')
     filename = fileobject.FilenameType(directory + basename)
     # "/foo/bar" with a breve over the "a"
     self.assertEquals(filename.urlize(), "file:///foo/b%C4%83r")
     # urlize() should convert it to utf-8 then quote it
     self.assertEquals(type(filename.urlize()), str)
开发者ID:CodeforEvolution,项目名称:miro,代码行数:9,代码来源:fileobjecttest.py


示例10: icon_path_for_engine

def icon_path_for_engine(engine):
    engine_name = unicode_to_filename(engine.name)
    icon_path = resources.path('images/search_icon_%s.png' % engine_name)
    if app.config.get(prefs.THEME_NAME):
        logging.debug('engine %s filename: %s' % (engine.name, engine.filename))
        test_icon_path = resources.theme_path(app.config.get(prefs.THEME_NAME),
                                              'images/search_icon_%s.png' %
                                              engine_name)
        if os.path.exists(test_icon_path):
            # this search engine came from a theme; look up the icon in the
            # theme directory instead
            icon_path = test_icon_path
    return icon_path
开发者ID:ShriramK,项目名称:miro,代码行数:13,代码来源:searchengines.py


示例11: _add_item

 def _add_item(self, final_path, item_info):
     dirname, basename = os.path.split(final_path)
     _, extension = os.path.splitext(basename)
     new_basename = "%s%s" % (unicode_to_filename(item_info.name),
                              extension)
     new_path = os.path.join(dirname, new_basename)
     os.rename(final_path, new_path)
     device_item = item.DeviceItem(
         device=self.device,
         file_type=item_info.file_type,
         video_path=new_path[len(self.device.mount):],
         name=item_info.name,
         feed_name=item_info.feed_name,
         feed_url=item_info.feed_url,
         description=item_info.description,
         release_date=time.mktime(item_info.release_date.timetuple()),
         duration=item_info.duration * 1000,
         permalink=item_info.permalink,
         commentslink=item_info.commentslink,
         payment_link=item_info.payment_link,
         screenshot=item_info.thumbnail,
         thumbnail_url=item_info.thumbnail_url,
         file_format=item_info.file_format,
         license=item_info.license,
         url=item_info.file_url,
         media_type_checked=item_info.media_type_checked,
         mime_type=item_info.mime_type)
     device_item._migrate_thumbnail()
     database = self.device.database
     database.setdefault(device_item.file_type, [])
     database[device_item.file_type][device_item.video_path] = \
         device_item.to_dict()
     messages.ItemsChanged('device', '%s-%s' % (self.device.id,
                                                device_item.file_type),
                           [messages.ItemInfo(device_item)], # added
                           [], []).send_to_frontend() # changed, removed
开发者ID:cool-RR,项目名称:Miro,代码行数:36,代码来源:devices.py


示例12: update_icon_cache

    def update_icon_cache(self, url, info):
        self.dbItem.confirm_db_thread()

        if self.removed:
            app.icon_cache_updater.update_finished()
            return

        needs_save = False
        needsChange = False

        if info == None or (info['status'] != 304 and info['status'] != 200):
            self.error_callback(url, "bad response")
            return
        try:
            # Our cache is good.  Hooray!
            if info['status'] == 304:
                return

            needsChange = True

            # We have to update it, and if we can't write to the file, we
            # should pick a new filename.
            if ((self.filename and
                 not fileutil.access(self.filename, os.R_OK | os.W_OK))):
                self.filename = None

            cachedir = app.config.get(prefs.ICON_CACHE_DIRECTORY)
            try:
                fileutil.makedirs(cachedir)
            except OSError:
                pass

            try:
                # Write to a temp file.
                if self.filename:
                    tmp_filename = self.filename + ".part"
                else:
                    tmp_filename = os.path.join(cachedir, info["filename"]) + ".part"
                tmp_filename, output = next_free_filename(tmp_filename)
                output.write(info["body"])
                output.close()
            except IOError:
                self.remove_file(tmp_filename)
                return
            except ValueError:
                logging.warn('update_icon_cache: next_free_filename failed '
                             '#1, candidate = %r', tmp_filename)
                return

            filename = unicode(info["filename"])
            filename = unicode_to_filename(filename, cachedir)
            filename = os.path.join(cachedir, filename)
            needs_save = True
            try:
                filename, fp = next_free_filename(filename)
            except ValueError:
                logging.warn('update_icon_cache: next_free_filename failed '
                             '#2, candidate = %r', filename)
                return

            if self.filename:
                filename = self.filename
                self.filename = None
                self.remove_file(filename)

            # we need to move the file here--so we close the file
            # pointer and then move the file.
            fp.close()
            try:
                self.remove_file(filename)
                fileutil.rename(tmp_filename, filename)
            except (IOError, OSError):
                logging.exception("iconcache: fileutil.move failed")
                filename = None

            self.filename = filename

            etag = unicodify(info.get("etag"))
            modified = unicodify(info.get("modified"))

            if self.etag != etag:
                needs_save = True
                self.etag = etag
            if self.modified != modified:
                needs_save = True
                self.modified = modified
            if self.url != url:
                needs_save = True
                self.url = url
        finally:
            if needsChange:
                self.icon_changed(needs_save=needs_save)
            self.updating = False
            if self.needsUpdate:
                self.needsUpdate = False
                self.request_update(True)
            app.icon_cache_updater.update_finished()
开发者ID:CodeforEvolution,项目名称:miro,代码行数:97,代码来源:iconcache.py


示例13: remove_item

 def remove_item(self, filename):
     path = '/videos/' + unicode_to_filename(filename)
     self.added_items[path].remove()
     del self.added_items[path]
     self.deleted_paths.append(path)
开发者ID:ShriramK,项目名称:miro,代码行数:5,代码来源:itemtest.py


示例14: make_device_item

def make_device_item(device, filename):
    # ensure that filename is the correct type for our platform
    filename = unicode_to_filename(unicode(filename))
    ensure_file_exists(os.path.join(device.mount, filename))
    return item.DeviceItem(device, filename)
开发者ID:bluezone,项目名称:miro,代码行数:5,代码来源:testobjects.py


示例15: test_extendend_chars

 def test_extendend_chars(self):
     filename = unicode_to_filename(u'\ufffdxtended Chars')
     self.add_file_to_support_dir(filename, 'xtended Chars')
     self.check_backup()
开发者ID:foxi,项目名称:miro,代码行数:4,代码来源:utiltest.py


示例16: remove_item

 def remove_item(self, filename):
     path = os.path.join(self.tempdir, unicode_to_filename(filename))
     self.added_items[path].remove()
     del self.added_items[path]
     self.deleted_paths.append(path)
开发者ID:CodeforEvolution,项目名称:miro,代码行数:5,代码来源:itemtest.py


示例17: add_item

 def add_item(self, filename):
     path = os.path.join(self.tempdir, unicode_to_filename(filename))
     # create a bogus file so we don't get a warning when we create a
     # filename.
     open(path, 'wb').write("data")
     self.added_items[path] = FileItem(path, self.feed.id)
开发者ID:CodeforEvolution,项目名称:miro,代码行数:6,代码来源:itemtest.py


示例18: update_icon_cache

    def update_icon_cache(self, url, info):
        self.dbItem.confirm_db_thread()

        if self.removed:
            iconCacheUpdater.update_finished()
            return

        needs_save = False
        needsChange = False

        if info == None or (info['status'] != 304 and info['status'] != 200):
            self.error_callback(url, "bad response")
            return
        try:
            # Our cache is good.  Hooray!
            if info['status'] == 304:
                return

            needsChange = True

            # We have to update it, and if we can't write to the file, we
            # should pick a new filename.
            if self.filename and not fileutil.access(self.filename, os.R_OK | os.W_OK):
                self.filename = None

            cachedir = app.config.get(prefs.ICON_CACHE_DIRECTORY)
            try:
                fileutil.makedirs(cachedir)
            except OSError:
                pass

            try:
                # Write to a temp file.
                if self.filename:
                    tmp_filename = self.filename + ".part"
                else:
                    tmp_filename = os.path.join(cachedir, info["filename"]) + ".part"

                tmp_filename, output = next_free_filename(tmp_filename)
                output.write(info["body"])
                output.close()
            except IOError:
                self.remove_file(tmp_filename)
                return

            if self.filename:
                self.remove_file(self.filename)

            # Create a new filename always to avoid browser caching in case a
            # file changes.
            # Add a random unique id
            parts = unicodify(info["filename"]).split('.')
            uid = u"%08d" % random.randint(0, 99999999)
            if len(parts) == 1:
                parts.append(uid)
            else:
                parts[-1:-1] = [uid]
            self.filename = u'.'.join(parts)
            self.filename = unicode_to_filename(self.filename, cachedir)
            self.filename = os.path.join(cachedir, self.filename)
            self.filename, fp = next_free_filename(self.filename)
            needs_save = True

            try:
                fileutil.rename(tmp_filename, self.filename)
            except OSError:
                self.filename = None
                needs_save = True
            fp.close()

            etag = unicodify(info.get("etag"))
            modified = unicodify(info.get("modified"))

            if self.etag != etag:
                needs_save = True
                self.etag = etag
            if self.modified != modified:
                needs_save = True
                self.modified = modified
            if self.url != url:
                needs_save = True
                self.url = url
        finally:
            if needsChange:
                self.icon_changed(needs_save=needs_save)
            self.updating = False
            if self.needsUpdate:
                self.needsUpdate = False
                self.request_update(True)
            iconCacheUpdater.update_finished()
开发者ID:nxmirrors,项目名称:miro,代码行数:90,代码来源:iconcache.py


示例19: add_item

 def add_item(self, filename):
     path = '/videos/' + unicode_to_filename(filename)
     self.added_items[path] = FileItem(path, self.feed.id)
开发者ID:ShriramK,项目名称:miro,代码行数:3,代码来源:itemtest.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python playlist.SavedPlaylist类代码示例发布时间:2022-05-27
下一篇:
Python utils.filename_to_unicode函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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