MCPcopy Index your code
hub / github.com/RustPython/RustPython / chown

Function chown

Lib/shutil.py:1471–1509  ·  view source on GitHub ↗

Change owner user and group of the given path. user and group can be the uid/gid or the user/group names, and in that case, they are converted to their respective uid/gid. If dir_fd is set, it should be an open file descriptor to the directory to be used as the root of *path* if it

(path, user=None, group=None, *, dir_fd=None, follow_symlinks=True)

Source from the content-addressed store, hash-verified

1469
1470
1471def chown(path, user=None, group=None, *, dir_fd=None, follow_symlinks=True):
1472 """Change owner user and group of the given path.
1473
1474 user and group can be the uid/gid or the user/group names, and in that case,
1475 they are converted to their respective uid/gid.
1476
1477 If dir_fd is set, it should be an open file descriptor to the directory to
1478 be used as the root of *path* if it is relative.
1479
1480 If follow_symlinks is set to False and the last element of the path is a
1481 symbolic link, chown will modify the link itself and not the file being
1482 referenced by the link.
1483 """
1484 sys.audit('shutil.chown', path, user, group)
1485
1486 if user is None and group is None:
1487 raise ValueError("user and/or group must be set")
1488
1489 _user = user
1490 _group = group
1491
1492 # -1 means don't change it
1493 if user is None:
1494 _user = -1
1495 # user can either be an int (the uid) or a string (the system username)
1496 elif isinstance(user, str):
1497 _user = _get_uid(user)
1498 if _user is None:
1499 raise LookupError("no such user: {!r}".format(user))
1500
1501 if group is None:
1502 _group = -1
1503 elif not isinstance(group, int):
1504 _group = _get_gid(group)
1505 if _group is None:
1506 raise LookupError("no such group: {!r}".format(group))
1507
1508 os.chown(path, _user, _group, dir_fd=dir_fd,
1509 follow_symlinks=follow_symlinks)
1510
1511def get_terminal_size(fallback=(80, 24)):
1512 """Get the size of the terminal window.

Callers

nothing calls this directly

Calls 5

isinstanceFunction · 0.85
_get_uidFunction · 0.85
_get_gidFunction · 0.85
chownMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected