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

Python posixpath.samestat函数代码示例

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

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



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

示例1: test_samestat

 def test_samestat(self):
     f = open(test_support.TESTFN + "1", "wb")
     try:
         f.write("foo")
         f.close()
         self.assertIs(
             posixpath.samestat(os.stat(test_support.TESTFN + "1"), os.stat(test_support.TESTFN + "1")), True
         )
         # If we don't have links, assume that os.stat() doesn't return resonable
         # inode information and thus, that samefile() doesn't work
         if hasattr(os, "symlink"):
             if hasattr(os, "symlink"):
                 os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
                 self.assertIs(
                     posixpath.samestat(os.stat(test_support.TESTFN + "1"), os.stat(test_support.TESTFN + "2")), True
                 )
                 os.remove(test_support.TESTFN + "2")
             f = open(test_support.TESTFN + "2", "wb")
             f.write("bar")
             f.close()
             self.assertIs(
                 posixpath.samestat(os.stat(test_support.TESTFN + "1"), os.stat(test_support.TESTFN + "2")), False
             )
     finally:
         if not f.close():
             f.close()
开发者ID:herenowcoder,项目名称:stackless,代码行数:26,代码来源:test_posixpath.py


示例2: test_samestat_on_links

    def test_samestat_on_links(self):
        test_fn1 = support.TESTFN + "1"
        test_fn2 = support.TESTFN + "2"
        self._create_file(test_fn1)
        test_fns = (test_fn1, test_fn2)
        os.symlink(*test_fns)
        stats = map(os.stat, test_fns)
        self.assertTrue(posixpath.samestat(*stats))
        os.remove(test_fn2)

        self._create_file(test_fn2)
        stats = map(os.stat, test_fns)
        self.assertFalse(posixpath.samestat(*stats))

        self.assertRaises(TypeError, posixpath.samestat)
开发者ID:pierreorz,项目名称:web_ctp,代码行数:15,代码来源:test_posixpath.py


示例3: _fwalk

    def _fwalk(topfd, toppath, isbytes, topdown, onerror, follow_symlinks):
        # Note: This uses O(depth of the directory tree) file descriptors: if
        # necessary, it can be adapted to only require O(1) FDs, see issue
        # #13734.

        scandir_it = scandir(topfd)
        dirs = []
        nondirs = []
        entries = None if topdown or follow_symlinks else []
        for entry in scandir_it:
            name = entry.name
            if isbytes:
                name = fsencode(name)
            try:
                if entry.is_dir():
                    dirs.append(name)
                    if entries is not None:
                        entries.append(entry)
                else:
                    nondirs.append(name)
            except OSError:
                try:
                    # Add dangling symlinks, ignore disappeared files
                    if entry.is_symlink():
                        nondirs.append(name)
                except OSError:
                    pass

        if topdown:
            yield toppath, dirs, nondirs, topfd

        for name in dirs if entries is None else zip(dirs, entries):
            try:
                if not follow_symlinks:
                    if topdown:
                        orig_st = stat(name, dir_fd=topfd, follow_symlinks=False)
                    else:
                        assert entries is not None
                        name, entry = name
                        orig_st = entry.stat(follow_symlinks=False)
                dirfd = open(name, O_RDONLY, dir_fd=topfd)
            except OSError as err:
                if onerror is not None:
                    onerror(err)
                continue
            try:
                if follow_symlinks or path.samestat(orig_st, stat(dirfd)):
                    dirpath = path.join(toppath, name)
                    yield from _fwalk(dirfd, dirpath, isbytes,
                                      topdown, onerror, follow_symlinks)
            finally:
                close(dirfd)

        if not topdown:
            yield toppath, dirs, nondirs, topfd
开发者ID:Daetalus,项目名称:cpython,代码行数:55,代码来源:os.py


示例4: _fwalk

    def _fwalk(topfd, toppath, topdown, onerror, follow_symlinks):
        # Note: This uses O(depth of the directory tree) file descriptors: if
        # necessary, it can be adapted to only require O(1) FDs, see issue
        # #13734.

        names = listdir(topfd)
        dirs, nondirs = [], []
        for name in names:
            try:
                # Here, we don't use AT_SYMLINK_NOFOLLOW to be consistent with
                # walk() which reports symlinks to directories as directories.
                # We do however check for symlinks before recursing into
                # a subdirectory.
                if st.S_ISDIR(stat(name, dir_fd=topfd).st_mode):
                    dirs.append(name)
                else:
                    nondirs.append(name)
            except FileNotFoundError:
                try:
                    # Add dangling symlinks, ignore disappeared files
                    if st.S_ISLNK(
                            stat(name, dir_fd=topfd, follow_symlinks=False)
                                    .st_mode):
                        nondirs.append(name)
                except FileNotFoundError:
                    continue

        if topdown:
            yield toppath, dirs, nondirs, topfd

        for name in dirs:
            try:
                orig_st = stat(name, dir_fd=topfd,
                               follow_symlinks=follow_symlinks)
                dirfd = open(name, O_RDONLY, dir_fd=topfd)
            except OSError as err:
                if onerror is not None:
                    onerror(err)
                continue
            try:
                if follow_symlinks or path.samestat(orig_st, stat(dirfd)):
                    dirpath = path.join(toppath, name)
                    yield from _fwalk(dirfd, dirpath, topdown, onerror,
                                      follow_symlinks)
            finally:
                close(dirfd)

        if not topdown:
            yield toppath, dirs, nondirs, topfd
开发者ID:pashkash,项目名称:reviews,代码行数:49,代码来源:os.py


