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)¶ An abstraction for file system permissions.
参数: - 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)¶ Add permission(s).
参数: permissions – Permission name(s).
-
as_str()¶ Get a linux-style string representation of permissions.
-
check(*permissions)¶ Check if one or more permissions are enabled.
参数: permissions – Permission name(s). 返回: True if all given permissions are set. Rtype bool:
-
copy()¶ Make a copy of this permissions object.
-
classmethod
create(init=None)¶ Create a permissions object from an initial value.
参数: init – May be None for equivalent for 0o777 permissions, a mode integer, or a list of permission names. 返回: 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()¶ 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)¶ Convert an initial value to a mode integer.
-
classmethod
load(permissions)¶ 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)¶ Parse permissions in linux notation.
-
remove(*permissions)¶ Remove permission(s).
参数: 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)¶ Make a mode integer from an initial value.