當前位置: 首頁>>代碼示例>>Python>>正文


Python posix.stat_result方法代碼示例

本文整理匯總了Python中posix.stat_result方法的典型用法代碼示例。如果您正苦於以下問題:Python posix.stat_result方法的具體用法?Python posix.stat_result怎麽用?Python posix.stat_result使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在posix的用法示例。


在下文中一共展示了posix.stat_result方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ismount_different_device

# 需要導入模塊: import posix [as 別名]
# 或者: from posix import stat_result [as 別名]
def test_ismount_different_device(self):
        # Simulate the path being on a different device from its parent by
        # mocking out st_dev.
        save_lstat = os.lstat
        def fake_lstat(path):
            st_ino = 0
            st_dev = 0
            if path == ABSTFN:
                st_dev = 1
                st_ino = 1
            return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
        try:
            os.lstat = fake_lstat
            self.assertIs(posixpath.ismount(ABSTFN), True)
        finally:
            os.lstat = save_lstat 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_posixpath.py

示例2: test_ismount_directory_not_readable

# 需要導入模塊: import posix [as 別名]
# 或者: from posix import stat_result [as 別名]
def test_ismount_directory_not_readable(self):
        # issue #2466: Simulate ismount run on a directory that is not
        # readable, which used to return False.
        save_lstat = os.lstat
        def fake_lstat(path):
            st_ino = 0
            st_dev = 0
            if path.startswith(ABSTFN) and path != ABSTFN:
                # ismount tries to read something inside the ABSTFN directory;
                # simulate this being forbidden (no read permission).
                raise OSError("Fake [Errno 13] Permission denied")
            if path == ABSTFN:
                st_dev = 1
                st_ino = 1
            return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
        try:
            os.lstat = fake_lstat
            self.assertIs(posixpath.ismount(ABSTFN), True)
        finally:
            os.lstat = save_lstat 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_posixpath.py

示例3: testUnknownUser

# 需要導入模塊: import posix [as 別名]
# 或者: from posix import stat_result [as 別名]
def testUnknownUser(self):
        # CNY-1071
        # Tests that FileFromFilesystem packs '+UID' as the owner (and '+GID'
        # as the group) if the owner/group don't exist.
        fobj = tempfile.NamedTemporaryFile()
        fobj.write("test\n")
        fobj.flush()

        uid, gid = self.findUnknownIds()

        import posix
        origLstat = os.lstat
        def myLstat(path):
            s = origLstat(path)
            if path == fobj.name:
                # Convert the stat info to a tuple
                s = tuple(s)
                # Replace st_uid and st_gid
                s = s[:4] + (uid, gid) + s[6:]
                # Convert to stat_result
                s = posix.stat_result(s)
                self.assertEqual(s.st_uid, uid)
                self.assertEqual(s.st_gid, gid)
            return s

        try:
            os.lstat = myLstat
            # No failure here
            f = files.FileFromFilesystem(fobj.name, None)
            self.assertEqual(f.inode.owner(), "+" + str(uid))
            self.assertEqual(f.inode.group(), "+" + str(gid))
        finally:
            os.lstat = origLstat 
開發者ID:sassoftware,項目名稱:conary,代碼行數:35,代碼來源:filestest.py

示例4: stat_file

# 需要導入模塊: import posix [as 別名]
# 或者: from posix import stat_result [as 別名]
def stat_file(filename):
    inzip_path, is_dir = _get_inzip_path(filename, OSError)
    info = exxo_importer.exe_zip.getinfo(inzip_path)
    stat_result = list(os.stat(sys.executable))
    stat_result[6] = info.file_size
    if is_dir:
        stat_result[0] &= ~(stat.S_IFREG | stat.S_IFLNK)
        stat_result[0] |= stat.S_IFDIR
    return posix.stat_result(stat_result) 
開發者ID:mbachry,項目名稱:exxo,代碼行數:11,代碼來源:_exxo_hack.py

示例5: stat

# 需要導入模塊: import posix [as 別名]
# 或者: from posix import stat_result [as 別名]
def stat(self):
        """
        Returns information about this path (similarly to boto3's ObjectSummary).
        For compatibility with pathlib, the returned object some similar attributes like os.stat_result.
        The result is looked up at each call to this method
        """
        self._absolute_path_validation()
        if not self.key:
            return None
        return super().stat() 
開發者ID:liormizr,項目名稱:s3path,代碼行數:12,代碼來源:s3path.py

示例6: __getattr__

# 需要導入模塊: import posix [as 別名]
# 或者: from posix import stat_result [as 別名]
def __getattr__(self, item):
        if item in vars(stat_result):
            raise UnsupportedOperation('{} do not support {} attribute'.format(type(self).__name__, item))
        return super().__getattribute__(item) 
開發者ID:liormizr,項目名稱:s3path,代碼行數:6,代碼來源:s3path.py

示例7: testUnknownUser

# 需要導入模塊: import posix [as 別名]
# 或者: from posix import stat_result [as 別名]
def testUnknownUser(self):
        # CNY-1071
        repos = self.openRepository()
        self.addComponent('foo:runtime', '1', '', [('/foo/contents0', 'foo\n')])
        self.updatePkg('foo:runtime')

        uid, gid = self.findUnknownIds()

        import posix
        origLstat = os.lstat
        def myLstat(path):
            s = origLstat(path)
            if path == util.joinPaths(self.rootDir, '/foo/contents0'):
                # Convert the stat info to a tuple
                s = tuple(s)
                # Replace st_uid and st_gid
                s = s[:4] + (uid, gid) + s[6:]
                # Convert to stat_result
                s = posix.stat_result(s)
                self.assertEqual(s.st_uid, uid)
                self.assertEqual(s.st_gid, gid)
            return s

        try:
            os.lstat = myLstat
            # No errors here
            self.erasePkg(self.rootDir, 'foo:runtime', '1')

            db = database.Database(self.rootDir, self.cfg.dbPath)
            rbnum = db.rollbackStack.getList()[-1]

            rb = db.rollbackStack.getRollback(rbnum)

            # Make changeset absolute
            cs = rb.getLocalChangeset(0).makeAbsolute(repos)

            self.logFilter.add()
            ret, out = self.captureOutput(showchangeset.displayChangeSet,
                db, cs, None, self.cfg, lsl=True)
            # Verify there is a warning.
            self.logFilter.compare(
                ['warning: No primary troves in changeset, listing all troves']
            )
            # Make sure we don't display the plus sign
            self.assertEqual(out[:33], "-rw-r--r--    1 %-8s %-8s" %
                                 (uid, gid))

            # No errors here either
            self.rollback(self.rootDir, 1)
        finally:
            os.lstat = origLstat 
開發者ID:sassoftware,項目名稱:conary,代碼行數:53,代碼來源:updatetest.py


注:本文中的posix.stat_result方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。