mirror of
https://github.com/SELinuxProject/setools
synced 2025-03-20 18:16:41 +00:00
Default: Revise factory method so attributes can be readonly.
This commit is contained in:
parent
14eb9a793e
commit
3c8f2d9ad4
@ -72,16 +72,19 @@ cdef class Default(PolicySymbol):
|
|||||||
"""Base class for default_* statements."""
|
"""Base class for default_* statements."""
|
||||||
|
|
||||||
cdef:
|
cdef:
|
||||||
public object ruletype
|
readonly object ruletype
|
||||||
public object tclass
|
readonly ObjClass tclass
|
||||||
object _default
|
object _default
|
||||||
|
|
||||||
# the default object is not exposed as a Python
|
# the default object is not exposed as a Python
|
||||||
# attribute, as it collides with CPython code
|
# attribute, as it collides with CPython code
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef factory(SELinuxPolicy policy, ObjClass tclass, user, role, type_, range_):
|
cdef inline Default factory(SELinuxPolicy policy, ObjClass tclass, user, role, type_, range_):
|
||||||
"""Factory function for Default objects."""
|
"""Factory function for Default objects."""
|
||||||
|
cdef:
|
||||||
|
Default obj
|
||||||
|
DefaultRange objr
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
obj = Default()
|
obj = Default()
|
||||||
@ -108,13 +111,13 @@ cdef class Default(PolicySymbol):
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
if range_:
|
if range_:
|
||||||
obj = DefaultRange()
|
objr = DefaultRange()
|
||||||
obj.policy = policy
|
objr.policy = policy
|
||||||
obj.ruletype = DefaultRuletype.default_range
|
objr.ruletype = DefaultRuletype.default_range
|
||||||
obj.tclass = tclass
|
objr.tclass = tclass
|
||||||
obj._default = DefaultValue.from_default_range(range_)
|
objr._default = DefaultValue.from_default_range(range_)
|
||||||
obj.default_range = DefaultRangeValue.from_default_range(range_)
|
objr.default_range = DefaultRangeValue.from_default_range(range_)
|
||||||
return obj
|
return objr
|
||||||
|
|
||||||
raise ValueError("At least one of user, role, type_, or range_ must be specified.")
|
raise ValueError("At least one of user, role, type_, or range_ must be specified.")
|
||||||
|
|
||||||
@ -145,7 +148,7 @@ cdef class DefaultRange(Default):
|
|||||||
|
|
||||||
"""A default_range statement."""
|
"""A default_range statement."""
|
||||||
|
|
||||||
cdef public object default_range
|
cdef readonly object default_range
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{0.ruletype} {0.tclass} {0.default} {0.default_range};".format(self)
|
return "{0.ruletype} {0.tclass} {0.default} {0.default_range};".format(self)
|
||||||
|
Loading…
Reference in New Issue
Block a user