mirror of
https://github.com/SELinuxProject/setools
synced 2025-04-25 21:02:03 +00:00
ioctlSet: implement a __format__ function which has a "," formatter.
The "," formatter will format the output as comma separated rather than space separated.
This commit is contained in:
parent
e8d9d611eb
commit
ab41dc81e6
@ -158,11 +158,24 @@ class AVRule(BaseTERule):
|
||||
class ioctlSet(set):
|
||||
|
||||
"""
|
||||
A set with an overridden str function which compresses
|
||||
the output into ioctl ranges.
|
||||
A set with overridden string functions which compresses
|
||||
the output into ioctl ranges instead of individual elements.
|
||||
"""
|
||||
|
||||
def __format__(self, spec):
|
||||
"""
|
||||
String formating.
|
||||
|
||||
The standard formatting (no specification) will render the
|
||||
ranges of ioctls, space separated.
|
||||
|
||||
The , option by itself will render the ranges of ioctls,
|
||||
comma separated
|
||||
|
||||
Any other combination of formatting options will fall back
|
||||
to set's formatting behavior.
|
||||
"""
|
||||
|
||||
def __str__(self):
|
||||
# generate short permission notation
|
||||
perms = sorted(self)
|
||||
shortlist = []
|
||||
@ -173,10 +186,18 @@ class ioctlSet(set):
|
||||
else:
|
||||
shortlist.append("0x{0:04x}".format(group[0]))
|
||||
|
||||
if not spec:
|
||||
return " ".join(shortlist)
|
||||
elif spec == ",":
|
||||
return ", ".join(shortlist)
|
||||
else:
|
||||
return super(ioctlSet, self).__format__(spec)
|
||||
|
||||
def __str__(self):
|
||||
return "{0}".format(self)
|
||||
|
||||
def __repr__(self):
|
||||
return "{{ {0} }}".format(self)
|
||||
return "{{ {0:,} }}".format(self)
|
||||
|
||||
def ranges(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user