55from scim2_filter_parser .parser import SCIMParser
66from scim2_models import BaseModel
77from scim2_models import CaseExact
8- from scim2_models import Error
8+ from scim2_models import InvalidPathException
9+ from scim2_models import InvalidValueException
910from scim2_models import Mutability
11+ from scim2_models import MutabilityException
12+ from scim2_models import NoTargetException
1013from scim2_models import PatchOperation
1114from scim2_models import Required
1215from scim2_models import Resource
1316from scim2_models import Returned
17+ from scim2_models import SensitiveException
1418
1519from scim2_server .filter import evaluate_filter
16- from scim2_server .utils import SCIMException
1720from scim2_server .utils import get_by_alias
1821from scim2_server .utils import get_or_create
1922from scim2_server .utils import handle_extension
@@ -55,7 +58,7 @@ def parse_attribute_path(attribute_path: str | None) -> dict[str, Any] | None:
5558
5659 match = ATTRIBUTE_PATH_REGEX .match (attribute_path )
5760 if not match :
58- raise SCIMException ( Error . make_invalid_path_error () )
61+ raise InvalidPathException ( )
5962 parse_attribute_path .cache [attribute_path ] = match .groupdict ()
6063 return match .groupdict ()
6164
@@ -148,7 +151,7 @@ def match_multi_valued_attribute_sub(
148151 attribute_name = get_by_alias (type (model ), attribute )
149152 multi_valued_attribute = get_or_create (model , attribute_name , True )
150153 if not isinstance (multi_valued_attribute , list ):
151- raise SCIMException ( Error . make_invalid_path_error () )
154+ raise InvalidPathException ( )
152155 token_stream = SCIMLexer ().tokenize (condition )
153156 condition = SCIMParser ().parse (token_stream )
154157 self .init_return (model , attribute_name , sub_attribute , self .value )
@@ -160,13 +163,13 @@ def match_multi_valued_attribute(
160163 self , attribute : str , condition : str , model : BaseModel
161164 ):
162165 if self .REQUIRES_VALUE and not isinstance (self .value , dict ):
163- raise SCIMException ( Error . make_invalid_value_error () )
166+ raise InvalidValueException ( )
164167 attribute_name = get_by_alias (type (model ), attribute )
165168 multi_valued_attribute = get_or_create (
166169 model , attribute_name , self .REQUIRES_VALUE
167170 )
168171 if not isinstance (multi_valued_attribute , list ):
169- raise SCIMException ( Error . make_invalid_path_error () )
172+ raise InvalidPathException ( )
170173 token_stream = SCIMLexer ().tokenize (condition )
171174 condition = SCIMParser ().parse (token_stream )
172175 if self .REQUIRES_VALUE :
@@ -196,7 +199,7 @@ def match_complex_attribute(self, attribute: str, model: BaseModel, sub_path: st
196199 self .match_attribute (sub_path , value )
197200 else :
198201 if not isinstance (complex_attribute , BaseModel ):
199- raise SCIMException ( Error . make_invalid_path_error () )
202+ raise InvalidPathException ( )
200203 self .match_attribute (sub_path , complex_attribute )
201204
202205 def match_attribute (self , attribute : str , model : BaseModel ):
@@ -205,9 +208,9 @@ def match_attribute(self, attribute: str, model: BaseModel):
205208
206209 def call_on_root (self , model : Resource ):
207210 if not self .OPERATE_ON_ROOT :
208- raise SCIMException ( Error . make_no_target_error () )
211+ raise NoTargetException ( )
209212 if not isinstance (self .value , dict ):
210- raise SCIMException ( Error . make_invalid_value_error () )
213+ raise InvalidValueException ( )
211214 for k , v in self .value .items ():
212215 ext , scim_name = handle_extension (model , k )
213216 if ext == model :
@@ -233,7 +236,7 @@ def operation(cls, model: BaseModel, attribute: str, value: Any):
233236 return
234237
235238 if model .get_field_annotation (alias , Mutability ) == Mutability .read_only :
236- raise SCIMException ( Error . make_mutability_error () )
239+ raise MutabilityException ( )
237240
238241 if model .get_field_multiplicity (alias ):
239242 if getattr (model , alias ) is None :
@@ -247,7 +250,7 @@ def operation(cls, model: BaseModel, attribute: str, value: Any):
247250 model .get_field_annotation (alias , Required ) == Required .true
248251 and not new_value
249252 ):
250- raise SCIMException ( Error . make_invalid_value_error () )
253+ raise InvalidValueException ( )
251254 setattr (model , alias , new_value )
252255
253256
@@ -268,10 +271,10 @@ def operation(cls, model: BaseModel, attribute: str, value: Any):
268271 Mutability .read_only ,
269272 Mutability .immutable ,
270273 ):
271- raise SCIMException ( Error . make_mutability_error () )
274+ raise MutabilityException ( )
272275
273276 if model .get_field_annotation (alias , Required ) == Required .true :
274- raise SCIMException ( Error . make_invalid_value_error () )
277+ raise InvalidValueException ( )
275278
276279 setattr (model , alias , None )
277280
@@ -283,21 +286,21 @@ class ReplaceOperator(Operator):
283286 def operation (cls , model : BaseModel , attribute : str , value : Any ):
284287 alias = get_by_alias (type (model ), attribute )
285288 if model .get_field_multiplicity (alias ) and not isinstance (value , list ):
286- raise SCIMException ( Error . make_invalid_value_error () )
289+ raise InvalidValueException ( )
287290
288291 existing_value = getattr (model , alias )
289292 new_value = parse_new_value (model , alias , value )
290293 if new_value == existing_value :
291294 return
292295
293296 if model .get_field_annotation (alias , Mutability ) == Mutability .read_only :
294- raise SCIMException ( Error . make_mutability_error () )
297+ raise MutabilityException ( )
295298
296299 if (
297300 model .get_field_annotation (alias , Required ) == Required .true
298301 and not new_value
299302 ):
300- raise SCIMException ( Error . make_invalid_value_error () )
303+ raise InvalidValueException ( )
301304 setattr (model , alias , new_value )
302305
303306
@@ -372,7 +375,7 @@ def init_return(
372375 model .get_field_annotation (alias , Mutability ) == Mutability .write_only
373376 or model .get_field_annotation (alias , Returned ) == Returned .never
374377 ):
375- raise SCIMException ( Error . make_sensitive_error () )
378+ raise SensitiveException ( )
376379
377380 @classmethod
378381 def operation (
0 commit comments