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

Python path.fsnative函数代码示例

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

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



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

示例1: test_conv

 def test_conv(self):
     empty = fsnative(u"")
     in_ = fsnative(u"foo \u00c1 \u1234")
     out = fsnative(u"foo _ _")
     v = self.c.filter(empty, in_)
     self.failUnlessEqual(v, out)
     self.failUnless(is_fsnative(v))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:7,代码来源:test_qltk_renamefiles.py


示例2: test_disctrack

 def test_disctrack(self):
     pat = TagsFromPattern('<discnumber><tracknumber>. <title>')
     self.assertEquals(pat.match_path(fsnative(u'101. T1.ogg')),
         dict(discnumber='1', tracknumber='01', title='T1'))
     self.assertEquals(pat.match_path(fsnative(u'1318. T18.ogg')),
         dict(discnumber='13', tracknumber='18', title='T18'))
     self.assertEquals(pat.match_path(fsnative(u'24. T4.ogg')),
         dict(discnumber='2', tracknumber='4', title='T4'))
开发者ID:bp0,项目名称:quodlibet,代码行数:8,代码来源:test_util_tagsfrompath.py


示例3: test_uri_to_path

 def test_uri_to_path(self):
     if os.name != "nt":
         path = uri_to_path("file:///home/piman/cr%21azy")
         self.assertTrue(is_fsnative(path))
         self.assertEqual(path, fsnative(u"/home/piman/cr!azy"))
     else:
         path = uri_to_path("file:///C:/foo")
         self.assertTrue(is_fsnative(path))
         self.assertEqual(path, fsnative(u"C:\\foo"))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:9,代码来源:test_util_path.py


示例4: test_uri_from_path

 def test_uri_from_path(self):
     if os.name != "nt":
         uri = uri_from_path(fsnative(u"/öäü.txt"))
         self.assertEqual(uri, u"file:///%C3%B6%C3%A4%C3%BC.txt")
     else:
         uri = uri_from_path(fsnative(u"C:\\öäü.txt"))
         self.assertEqual(
             uri, "file:///C:/%C3%B6%C3%A4%C3%BC.txt")
         self.assertEqual(
             uri_from_path(u"C:\\SomeDir\xe4"), "file:///C:/SomeDir%C3%A4")
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:10,代码来源:test_util_path.py


示例5: test_roundtrip

    def test_roundtrip(self):
        if os.name == "nt":
            paths = [u"C:\\öäü.txt"]
        else:
            paths = [u"/öäü.txt", u"//foo/bar", u"///foo/bar"]

        for source in paths:
            path = uri_to_path(uri_from_path(fsnative(source)))
            self.assertTrue(is_fsnative(path))
            self.assertEqual(path, fsnative(source))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:10,代码来源:test_util_path.py


示例6: test_ends_with_dots_or_spaces

    def test_ends_with_dots_or_spaces(self):
        empty = fsnative(u"")
        v = self.c.filter(empty, fsnative(u"foo. . "))
        self.failUnlessEqual(v, fsnative(u"foo. ._"))
        self.assertTrue(is_fsnative(v))

        if os.name == "nt":
            self.failUnlessEqual(self.c.filter(empty, u"foo. \\bar ."), u"foo._\\bar _")
        else:
            self.failUnlessEqual(self.c.filter(empty, u"foo. /bar ."), "foo._/bar _")
开发者ID:mistotebe,项目名称:quodlibet,代码行数:10,代码来源:test_qltk_renamefiles.py


示例7: init_test_environ

