2323from scim2_models .annotations import Required
2424from scim2_models .annotations import Returned
2525from scim2_models .context import Context
26- from scim2_models .utils import UNION_TYPES
27- from scim2_models .utils import find_field_name
28- from scim2_models .utils import normalize_attribute_name
29- from scim2_models .utils import to_camel
26+ from scim2_models .utils import _UNION_TYPES
27+ from scim2_models .utils import _find_field_name
28+ from scim2_models .utils import _normalize_attribute_name
29+ from scim2_models .utils import _to_camel
3030
3131
32- def contains_attribute_or_subattributes (
32+ def _contains_attribute_or_subattributes (
3333 attribute_urns : list [str ], attribute_urn : str
3434) -> bool :
3535 return attribute_urn in attribute_urns or any (
@@ -43,8 +43,8 @@ class BaseModel(PydanticBaseModel):
4343
4444 model_config = ConfigDict (
4545 alias_generator = AliasGenerator (
46- validation_alias = normalize_attribute_name ,
47- serialization_alias = to_camel ,
46+ validation_alias = _normalize_attribute_name ,
47+ serialization_alias = _to_camel ,
4848 ),
4949 validate_assignment = True ,
5050 populate_by_name = True ,
@@ -77,7 +77,7 @@ def get_field_root_type(cls, attribute_name: str) -> Optional[type]:
7777 attribute_type = cls .model_fields [attribute_name ].annotation
7878
7979 # extract 'x' from 'Optional[x]'
80- if get_origin (attribute_type ) in UNION_TYPES :
80+ if get_origin (attribute_type ) in _UNION_TYPES :
8181 attribute_type = get_args (attribute_type )[0 ]
8282
8383 # extract 'x' from 'List[x]'
@@ -93,7 +93,7 @@ def get_field_multiplicity(cls, attribute_name: str) -> bool:
9393 attribute_type = cls .model_fields [attribute_name ].annotation
9494
9595 # extract 'x' from 'Optional[x]'
96- if get_origin (attribute_type ) in UNION_TYPES :
96+ if get_origin (attribute_type ) in _UNION_TYPES :
9797 attribute_type = get_args (attribute_type )[0 ]
9898
9999 origin = get_origin (attribute_type )
@@ -159,7 +159,7 @@ def normalize_dict_keys(
159159 result = {}
160160
161161 for key , val in input_dict .items ():
162- field_name = find_field_name (model_class , key )
162+ field_name = _find_field_name (model_class , key )
163163 field_type = (
164164 model_class .get_field_root_type (field_name ) if field_name else None
165165 )
@@ -170,7 +170,7 @@ def normalize_dict_keys(
170170 if field_name and field_type == Any :
171171 result [key ] = normalize_value (val )
172172 else :
173- result [normalize_attribute_name (key )] = normalize_value (
173+ result [_normalize_attribute_name (key )] = normalize_value (
174174 val , field_type
175175 )
176176
@@ -285,11 +285,11 @@ def check_replacement_request_mutability(
285285 and issubclass (cls , Resource )
286286 and original is not None
287287 ):
288- cls .check_mutability_issues (original , obj )
288+ cls ._check_mutability_issues (original , obj )
289289 return obj
290290
291291 @classmethod
292- def check_mutability_issues (
292+ def _check_mutability_issues (
293293 cls , original : "BaseModel" , replacement : "BaseModel"
294294 ) -> None :
295295 """Compare two instances, and check for differences of values on the fields marked as immutable."""
@@ -316,9 +316,9 @@ def check_mutability_issues(
316316 original_val = getattr (original , field_name )
317317 replacement_value = getattr (replacement , field_name )
318318 if original_val is not None and replacement_value is not None :
319- cls .check_mutability_issues (original_val , replacement_value )
319+ cls ._check_mutability_issues (original_val , replacement_value )
320320
321- def set_complex_attribute_urns (self ) -> None :
321+ def _set_complex_attribute_urns (self ) -> None :
322322 """Navigate through attributes and sub-attributes of type ComplexAttribute, and mark them with a '_attribute_urn' attribute.
323323
324324 '_attribute_urn' will later be used by 'get_attribute_urn'.
@@ -359,14 +359,14 @@ def scim_serializer(
359359 scim_ctx = info .context .get ("scim" ) if info .context else None
360360
361361 if scim_ctx and Context .is_request (scim_ctx ):
362- value = self .scim_request_serializer (value , info )
362+ value = self ._scim_request_serializer (value , info )
363363
364364 if scim_ctx and Context .is_response (scim_ctx ):
365- value = self .scim_response_serializer (value , info )
365+ value = self ._scim_response_serializer (value , info )
366366
367367 return value
368368
369- def scim_request_serializer (self , value : Any , info : FieldSerializationInfo ) -> Any :
369+ def _scim_request_serializer (self , value : Any , info : FieldSerializationInfo ) -> Any :
370370 """Serialize the fields according to mutability indications passed in the serialization context."""
371371 mutability = self .get_field_annotation (info .field_name , Mutability )
372372 scim_ctx = info .context .get ("scim" ) if info .context else None
@@ -390,7 +390,9 @@ def scim_request_serializer(self, value: Any, info: FieldSerializationInfo) -> A
390390
391391 return value
392392
393- def scim_response_serializer (self , value : Any , info : FieldSerializationInfo ) -> Any :
393+ def _scim_response_serializer (
394+ self , value : Any , info : FieldSerializationInfo
395+ ) -> Any :
394396 """Serialize the fields according to returnability indications passed in the serialization context."""
395397 returnability = self .get_field_annotation (info .field_name , Returned )
396398 attribute_urn = self .get_attribute_urn (info .field_name )
@@ -399,17 +401,17 @@ def scim_response_serializer(self, value: Any, info: FieldSerializationInfo) ->
399401 info .context .get ("scim_excluded_attributes" , []) if info .context else []
400402 )
401403
402- attribute_urn = normalize_attribute_name (attribute_urn )
403- included_urns = [normalize_attribute_name (urn ) for urn in included_urns ]
404- excluded_urns = [normalize_attribute_name (urn ) for urn in excluded_urns ]
404+ attribute_urn = _normalize_attribute_name (attribute_urn )
405+ included_urns = [_normalize_attribute_name (urn ) for urn in included_urns ]
406+ excluded_urns = [_normalize_attribute_name (urn ) for urn in excluded_urns ]
405407
406408 if returnability == Returned .never :
407409 return None
408410
409411 if returnability == Returned .default and (
410412 (
411413 included_urns
412- and not contains_attribute_or_subattributes (
414+ and not _contains_attribute_or_subattributes (
413415 included_urns , attribute_urn
414416 )
415417 )
@@ -427,7 +429,7 @@ def model_serializer_exclude_none(
427429 self , handler : SerializerFunctionWrapHandler , info : SerializationInfo
428430 ) -> dict [str , Any ]:
429431 """Remove `None` values inserted by the :meth:`~scim2_models.base.BaseModel.scim_serializer`."""
430- self .set_complex_attribute_urns ()
432+ self ._set_complex_attribute_urns ()
431433 result = handler (self )
432434 return {key : value for key , value in result .items () if value is not None }
433435
0 commit comments