@@ -123,48 +123,6 @@ class PermissionDenied(RuntimeError):
123
123
"""Permission denied to the resource"""
124
124
125
125
126
- class Identity (object ):
127
- """Represent the user's identity.
128
-
129
- :param id: The user id
130
- :param auth_type: The authentication type used to confirm the user's
131
- identity.
132
-
133
- The identity is used to represent the user's identity in the system. This
134
- object is created on login, or on the start of the request as loaded from
135
- the user's session.
136
-
137
- Once loaded it is sent using the `identity-loaded` signal, and should be
138
- populated with additional required information.
139
-
140
- Needs that are provided by this identity should be added to the `provides`
141
- set after loading.
142
- """
143
- def __init__ (self , id : Optional [Any ], auth_type : Optional [str ] = None ) -> None :
144
- self .id = id
145
- self .auth_type = auth_type
146
- self .provides : Set [Union [Need , ItemNeed ]] = set ()
147
-
148
- def can (self , permission : BasePermission ) -> bool :
149
- """Whether the identity has access to the permission.
150
-
151
- :param permission: The permission to test provision for.
152
- """
153
- return permission .allows (self )
154
-
155
- def __repr__ (self ) -> str :
156
- return '<{0} id="{1}" auth_type="{2}" provides={3}>' .format (
157
- self .__class__ .__name__ , self .id , self .auth_type , self .provides
158
- )
159
-
160
-
161
- class AnonymousIdentity (Identity ):
162
- """An anonymous identity"""
163
-
164
- def __init__ (self ) -> None :
165
- Identity .__init__ (self , None )
166
-
167
-
168
126
class IdentityContext (object ):
169
127
"""The context of an identity for a permission.
170
128
@@ -176,14 +134,14 @@ class IdentityContext(object):
176
134
flow is continued (context manager) or the function is executed (decorator).
177
135
"""
178
136
179
- def __init__ (self , permission : BasePermission , http_exception : Optional [int ] = None ) -> None :
137
+ def __init__ (self , permission : ' BasePermission' , http_exception : Optional [int ] = None ) -> None :
180
138
self .permission = permission
181
139
self .http_exception = http_exception
182
140
"""The permission of this principal
183
141
"""
184
142
185
143
@property
186
- def identity (self ) -> Identity :
144
+ def identity (self ) -> ' Identity' :
187
145
"""The identity of this principal
188
146
"""
189
147
return cast (Identity , g .identity )
@@ -230,28 +188,28 @@ def __bool__(self) -> bool:
230
188
"""
231
189
return self ._bool ()
232
190
233
- def __or__ (self , other : Union ['Permission' , BasePermission ]) -> Union ['Permission' , BasePermission ]:
191
+ def __or__ (self , other : Union ['Permission' , ' BasePermission' ]) -> Union ['Permission' , ' BasePermission' ]:
234
192
"""See ``OrPermission``.
235
193
"""
236
194
return self .or_ (other )
237
195
238
- def or_ (self , other : Union ['Permission' , BasePermission ]) -> Union ['Permission' , BasePermission ]:
196
+ def or_ (self , other : Union ['Permission' , ' BasePermission' ]) -> Union ['Permission' , ' BasePermission' ]:
239
197
return OrPermission (self , other )
240
198
241
- def __and__ (self , other : Union ['Permission' , BasePermission ]) -> Union ['Permission' , BasePermission ]:
199
+ def __and__ (self , other : Union ['Permission' , ' BasePermission' ]) -> Union ['Permission' , ' BasePermission' ]:
242
200
"""See ``AndPermission``.
243
201
"""
244
202
return self .and_ (other )
245
203
246
- def and_ (self , other : Union ['Permission' , BasePermission ]) -> Union ['Permission' , BasePermission ]:
204
+ def and_ (self , other : Union ['Permission' , ' BasePermission' ]) -> Union ['Permission' , ' BasePermission' ]:
247
205
return AndPermission (self , other )
248
206
249
- def __invert__ (self ) -> Union ['NotPermission' , BasePermission ]:
207
+ def __invert__ (self ) -> Union ['NotPermission' , ' BasePermission' ]:
250
208
"""See ``NotPermission``.
251
209
"""
252
210
return self .invert ()
253
211
254
- def invert (self ) -> Union ['NotPermission' , BasePermission ]:
212
+ def invert (self ) -> Union ['NotPermission' , ' BasePermission' ]:
255
213
return NotPermission (self )
256
214
257
215
def require (self , http_exception : Optional [int ] = None ) -> IdentityContext :
@@ -287,7 +245,7 @@ def test(self, http_exception: Optional[int] = None) -> None:
287
245
with self .require (http_exception ):
288
246
pass
289
247
290
- def allows (self , identity : Identity ) -> bool :
248
+ def allows (self , identity : ' Identity' ) -> bool :
291
249
"""Whether the identity can access this permission.
292
250
293
251
:param identity: The identity
@@ -303,6 +261,49 @@ def can(self) -> bool:
303
261
"""
304
262
return self .require ().can ()
305
263
264
+ class Identity :
265
+ """Represent the user's identity.
266
+
267
+ :param id: The user id
268
+ :param auth_type: The authentication type used to confirm the user's
269
+ identity.
270
+
271
+ The identity is used to represent the user's identity in the system. This
272
+ object is created on login, or on the start of the request as loaded from
273
+ the user's session.
274
+
275
+ Once loaded it is sent using the `identity-loaded` signal, and should be
276
+ populated with additional required information.
277
+
278
+ Needs that are provided by this identity should be added to the `provides`
279
+ set after loading.
280
+ """
281
+ def __init__ (self , id : Optional [Any ], auth_type : Optional [str ] = None ) -> None :
282
+ self .id = id
283
+ self .auth_type = auth_type
284
+ self .provides : Set [Union [Need , ItemNeed ]] = set ()
285
+
286
+ def can (self , permission : BasePermission ) -> bool :
287
+ """Whether the identity has access to the permission.
288
+
289
+ :param permission: The permission to test provision for.
290
+ """
291
+ return permission .allows (self )
292
+
293
+ def __repr__ (self ) -> str :
294
+ return '<{0} id="{1}" auth_type="{2}" provides={3}>' .format (
295
+ self .__class__ .__name__ , self .id , self .auth_type , self .provides
296
+ )
297
+
298
+
299
+ class AnonymousIdentity (Identity ):
300
+ """An anonymous identity"""
301
+
302
+ def __init__ (self ) -> None :
303
+ Identity .__init__ (self , None )
304
+
305
+
306
+
306
307
307
308
class _NaryOperatorPermission (BasePermission ):
308
309
0 commit comments