def init_test_environ():
    """This needs to be called before any test can be run.

    Before exiting the process call exit_test_environ() to clean up
    any resources created.
    """

    global _TEMP_DIR, _BUS_INFO

    # create a user dir in /tmp and set env vars
    _TEMP_DIR = tempfile.mkdtemp(prefix=fsnative(u"QL-TEST-"))

    # needed for dbus/dconf
    runtime_dir = tempfile.mkdtemp(prefix=fsnative(u"RUNTIME-"), dir=_TEMP_DIR)
    os.chmod(runtime_dir, 0o700)
    environ["XDG_RUNTIME_DIR"] = runtime_dir

    # force the old cache dir so that GStreamer can re-use the GstRegistry
    # cache file
    environ["XDG_CACHE_HOME"] = xdg_get_cache_home()
    # GStreamer will update the cache if the environment has changed
    # (in Gst.init()). Since it takes 0.5s here and doesn't add much,
    # disable it. If the registry cache is missing it will be created
    # despite this setting.
    environ["GST_REGISTRY_UPDATE"] = fsnative(u"no")

    # set HOME and remove all XDG vars that default to it if not set
    home_dir = tempfile.mkdtemp(prefix=fsnative(u"HOME-"), dir=_TEMP_DIR)
    environ["HOME"] = home_dir

    # set to new default
    environ.pop("XDG_DATA_HOME", None)

    _BUS_INFO = None
    if os.name != "nt" and "DBUS_SESSION_BUS_ADDRESS" in environ:
        try:
            out = subprocess.check_output(["dbus-launch"])
        except (subprocess.CalledProcessError, OSError):
            pass
        else:
            if PY3:
                out = out.decode("ascii")
            _BUS_INFO = dict([l.split("=", 1) for l in out.splitlines()])
            environ.update(_BUS_INFO)

    # Ideally nothing should touch the FS on import, but we do atm..
    # Get rid of all modules so QUODLIBET_USERDIR gets used everywhere.
    for key in list(sys.modules.keys()):
        if key.startswith('quodlibet'):
            del(sys.modules[key])

    import quodlibet
    quodlibet.init(no_translations=True, no_excepthook=True)
    quodlibet.app.name = "QL Tests"
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:54,代码来源:__init__.py


示例8: test_masked_handling

    def test_masked_handling(self):
        if os.name == "nt":
            # FIXME: masking isn't properly implemented on Windows
            return
        # playlists can contain songs and paths for masked handling..
        lib = FileLibrary("foobar")
        pl = Playlist(self.temp, "playlist", lib)
        song = Fakesong({"date": "2038", "~filename": fsnative(u"/fake")})
        song.sanitize()
        lib.add([song])

        # mask and update
        lib.mask("/")
        pl.append(song)
        pl.remove_songs([song])
        self.failUnless("/fake" in pl)

        pl.extend(self.TWO_SONGS)

        # check if collections can handle the mix
        self.failUnlessEqual(pl("date"), "2038")

        # unmask and update
        lib.unmask("/")
        pl.add_songs(["/fake"], lib)
        self.failUnless(song in pl)

        pl.delete()
        lib.destroy()
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:29,代码来源:test_util_collection.py


示例9: _post

    def _post(self, value, song, keep_extension=True):
        if value:
            assert isinstance(value, unicode)
            value = fsnative(value)

            if keep_extension:
                fn = song.get("~filename", ".")
                ext = fn[fn.rfind("."):].lower()
                val_ext = value[-len(ext):].lower()
                if not ext == val_ext:
                    value += ext.lower()

            if os.name == "nt":
                assert isinstance(value, unicode)
                value = strip_win32_incompat_from_path(value)

            value = expanduser(value)

            # Limit each path section to 255 (bytes on linux, chars on win).
            # http://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
            path, ext = os.path.splitext(value)
            path = path.split(sep)
            limit = [255] * len(path)
            limit[-1] -= len(ext)
            elip = lambda (p, l): (len(p) > l and p[:l - 2] + "..") or p
            path = sep.join(map(elip, zip(path, limit)))
            value = path + ext

            if sep in value and not os.path.isabs(value):
                raise ValueError("Pattern is not rooted")
        return value
开发者ID:kriskielce88,项目名称:xn--ls8h,代码行数:31,代码来源:_pattern.py


