当前位置: 首页>>代码示例>>Python>>正文


Python stat.st_gid方法代码示例

本文整理汇总了Python中stat.st_gid方法的典型用法代码示例。如果您正苦于以下问题:Python stat.st_gid方法的具体用法?Python stat.st_gid怎么用?Python stat.st_gid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stat的用法示例。


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

示例1: test_chown_uid_gid_arguments_must_be_index

# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_gid [as 别名]
def test_chown_uid_gid_arguments_must_be_index(self):
        stat = os.stat(support.TESTFN)
        uid = stat.st_uid
        gid = stat.st_gid
        for value in (-1.0, -1j, decimal.Decimal(-1), fractions.Fraction(-2, 2)):
            self.assertRaises(TypeError, os.chown, support.TESTFN, value, gid)
            self.assertRaises(TypeError, os.chown, support.TESTFN, uid, value)
        self.assertIsNone(os.chown(support.TESTFN, uid, gid))
        self.assertIsNone(os.chown(support.TESTFN, -1, -1)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_os.py

示例2: test_chown

# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_gid [as 别名]
def test_chown(self):
        gid_1, gid_2 = groups[:2]
        uid = os.stat(support.TESTFN).st_uid
        os.chown(support.TESTFN, uid, gid_1)
        gid = os.stat(support.TESTFN).st_gid
        self.assertEqual(gid, gid_1)
        os.chown(support.TESTFN, uid, gid_2)
        gid = os.stat(support.TESTFN).st_gid
        self.assertEqual(gid, gid_2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_os.py

示例3: test_chown_with_root

# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_gid [as 别名]
def test_chown_with_root(self):
        uid_1, uid_2 = all_users[:2]
        gid = os.stat(support.TESTFN).st_gid
        os.chown(support.TESTFN, uid_1, gid)
        uid = os.stat(support.TESTFN).st_uid
        self.assertEqual(uid, uid_1)
        os.chown(support.TESTFN, uid_2, gid)
        uid = os.stat(support.TESTFN).st_uid
        self.assertEqual(uid, uid_2) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_os.py

示例4: test_chown_without_permission

# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_gid [as 别名]
def test_chown_without_permission(self):
        uid_1, uid_2 = all_users[:2]
        gid = os.stat(support.TESTFN).st_gid
        with self.assertRaises(PermissionError):
            os.chown(support.TESTFN, uid_1, gid)
            os.chown(support.TESTFN, uid_2, gid) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_os.py

示例5: _GetUserAndGroupID

# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_gid [as 别名]
def _GetUserAndGroupID(self, path):
        '''
            Returns tuple (success, UID, GID) for object identified by path.
            UID & GID are returned as strings.
            If failed to get values, success=False
        '''
        success, uid, gid = False, 0, 0
        try:
            stat = os.stat(path)
            uid = str(stat.st_uid)
            gid = str(stat.st_gid)
            success = True
        except OSError as ex:
            log.error("Exception trying to get uid & gid for file " + path + ' Exception details: ' + str(ex))
        return success, uid, gid 
开发者ID:ydkhatri,项目名称:mac_apt,代码行数:17,代码来源:macinfo.py

示例6: _test_all_chown_common

# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_gid [as 别名]
def _test_all_chown_common(self, chown_func, first_param, stat_func):
        """Common code for chown, fchown and lchown tests."""
        def check_stat(uid, gid):
            if stat_func is not None:
                stat = stat_func(first_param)
                self.assertEqual(stat.st_uid, uid)
                self.assertEqual(stat.st_gid, gid)
        uid = os.getuid()
        gid = os.getgid()
        # test a successful chown call
        chown_func(first_param, uid, gid)
        check_stat(uid, gid)
        chown_func(first_param, -1, gid)
        check_stat(uid, gid)
        chown_func(first_param, uid, -1)
        check_stat(uid, gid)

        if uid == 0:
            # Try an amusingly large uid/gid to make sure we handle
            # large unsigned values.  (chown lets you use any
            # uid/gid you like, even if they aren't defined.)
            #
            # This problem keeps coming up:
            #   http://bugs.python.org/issue1747858
            #   http://bugs.python.org/issue4591
            #   http://bugs.python.org/issue15301
            # Hopefully the fix in 4591 fixes it for good!
            #
            # This part of the test only runs when run as root.
            # Only scary people run their tests as root.

            big_value = 2**31
            chown_func(first_param, big_value, big_value)
            check_stat(big_value, big_value)
            chown_func(first_param, -1, -1)
            check_stat(big_value, big_value)
            chown_func(first_param, uid, gid)
            check_stat(uid, gid)
        elif platform.system() in ('HP-UX', 'SunOS'):
            # HP-UX and Solaris can allow a non-root user to chown() to root
            # (issue #5113)
            raise unittest.SkipTest("Skipping because of non-standard chown() "
                                    "behavior")
        else:
            # non-root cannot chown to root, raises OSError
            self.assertRaises(OSError, chown_func, first_param, 0, 0)
            check_stat(uid, gid)
            self.assertRaises(OSError, chown_func, first_param, 0, -1)
            check_stat(uid, gid)
            if 0 not in os.getgroups():
                self.assertRaises(OSError, chown_func, first_param, -1, 0)
                check_stat(uid, gid)
        # test illegal types
        for t in str, float:
            self.assertRaises(TypeError, chown_func, first_param, t(uid), gid)
            check_stat(uid, gid)
            self.assertRaises(TypeError, chown_func, first_param, uid, t(gid))
            check_stat(uid, gid) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:60,代码来源:test_posix.py


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