本文整理汇总了Python中stat.st_uid方法的典型用法代码示例。如果您正苦于以下问题:Python stat.st_uid方法的具体用法?Python stat.st_uid怎么用?Python stat.st_uid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stat
的用法示例。
在下文中一共展示了stat.st_uid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_chown_uid_gid_arguments_must_be_index
# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_uid [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))
示例2: test_chown
# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_uid [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)
示例3: test_chown_with_root
# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_uid [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)
示例4: _GetUserAndGroupID
# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_uid [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
示例5: _test_all_chown_common
# 需要导入模块: import stat [as 别名]
# 或者: from stat import st_uid [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)