Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/rest_framework_simplejwt/compat.py: 68%

30 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1import warnings 

2 

3try: 

4 from django.urls import reverse, reverse_lazy 

5except ImportError: 

6 from django.core.urlresolvers import reverse, reverse_lazy # NOQA 

7 

8 

9class RemovedInDjango20Warning(DeprecationWarning): 

10 pass 

11 

12 

13class CallableBool: # pragma: no cover 

14 """ 

15 An boolean-like object that is also callable for backwards compatibility. 

16 """ 

17 

18 do_not_call_in_templates = True 

19 

20 def __init__(self, value): 

21 self.value = value 

22 

23 def __bool__(self): 

24 return self.value 

25 

26 def __call__(self): 

27 warnings.warn( 

28 "Using user.is_authenticated() and user.is_anonymous() as a method " 

29 "is deprecated. Remove the parentheses to use it as an attribute.", 

30 RemovedInDjango20Warning, 

31 stacklevel=2, 

32 ) 

33 return self.value 

34 

35 def __nonzero__(self): # Python 2 compatibility 

36 return self.value 

37 

38 def __repr__(self): 

39 return "CallableBool(%r)" % self.value 

40 

41 def __eq__(self, other): 

42 return self.value == other 

43 

44 def __ne__(self, other): 

45 return self.value != other 

46 

47 def __or__(self, other): 

48 return bool(self.value or other) 

49 

50 def __hash__(self): 

51 return hash(self.value) 

52 

53 

54CallableFalse = CallableBool(False) 

55CallableTrue = CallableBool(True)