fs.permissions

An abstract permissions container.

class fs.permissions.Permissions(names=None, mode=None, user=None, group=None, other=None, sticky=None, setuid=None, setguid=None)[source]

An abstraction for file system permissions.

Parameters:
  • names (list) – A list of permissions.
  • mode (int) – A mode integer.
  • user (str) – A triplet of user permissions, e.g. "rwx" or "r--"
  • group (str) – A triplet of group permissions, e.g. "rwx" or "r--"
  • other (str) – A triplet of other permissions, e.g. "rwx" or "r--"
  • sticky (bool) – A boolean for the sticky bit.
  • setuid (bool) – A boolean for the setuid bit.
  • setguid (bool) – A boolean for the setuid bit.

Permissions objects store information regarding the permissions on a resource. It supports Linux permissions, but is generic enough to manage permission information from almost any filesystem.

>>> from fs.permissions import Permissions
>>> p = Permissions(user='rwx', group='rw-', other='r--')
>>> print(p)
rwxrw-r--
>>> p.mode
500
>>> oct(p.mode)
'0764'
add(*permissions)[source]

Add permission(s).

Parameters:permissions – Permission name(s).
as_str()[source]

Get a linux-style string representation of permissions.

check(*permissions)[source]

Check if one or more permissions are enabled.

Parameters:permissions – Permission name(s).
Returns:True if all given permissions are set.
Rtype bool:
copy()[source]

Make a copy of this permissions object.

classmethod create(init=None)[source]

Create a permissions object from an initial value.

Parameters:init – May be None for equivalent for 0o777 permissions, a mode integer, or a list of permission names.
Returns:mode integer, that may be used by os.makedir (amongst others).
>>> Permissions.create(None)
Permissions(user='rwx', group='rwx', other='rwx')
>>> Permissions.create(0o700)
Permissions(user='rwx', group='', other='')
>>> Permissions.create(['u_r', 'u_w', 'u_x'])
Permissions(user='rwx', group='', other='')
dump()[source]

Get a list suitable for serialization.

g_r

Boolean for ‘g_r’ permission.

g_w

Boolean for ‘g_w’ permission.

g_x

Boolean for ‘g_x’ permission.

classmethod get_mode(init)[source]

Convert an initial value to a mode integer.

classmethod load(permissions)[source]

Load a serialized permissions object.

mode

Mode integer.

o_r

Boolean for ‘o_r’ permission.

o_w

Boolean for ‘o_w’ permission.

o_x

Boolean for ‘o_x’ permission.

classmethod parse(ls)[source]

Parse permissions in linux notation.

remove(*permissions)[source]

Remove permission(s).

Parameters:permissions – Permission name(s).
setguid

Boolean for ‘setguid’ permission.

setuid

Boolean for ‘setuid’ permission.

sticky

Boolean for ‘sticky’ permission.

u_r

Boolean for ‘u_r’ permission.

u_w

Boolean for ‘u_w’ permission.

u_x

Boolean for ‘u_x’ permission.

fs.permissions.make_mode(init)[source]

Make a mode integer from an initial value.