handle Permissions being initialized with a str

This commit is contained in:
Luna 2020-07-29 16:17:15 -03:00
parent fa4a4138f0
commit b965532621
1 changed files with 5 additions and 3 deletions

View File

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import ctypes
from typing import Optional
from typing import Optional, Union
from quart import current_app as app
@ -77,8 +77,10 @@ class Permissions(ctypes.Union):
_fields_ = [("bits", _RawPermsBits), ("binary", ctypes.c_uint64)]
def __init__(self, val: int):
self.binary = val
def __init__(self, val: Union[str, int]):
# always coerce to int, even when the user gives us a str, because
# python ints are infinity-sized (yes, yes, the memory concerns, yes)
self.binary = int(val)
def __repr__(self):
return f"<Permissions binary={self.binary}>"