示例10: test_embedded_special_cover_words

    def test_embedded_special_cover_words(self):
        """Tests that words incidentally containing embedded "special" words
        album keywords (e.g. cover, disc, back) don't trigger
        See Issue 818"""

        song = AudioFile({
            "~filename": fsnative(u"tests/data/asong.ogg"),
            "album": "foobar",
            "title": "Ode to Baz",
            "artist": "Q-Man",
        })
        files = [self.full_path(f) for f in
                 ['back.jpg',
                  'discovery.jpg', "Pharell - frontin'.jpg",
                  'nickelback - Curb.jpg',
                  'foobar.jpg', 'folder.jpg',     # Though this is debatable
                  'Q-Man - foobar.jpg', 'Q-man - foobar (cover).jpg']]
        for f in files:
            file(f, "w").close()
            self.files.append(f)
            cover = self._find_cover(song)
            if cover:
                actual = os.path.abspath(cover.name)
                self.failUnlessEqual(
                    actual, f, "\"%s\" should trump \"%s\"" % (f, actual))
            else:
                self.failUnless(f, self.full_path('back.jpg'))
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:27,代码来源:test_util_cover.py


示例11: test_rename_to_existing

 def test_rename_to_existing(self):
     quux.rename(quux("~basename"))
     if os.name != "nt":
         self.failUnlessRaises(
             ValueError, quux.rename, fsnative(u"/dev/null"))
     self.failUnlessRaises(ValueError, quux.rename,
                           os.path.join(DATA_DIR, "silence-44-s.ogg"))
开发者ID:pyromaniac2k,项目名称:quodlibet,代码行数:7,代码来源:test_formats__audio.py


示例12: test_main

 def test_main(self):
     self.assertEqual(decode_value("~#foo", 0.25), u"0.25")
     self.assertEqual(decode_value("~#foo", 4), u"4")
     self.assertEqual(decode_value("~#foo", "bar"), u"bar")
     self.assertTrue(isinstance(decode_value("~#foo", "bar"), unicode))
     path = fsnative(u"/foobar")
     self.assertEqual(decode_value("~filename", path), fsdecode(path))
开发者ID:pyromaniac2k,项目名称:quodlibet,代码行数:7,代码来源:test_formats__audio.py


示例13: test_embedded_special_cover_words

    def test_embedded_special_cover_words(self):
        """Tests that words incidentally containing embedded "special" words
        album keywords (e.g. cover, disc, back) don't trigger
        See Issue 818"""

        song = AudioFile({
            "~filename": fsnative(os.path.join(self.dir, u"asong.ogg")),
            "album": "foobar",
            "title": "Ode to Baz",
            "artist": "Q-Man",
        })
        data = [('back.jpg', False),
                ('discovery.jpg', False),
                ("Pharell - frontin'.jpg", False),
                ('nickelback - Curb.jpg', False),
                ('foobar.jpg', True),
                ('folder.jpg', True),  # Though this order is debatable
                ('Q-Man - foobar.jpg', True),
                ('Q-man - foobar (cover).jpg', True)]
        for fn, should_find in data:
            f = self.add_file(fn)
            cover = self._find_cover(song)
            if cover:
                actual = os.path.abspath(cover.name)
                self.failUnlessEqual(
                    actual, f, "\"%s\" should trump \"%s\"" % (f, actual))
            else:
                self.failIf(should_find, msg="Couldn't find %s for %s" %
                                             (f, song("~filename")))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:29,代码来源:test_util_cover.py


示例14: lyric_filename

    def lyric_filename(self):
        """Returns the (potential) lyrics filename for this file"""

        filename = self.comma("title").replace(u"/", u"")[:128] + u".lyric"
        sub_dir = (self.comma("lyricist") or self.comma("artist")).replace(u"/", u"")[:128]

        if os.name == "nt":
            # this was added at a later point. only use escape_filename here
            # to keep the linux case the same as before
            filename = escape_filename(filename)
            sub_dir = escape_filename(sub_dir)
        else:
            filename = fsnative(filename)
            sub_dir = fsnative(sub_dir)

        path = os.path.join(expanduser(fsnative(u"~/.lyrics")), sub_dir, filename)
        return path
开发者ID:pfps,项目名称:quodlibet,代码行数:17,代码来源:_audio.py


示例15: test_write

    def test_write(self):
        with self.wrap("playlist") as pl:
            pl.extend(NUMERIC_SONGS)
            pl.extend([fsnative(u"xf0xf0")])
            pl.write()

            with open(pl.filename, "rb") as h:
                self.assertEqual(len(h.read().splitlines()), len(NUMERIC_SONGS) + 1)
