11import abc
2- from typing import Any , Dict , Optional
2+ from typing import Any , Dict , List , Optional
33
44import cachelib
55
@@ -77,22 +77,23 @@ def get_user_acl(self, raw_user_permissions: str) -> UserAcl:
7777
7878
7979class UserAcl (object ):
80- def __init__ (self , raw_acl_options , raw_user_permissions ):
81- # type: (typing.List[dict], str) -> None
80+ def __init__ (self , raw_acl_options : List [Dict ], raw_user_permissions : str ):
8281 self ._acl_options = self ._parse_acl_options (raw_acl_options )
8382 self ._acl = self ._parse_user_permissions (raw_user_permissions )
84- self ._acl_lookup_cache = {} # type: dict
83+ self ._acl_lookup_cache : Dict [ str , Any ] = {}
8584
8685 @classmethod
87- def _parse_acl_options (cls , raw_acl_options ):
88- # type: (typing.List[dict]) -> dict
86+ def _parse_acl_options (
87+ cls ,
88+ raw_acl_options : List [Dict [str , Any ]]
89+ ) -> Dict [str , Dict [str , int ]]:
8990 # Load ACL options, so we can decode the user ACL
90- acl_options = {
91+ acl_options : Dict [ str , Dict [ str , int ]] = {
9192 'local' : {},
9293 'global' : {}
93- } # type: dict
94- local_index = 0
95- global_index = 0
94+ }
95+ local_index : int = 0
96+ global_index : int = 0
9697
9798 for opt in raw_acl_options or []:
9899 if opt ['is_local' ] == 1 :
@@ -109,10 +110,12 @@ def _parse_acl_options(cls, raw_acl_options):
109110 return acl_options
110111
111112 @classmethod
112- def _parse_user_permissions (cls , raw_user_permissions ):
113- # type: (str) -> dict
114- seq_cache = {} # type: dict
115- acl = {}
113+ def _parse_user_permissions (
114+ cls ,
115+ raw_user_permissions : str
116+ ) -> Dict [str , str ]:
117+ seq_cache : Dict [str , str ] = {}
118+ acl : Dict [str , str ] = {}
116119
117120 split_user_permissions = raw_user_permissions \
118121 .rstrip ()\
@@ -136,8 +139,7 @@ def _parse_user_permissions(cls, raw_user_permissions):
136139
137140 return acl
138141
139- def has_privilege (self , privilege , forum_id = 0 ):
140- # type: (str, int) -> bool
142+ def has_privilege (self , privilege : str , forum_id : int = 0 ) -> bool :
141143 # Parse negation
142144 str_forum_id = str (forum_id )
143145
@@ -172,13 +174,12 @@ def has_privilege(self, privilege, forum_id=0):
172174 except IndexError :
173175 pass
174176
175- output = (
177+ output : bool = (
176178 negated ^ self ._acl_lookup_cache [str_forum_id ][option ]
177- ) # type: bool
179+ )
178180 return output
179181
180- def has_privileges (self , * privileges , ** kwargs ):
181- # type: (*str, **int) -> bool
182+ def has_privileges (self , * privileges : str , ** kwargs : int ) -> bool :
182183 forum_id = kwargs .get ('forum_id' , 0 )
183184
184185 output = False
0 commit comments