@@ -9,7 +9,7 @@ class DefaultRequirementType(AttributeDict):
99 """
1010 Stores Policy Requirement Arguments in `arg_[n]` value
1111 example:
12- class MyPolicyHandler(BasePolicyHandlerWithRequirement ):
12+ class MyPolicyHandler(PolicyWithRequirement ):
1313 ...
1414
1515 policy = MyPolicyHandler['req1', 'req2', 'req2']
@@ -26,40 +26,40 @@ def __init__(self, *args: t.Any) -> None:
2626class _PolicyOperandMixin :
2727 @t .no_type_check
2828 def __and__ (
29- cls : t .Union ["BasePolicyHandler " , t .Type ["BasePolicyHandler " ]],
30- other : t .Union ["BasePolicyHandler " , t .Type ["BasePolicyHandler " ]],
31- ) -> "BasePolicyHandler " :
29+ cls : t .Union ["Policy " , t .Type ["Policy " ]],
30+ other : t .Union ["Policy " , t .Type ["Policy " ]],
31+ ) -> "Policy " :
3232 return _ANDPolicy (cls , other )
3333
3434 @t .no_type_check
3535 def __or__ (
36- cls : t .Union ["BasePolicyHandler " , t .Type ["BasePolicyHandler " ]],
37- other : t .Union ["BasePolicyHandler " , t .Type ["BasePolicyHandler " ]],
38- ) -> "BasePolicyHandler " :
36+ cls : t .Union ["Policy " , t .Type ["Policy " ]],
37+ other : t .Union ["Policy " , t .Type ["Policy " ]],
38+ ) -> "Policy " :
3939 return _ORPolicy (cls , other )
4040
4141 @t .no_type_check
4242 def __invert__ (
43- cls : t .Union ["BasePolicyHandler " , t .Type ["BasePolicyHandler " ]],
44- ) -> "BasePolicyHandler " :
43+ cls : t .Union ["Policy " , t .Type ["Policy " ]],
44+ ) -> "Policy " :
4545 return _NOTPolicy (cls )
4646
4747
48- class BasePolicyHandlerMetaclass (_PolicyOperandMixin , ABCMeta ):
48+ class PolicyMetaclass (_PolicyOperandMixin , ABCMeta ):
4949 pass
5050
5151
52- class BasePolicyHandler (ABC , _PolicyOperandMixin , metaclass = BasePolicyHandlerMetaclass ):
52+ class Policy (ABC , _PolicyOperandMixin , metaclass = PolicyMetaclass ):
5353 @abstractmethod
5454 async def handle (self , context : IExecutionContext ) -> bool :
5555 """Run Policy Actions and return true or false"""
5656
5757
58- class BasePolicyHandlerWithRequirement (
59- BasePolicyHandler ,
58+ class PolicyWithRequirement (
59+ Policy ,
6060 ABC ,
6161):
62- __requirements__ : t .Dict [int , "BasePolicyHandler " ] = {}
62+ __requirements__ : t .Dict [int , "Policy " ] = {}
6363
6464 requirement_type : t .Type = DefaultRequirementType
6565
@@ -68,7 +68,7 @@ class BasePolicyHandlerWithRequirement(
6868 async def handle (self , context : IExecutionContext , requirement : t .Any ) -> bool :
6969 """Handle Policy Action"""
7070
71- def __class_getitem__ (cls , parameters : t .Any ) -> "BasePolicyHandler " :
71+ def __class_getitem__ (cls , parameters : t .Any ) -> "Policy " :
7272 _parameters = parameters if isinstance (parameters , tuple ) else (parameters ,)
7373 hash_id = hash (_parameters )
7474 if hash_id not in cls .__requirements__ :
@@ -79,24 +79,24 @@ def __class_getitem__(cls, parameters: t.Any) -> "BasePolicyHandler":
7979
8080
8181PolicyType = t .Union [
82- BasePolicyHandler ,
83- t .Type [BasePolicyHandler ],
84- BasePolicyHandlerWithRequirement ,
85- t .Type [BasePolicyHandlerWithRequirement ],
82+ Policy ,
83+ t .Type [Policy ],
84+ PolicyWithRequirement ,
85+ t .Type [PolicyWithRequirement ],
8686]
8787
8888
8989class _OperandResolversMixin :
9090 def _get_policy_object (
9191 self , context : IExecutionContext , policy : PolicyType
92- ) -> t .Union [BasePolicyHandler , BasePolicyHandlerWithRequirement ]:
92+ ) -> t .Union [Policy , PolicyWithRequirement ]:
9393 if isinstance (policy , type ):
9494 # resolve instance from EllarInjector, we assume the policy hand been decorated with @injector decorator.
9595 return context .get_service_provider ().get (policy ) # type: ignore[no-any-return]
9696 return policy
9797
9898
99- class _ORPolicy (BasePolicyHandler , _OperandResolversMixin ):
99+ class _ORPolicy (Policy , _OperandResolversMixin ):
100100 def __init__ (self , policy_1 : PolicyType , policy_2 : PolicyType ) -> None :
101101 self ._policy_1 = policy_1
102102 self ._policy_2 = policy_2
@@ -111,7 +111,7 @@ async def handle(self, context: IExecutionContext) -> bool:
111111 return _policy_1_result or _policy_2_result
112112
113113
114- class _NOTPolicy (BasePolicyHandler , _OperandResolversMixin ):
114+ class _NOTPolicy (Policy , _OperandResolversMixin ):
115115 def __init__ (self , policy_1 : PolicyType ) -> None :
116116 self ._policy_1 = policy_1
117117
@@ -134,7 +134,7 @@ async def handle(self, context: IExecutionContext) -> bool:
134134 return _policy_1_result and _policy_2_result
135135
136136
137- class _PolicyHandlerWithRequirement (BasePolicyHandler , _OperandResolversMixin ):
137+ class _PolicyHandlerWithRequirement (Policy , _OperandResolversMixin ):
138138 def __init__ (self , policy_1 : PolicyType , requirement : t .Any ) -> None :
139139 self ._policy_1 = policy_1
140140 self .requirement = requirement
0 commit comments