开发者ID:faubiguy,项目名称:quodlibet,代码行数:8,代码来源:test_util_collection.py


示例16: setUp

 def setUp(self):
     config.init()
     player = NullPlayer()
     song = AudioFile()
     song.bookmarks = [(10, "bla")]
     song.sanitize(fsnative(u"/"))
     player.song = song
     self.player = player
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:8,代码来源:test_qltk_bookmarks.py


示例17: setUp

 def setUp(self):
     config.RATINGS = config.HardCodedRatingsPrefs()
     self.failUnlessEqual(config.RATINGS.number, NUM_RATINGS)
     self.library = SongLibrary()
     self.library.librarian = SongLibrarian()
     self.af = AudioFile({"~filename": fsnative(u"/foo"), "~#rating": 1.0})
     self.af.sanitize()
     self.rmi = RatingsMenuItem([self.af], self.library)
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:8,代码来源:test_qltk_ratingsmenu.py


示例18: test_msic

 def test_msic(self):
     with realized(self.b):
         self.b.activate()
         self.b.statusbar(1000)
         self.b.statusbar(1)
         song = AudioFile({"~filename": fsnative(u"/fake")})
         song.sanitize()
         self.b.scroll(song)
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:8,代码来源:test_browsers__base.py


示例19: sanitize

    def sanitize(self, filename=None):
        """Fill in metadata defaults. Find ~mountpoint, ~#mtime, ~#filesize
        and ~#added. Check for null bytes in tags.

        Does not raise.
        """

        # Replace nulls with newlines, trimming zero-length segments
        for key, val in self.items():
            if isinstance(val, string_types) and '\0' in val:
                self[key] = '\n'.join(filter(lambda s: s, val.split('\0')))
            # Remove unnecessary defaults
            if key in INTERN_NUM_DEFAULT and val == 0:
                del self[key]

        if filename:
            self["~filename"] = filename
        elif "~filename" not in self:
            raise ValueError("Unknown filename!")

        assert is_fsnative(self["~filename"])

        if self.is_file:
            self["~filename"] = normalize_path(
                self["~filename"], canonicalise=True)
            # Find mount point (terminating at "/" if necessary)
            head = self["~filename"]
            while "~mountpoint" not in self:
                head, tail = os.path.split(head)
                # Prevent infinite loop without a fully-qualified filename
                # (the unit tests use these).
                head = head or "/"
                if os.path.ismount(head):
                    self["~mountpoint"] = head
        else:
            self["~mountpoint"] = fsnative(u"/")

        # Fill in necessary values.
        self.setdefault("~#added", int(time.time()))

        # For efficiency, do a single stat here. See Issue 504
        try:
            stat = os.stat(self['~filename'])
            self["~#mtime"] = stat.st_mtime
            self["~#filesize"] = stat.st_size

            # Issue 342. This is a horrible approximation (due to headers) but
            # on FLACs, the most common case, this should be close enough
            if "~#bitrate" not in self:
                try:
                    # kbps = bytes * 8 / seconds / 1000
                    self["~#bitrate"] = int(stat.st_size /
                                            (self["~#length"] * (1000 / 8)))
                except (KeyError, ZeroDivisionError):
                    pass
        except OSError:
            self["~#mtime"] = 0
开发者ID:pensadorramm,项目名称:quodlibet,代码行数:57,代码来源:_audio.py


示例20: test_lyric_filename

 def test_lyric_filename(self):
     song = AudioFile()
     song["~filename"] = fsnative(u"filename")
     self.assertTrue(is_fsnative(song.lyric_filename))
     song["title"] = u"Title"
     song["artist"] = u"Artist"
     self.assertTrue(is_fsnative(song.lyric_filename))
     song["lyricist"] = u"Lyricist"
     self.assertTrue(is_fsnative(song.lyric_filename))
开发者ID:pyromaniac2k,项目名称:quodlibet,代码行数:9,代码来源:test_formats__audio.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python path.get_home_dir函数代码示例发布时间:2022-05-26
下一篇:
Python path.fsdecode函数代码示例发布时间: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