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

Python senf.fsnative函数代码示例

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

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



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

示例1: 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, _VDISPLAY, _faulthandler_fobj

    # 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)

    if xvfbwrapper is not None:
        _VDISPLAY = xvfbwrapper.Xvfb()
        _VDISPLAY.start()

    _BUS_INFO = None
    if os.name != "nt" and "DBUS_SESSION_BUS_ADDRESS" in environ:
        _BUS_INFO = dbus_launch_user()
        environ.update(_BUS_INFO)

    quodlibet.init(no_translations=True, no_excepthook=True)
    quodlibet.app.name = "QL Tests"

    # to get around pytest silencing
    _faulthandler_fobj = os.fdopen(os.dup(sys.__stderr__.fileno()), "w")
    faulthandler.enable(_faulthandler_fobj)

    # try to make things the same in case a different locale is active.
    # LANG for gettext, setlocale for number formatting etc.
    # Note: setlocale has to be called after Gtk.init()
    try:
        if os.name != "nt":
            environ["LANG"] = locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
        else:
            environ["LANG"] = "en_US.utf8"
            locale.setlocale(locale.LC_ALL, "english")
    except locale.Error:
        pass
开发者ID:elfalem,项目名称:quodlibet,代码行数:60,代码来源:__init__.py


示例2: test_types

    def test_types(self):
        from quodlibet.util.path import normalize_path

        assert isinstance(normalize_path(fsnative(u"foo"), False), fsnative)
        assert isinstance(normalize_path("foo", False), fsnative)
        assert isinstance(normalize_path(fsnative(u"foo"), True), fsnative)
        assert isinstance(normalize_path("foo", True), fsnative)
开发者ID:Muges,项目名称:quodlibet,代码行数:7,代码来源:test_util.py


示例3: test_sanitize_py2_fixup

    def test_sanitize_py2_fixup(self):
        if PY3:
            return

        old = dict.__new__(AudioFile)
        dict.__init__(old, {
            b"foo": b"bar",
            u"öäü": b"bla",
            "~#num": u"1",
            "~#num2": u"1.25",
            "~#num3": u"bla",
            "~filename": u"text",
            "~mountpoint": b"bytes",
            "~somethingdifferent": b"hello",
        })

        fixed = {
            b"foo": u"bar",
            u"öäü": u"bla",
            "~#num": 1,
            "~#num2": 1.25,
            "~#num3": 0,
            "~filename": fsnative(u"text"),
            "~mountpoint": fsnative(u"bytes"),
            "~somethingdifferent": u"hello",
        }

        data = dump_audio_files([old])
        new = load_audio_files(data)
        assert dict(new[0]) == fixed
        for v1, v2 in zip(sorted(new[0].values()), sorted(fixed.values())):
            assert type(v1) is type(v2)
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:32,代码来源:test_formats___init__.py


示例4: 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:urielz,项目名称:quodlibet,代码行数:8,代码来源:test_util_tagsfrompath.py


示例5: test_selection_set_songs

    def test_selection_set_songs(self):
        song = AudioFile()
        song["~filename"] = fsnative(u"foo")
        sel = MockSelData()
        qltk.selection_set_songs(sel, [song])
        assert sel.data == fsn2bytes(fsnative(u"foo"), "utf-8")

        assert qltk.selection_get_filenames(sel) == [fsnative(u"foo")]
开发者ID:piotrdrag,项目名称:quodlibet,代码行数:8,代码来源:test_qltk___init__.py


示例6: 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 listitems(self):
            self[key] = val
            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 NUMERIC_ZERO_DEFAULT and val == 0:
                del self[key]

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

        assert isinstance(self["~filename"], fsnative)

        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 fsnative(u"/")
                if 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:elfalem,项目名称:quodlibet,代码行数:58,代码来源:_audio.py


示例7: test_sort_albums

 def test_sort_albums(self):
     # Make sure we have more than one album, one having a null date
     f = AF({"~filename": fsnative(u"/1"), "album": "one"})
     f2 = AF({"~filename": fsnative(u"/2"), "album": "one"})
     f3 = AF({"~filename": fsnative(u"/3"), "album": "two", "date": "2009"})
     f4 = AF({"~filename": fsnative(u"/4")})
     albums, count = _sort_albums([f, f2, f3, f4])
     self.failUnlessEqual(count, 1)
     self.failUnlessEqual(len(albums), 2)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:9,代码来源:test_qltk_information.py


示例8: test_uri2fsn

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


示例9: atomic_save

def atomic_save(filename, mode):
    """Try to replace the content of a file in the safest way possible.

    A temporary file will be created in the same directory where the
    replacement data can be written into.
    After writing is done the data will be flushed to disk and the original
    file replaced atomically.

    In case of an error this raises IOError and OSError and the original file
    will be untouched. In case the computer crashes or any other
    non-recoverable error happens the temporary file will be left behind and
    has to be deleted manually.

    with atomic_save("config.cfg", "wb") as f:
        f.write(data)
    """

    assert isinstance(filename, fsnative)

    dir_ = os.path.dirname(filename)
    basename = os.path.basename(filename)
    fileobj = tempfile.NamedTemporaryFile(
        mode=mode, dir=dir_,
        prefix=basename + fsnative(u"_"), suffix=fsnative(u".tmp"),
        delete=False)

    try:
        yield fileobj

        fileobj.flush()
        fileno = fileobj.fileno()

        if os.name != "nt" and hasattr(fcntl, "F_FULLFSYNC"):
            # on OSX fsync doesn't sync all the way..
            # https://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html
            # https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fsync.2.html
            fcntl.fcntl(fileno, fcntl.F_FULLFSYNC)
        else:
            # on linux fsync goes all the way by default
            # http://linux.die.net/man/2/fsync
            os.fsync(fileno)

        fileobj.close()

        if os.name == "nt":
            _windows_rename(fileobj.name, filename)
        else:
            os.rename(fileobj.name, filename)
    except:
        try:
            os.unlink(fileobj.name)
        except OSError:
            pass
        raise
    finally:
        fileobj.close()
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:56,代码来源:atomic.py


示例10: test_conv

    def test_conv(self):
        empty = fsnative(u"")

        v = self.c.filter(empty, fsnative(u"foobar baz"))
        self.failUnlessEqual(v, fsnative(u"foobar baz"))
        self.failUnless(isinstance(v, fsnative))

        v = self.c.filter(empty, fsnative(u"Foobar.BAZ"))
        self.failUnlessEqual(v, fsnative(u"foobar.baz"))
        self.failUnless(isinstance(v, fsnative))
开发者ID:elfalem,项目名称:quodlibet,代码行数:10,代码来源:test_qltk_renamefiles.py


示例11: test_roundtrip

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

        for source in paths:
            path = uri2fsn(fsn2uri(fsnative(source)))
            self.assertTrue(isinstance(path, fsnative))
            self.assertEqual(path, fsnative(source))
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:10,代码来源:test_util_path.py


示例12: test_fsn2uri

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


示例13: 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(isinstance(v, fsnative))

        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:elfalem,项目名称:quodlibet,代码行数:12,代码来源:test_qltk_renamefiles.py


示例14: set_scan_dirs

def set_scan_dirs(dirs):
    """Saves a list of fs paths which should be scanned

    Args:
        list
    """

    assert all(isinstance(d, fsnative) for d in dirs)

    if is_windows():
        joined = fsnative(u":").join(dirs)
    else:
        joined = join_escape(dirs, fsnative(u":"))
    config.setbytes("settings", "scan", fsn2bytes(joined, "utf-8"))
开发者ID:piotrdrag,项目名称:quodlibet,代码行数:14,代码来源:library.py


示例15: 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)
                assert path_equal(
                    actual, f, "\"%s\" should trump \"%s\"" % (f, actual))
            else:
                self.failIf(should_find, msg="Couldn't find %s for %s" %
                                             (f, song("~filename")))
开发者ID:LudoBike,项目名称:quodlibet,代码行数:29,代码来源:test_util_cover.py


示例16: 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"), text_type))
     path = fsnative(u"/foobar")
     self.assertEqual(decode_value("~filename", path), fsn2text(path))
开发者ID:Muges,项目名称:quodlibet,代码行数:7,代码来源:test_formats__audio.py


示例17: 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,
                           get_data_path("silence-44-s.ogg"))
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:7,代码来源:test_formats__audio.py


示例18: test_drag_data_get

 def test_drag_data_get(self):
     b = self.bar
     song = AudioFile()
     song["~filename"] = fsnative(u"foo")
     sel = MockSelData()
     qltk.selection_set_songs(sel, [song])
     b._drag_data_get(None, None, sel, DND_QL, None)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:7,代码来源:test_browsers_playlists.py


示例19: 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")
        with self.wrap("playlist", lib) as pl:
            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)

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


示例20: limit_path

def limit_path(path, ellipsis=True):
    """Reduces the filename length of all filenames in the given path
    to the common maximum length for current platform.

    While the limits are depended on the file system and more restrictions
    may apply, this covers the common case.
    """

    assert isinstance(path, fsnative)

    main, ext = os.path.splitext(path)
    parts = main.split(sep)
    for i, p in enumerate(parts):
        # Limit each path section to 255 (bytes on linux, chars on win).
        # http://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
        limit = 255
        if i == len(parts) - 1:
            limit -= len(ext)

        if len(p) > limit:
            if ellipsis:
                p = p[:limit - 2] + fsnative(u"..")
            else:
                p = p[:limit]
        parts[i] = p

    return sep.join(parts) + ext
开发者ID:elfalem,项目名称:quodlibet,代码行数:27,代码来源:path.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python senf.path2fsn函数代码示例发布时间:2022-05-27
下一篇:
Python senf.fsn2uri函数代码示例发布时间: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