示例5: fwalk

    def fwalk(top=".", topdown=True, onerror=None, *, follow_symlinks=False, dir_fd=None):
        """Directory tree generator.

        This behaves exactly like walk(), except that it yields a 4-tuple

            dirpath, dirnames, filenames, dirfd

        `dirpath`, `dirnames` and `filenames` are identical to walk() output,
        and `dirfd` is a file descriptor referring to the directory `dirpath`.

        The advantage of fwalk() over walk() is that it's safe against symlink
        races (when follow_symlinks is False).

        If dir_fd is not None, it should be a file descriptor open to a directory,
          and top should be relative; top will then be relative to that directory.
          (dir_fd is always supported for fwalk.)

        Caution:
        Since fwalk() yields file descriptors, those are only valid until the
        next iteration step, so you should dup() them if you want to keep them
        for a longer period.

        Example:

        import os
        for root, dirs, files, rootfd in os.fwalk('python/Lib/email'):
            print(root, "consumes", end="")
            print(sum([os.stat(name, dir_fd=rootfd).st_size for name in files]),
                  end="")
            print("bytes in", len(files), "non-directory files")
            if 'CVS' in dirs:
                dirs.remove('CVS')  # don't visit CVS directories
        """
        if not isinstance(top, int) or not hasattr(top, '__index__'):
            top = fspath(top)
        # Note: To guard against symlink races, we use the standard
        # lstat()/open()/fstat() trick.
        if not follow_symlinks:
            orig_st = stat(top, follow_symlinks=False, dir_fd=dir_fd)
        topfd = open(top, O_RDONLY, dir_fd=dir_fd)
        try:
            if (follow_symlinks or (st.S_ISDIR(orig_st.st_mode) and
                                    path.samestat(orig_st, stat(topfd)))):
                yield from _fwalk(topfd, top, isinstance(top, bytes),
                                  topdown, onerror, follow_symlinks)
        finally:
            close(topfd)
开发者ID:Daetalus,项目名称:cpython,代码行数:47,代码来源:os.py


示例6: _fwalk

    def _fwalk(topfd, toppath, topdown, onerror, followlinks):
        # Note: This uses O(depth of the directory tree) file descriptors: if
        # necessary, it can be adapted to only require O(1) FDs, see issue
        # #13734.

        # whether to follow symlinks
        flag = 0 if followlinks else AT_SYMLINK_NOFOLLOW

        names = flistdir(topfd)
        dirs, nondirs = [], []
        for name in names:
            # Here, we don't use AT_SYMLINK_NOFOLLOW to be consistent with
            # walk() which reports symlinks to directories as directories. We do
            # however check for symlinks before recursing into a subdirectory.
            if st.S_ISDIR(fstatat(topfd, name).st_mode):
                dirs.append(name)
            else:
                nondirs.append(name)

        if topdown:
            yield toppath, dirs, nondirs, topfd

        for name in dirs:
            try:
                orig_st = fstatat(topfd, name, flag)
                dirfd = openat(topfd, name, O_RDONLY)
            except error as err:
                if onerror is not None:
                    onerror(err)
                return
            try:
                if followlinks or path.samestat(orig_st, fstat(dirfd)):
                    dirpath = path.join(toppath, name)
                    for x in _fwalk(dirfd, dirpath, topdown, onerror, followlinks):
                        yield x
            finally:
                close(dirfd)

        if not topdown:
            yield toppath, dirs, nondirs, topfd
开发者ID:Naddiseo,项目名称:cpython,代码行数:40,代码来源:os.py


示例7: fwalk

    def fwalk(top, topdown=True, onerror=None, followlinks=False):
        """Directory tree generator.

        This behaves exactly like walk(), except that it yields a 4-tuple

            dirpath, dirnames, filenames, dirfd

        `dirpath`, `dirnames` and `filenames` are identical to walk() output,
        and `dirfd` is a file descriptor referring to the directory `dirpath`.

        The advantage of walkfd() over walk() is that it's safe against symlink
        races (when followlinks is False).

        Caution:
        Since fwalk() yields file descriptors, those are only valid until the
        next iteration step, so you should dup() them if you want to keep them
        for a longer period.

        Example:

        import os
        for root, dirs, files, rootfd in os.fwalk('python/Lib/email'):
            print(root, "consumes", end="")
            print(sum([os.fstatat(rootfd, name).st_size for name in files]),
                  end="")
            print("bytes in", len(files), "non-directory files")
            if 'CVS' in dirs:
                dirs.remove('CVS')  # don't visit CVS directories
        """
        # Note: To guard against symlink races, we use the standard
        # lstat()/open()/fstat() trick.
        orig_st = lstat(top)
        topfd = open(top, O_RDONLY)
        try:
            if (followlinks or (st.S_ISDIR(orig_st.st_mode) and
                                path.samestat(orig_st, fstat(topfd)))):
                for x in _fwalk(topfd, top, topdown, onerror, followlinks):
                    yield x
        finally:
            close(topfd)
开发者ID:Naddiseo,项目名称:cpython,代码行数:40,代码来源:os.py


示例8: test_samestat

 def test_samestat(self):
     test_fn = support.TESTFN + "1"
     self._create_file(test_fn)
     test_fns = [test_fn] * 2
     stats = map(os.stat, test_fns)
     self.assertTrue(posixpath.samestat(*stats))
开发者ID:pierreorz,项目名称:web_ctp,代码行数:6,代码来源:test_posixpath.py


示例9: samefile

def samefile(f1, f2):
	"""
	Backport of samefile from Python 3.2 with support for Windows.
	"""
	return posixpath.samestat(compat_stat(f1), compat_stat(f2))
开发者ID:blue-yonder,项目名称:pyscaffold,代码行数:5,代码来源:win_py31_compat.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python posixpath.split函数代码示例发布时间:2022-05-25
下一篇:
Python posixpath.samefile函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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