Open the context
Choose the project folder and name the files or behavior involved.
Format POSIX permission bits as nine readable characters. Check setuid, setgid and sticky bits with and without execute permission, rejecting negative or oversized modes without changing any file.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def permission_text(mode):
if type(mode) is not int or not 0 <= mode <= 0o7777:
raise ValueError("permission bits only")
out = []
for shift in (6, 3, 0):
bits = (mode >> shift) & 7
out.extend(c if bits & bit else "-"
for c, bit in zip("rwx", (4, 2, 1)))
for pos, bit, mark in ((2, 0o4000, "s"), (5, 0o2000, "s"), (8, 0o1000, "t")):
if mode & bit: out[pos] = mark if out[pos] == "x" else mark.upper()
return "".join(out)The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.