Skip to content

Commit db9e367

Browse files
committed
refactor: extract annotation classes in their own file
1 parent 3bd5dc6 commit db9e367

13 files changed

+149
-146
lines changed

scim2_models/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
from .annotations import CaseExact
2+
from .annotations import Mutability
3+
from .annotations import Required
4+
from .annotations import Returned
5+
from .annotations import Uniqueness
16
from .base import BaseModel
2-
from .base import CaseExact
37
from .base import ComplexAttribute
48
from .base import MultiValuedComplexAttribute
5-
from .base import Mutability
6-
from .base import Required
7-
from .base import Returned
8-
from .base import Uniqueness
99
from .context import Context
1010
from .reference import ExternalReference
1111
from .reference import Reference

scim2_models/annotations.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
from enum import Enum
2+
3+
4+
class Mutability(str, Enum):
5+
"""A single keyword indicating the circumstances under which the value of the attribute can be (re)defined."""
6+
7+
read_only = "readOnly"
8+
"""The attribute SHALL NOT be modified."""
9+
10+
read_write = "readWrite"
11+
"""The attribute MAY be updated and read at any time."""
12+
13+
immutable = "immutable"
14+
"""The attribute MAY be defined at resource creation (e.g., POST) or at
15+
record replacement via a request (e.g., a PUT).
16+
17+
The attribute SHALL NOT be updated.
18+
"""
19+
20+
write_only = "writeOnly"
21+
"""The attribute MAY be updated at any time.
22+
23+
Attribute values SHALL NOT be returned (e.g., because the value is a
24+
stored hash). Note: An attribute with a mutability of "writeOnly"
25+
usually also has a returned setting of "never".
26+
"""
27+
28+
_default = read_write
29+
30+
31+
class Returned(str, Enum):
32+
"""A single keyword that indicates when an attribute and associated values are returned in response to a GET request or in response to a PUT, POST, or PATCH request."""
33+
34+
always = "always" # cannot be excluded
35+
"""The attribute is always returned, regardless of the contents of the
36+
"attributes" parameter.
37+
38+
For example, "id" is always returned to identify a SCIM resource.
39+
"""
40+
41+
never = "never" # always excluded
42+
"""The attribute is never returned, regardless of the contents of the
43+
"attributes" parameter."""
44+
45+
default = "default" # included by default but can be excluded
46+
"""The attribute is returned by default in all SCIM operation responses
47+
where attribute values are returned, unless it is explicitly excluded."""
48+
49+
request = "request" # excluded by default but can be included
50+
"""The attribute is returned in response to any PUT, POST, or PATCH
51+
operations if specified in the "attributes" parameter."""
52+
53+
_default = default
54+
55+
56+
class Uniqueness(str, Enum):
57+
"""A single keyword value that specifies how the service provider enforces uniqueness of attribute values."""
58+
59+
none = "none"
60+
"""The values are not intended to be unique in any way."""
61+
62+
server = "server"
63+
"""The value SHOULD be unique within the context of the current SCIM
64+
endpoint (or tenancy) and MAY be globally unique (e.g., a "username", email
65+
address, or other server-generated key or counter).
66+
67+
No two resources on the same server SHOULD possess the same value.
68+
"""
69+
70+
global_ = "global"
71+
"""The value SHOULD be globally unique (e.g., an email address, a GUID, or
72+
other value).
73+
74+
No two resources on any server SHOULD possess the same value.
75+
"""
76+
77+
_default = none
78+
79+
80+
class Required(Enum):
81+
"""A Boolean value that specifies whether the attribute is required or not.
82+
83+
Missing required attributes raise a :class:`~pydantic.ValidationError` on :attr:`~scim2_models.Context.RESOURCE_CREATION_REQUEST` and :attr:`~scim2_models.Context.RESOURCE_REPLACEMENT_REQUEST` validations.
84+
"""
85+
86+
true = True
87+
false = False
88+
89+
_default = false
90+
91+
def __bool__(self) -> bool:
92+
return self.value
93+
94+
95+
class CaseExact(Enum):
96+
"""A Boolean value that specifies whether a string attribute is case- sensitive or not."""
97+
98+
true = True
99+
false = False
100+
101+
_default = false
102+
103+
def __bool__(self) -> bool:
104+
return self.value

scim2_models/base.py

Lines changed: 3 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from enum import Enum
21
from inspect import isclass
32
from typing import Annotated
43
from typing import Any
@@ -22,6 +21,9 @@
2221
from pydantic_core import PydanticCustomError
2322
from typing_extensions import Self
2423

24+
from scim2_models.annotations import Mutability
25+
from scim2_models.annotations import Required
26+
from scim2_models.annotations import Returned
2527
from scim2_models.context import Context
2628
from scim2_models.reference import Reference
2729
from scim2_models.utils import normalize_attribute_name
@@ -116,109 +118,6 @@ def contains_attribute_or_subattributes(
116118
)
117119

118120

119-
class Mutability(str, Enum):
120-
"""A single keyword indicating the circumstances under which the value of the attribute can be (re)defined."""
121-
122-
read_only = "readOnly"
123-
"""The attribute SHALL NOT be modified."""
124-
125-
read_write = "readWrite"
126-
"""The attribute MAY be updated and read at any time."""
127-
128-
immutable = "immutable"
129-
"""The attribute MAY be defined at resource creation (e.g., POST) or at
130-
record replacement via a request (e.g., a PUT).
131-
132-
The attribute SHALL NOT be updated.
133-
"""
134-
135-
write_only = "writeOnly"
136-
"""The attribute MAY be updated at any time.
137-
138-
Attribute values SHALL NOT be returned (e.g., because the value is a
139-
stored hash). Note: An attribute with a mutability of "writeOnly"
140-
usually also has a returned setting of "never".
141-
"""
142-
143-
_default = read_write
144-
145-
146-
class Returned(str, Enum):
147-
"""A single keyword that indicates when an attribute and associated values are returned in response to a GET request or in response to a PUT, POST, or PATCH request."""
148-
149-
always = "always" # cannot be excluded
150-
"""The attribute is always returned, regardless of the contents of the
151-
"attributes" parameter.
152-
153-
For example, "id" is always returned to identify a SCIM resource.
154-
"""
155-
156-
never = "never" # always excluded
157-
"""The attribute is never returned, regardless of the contents of the
158-
"attributes" parameter."""
159-
160-
default = "default" # included by default but can be excluded
161-
"""The attribute is returned by default in all SCIM operation responses
162-
where attribute values are returned, unless it is explicitly excluded."""
163-
164-
request = "request" # excluded by default but can be included
165-
"""The attribute is returned in response to any PUT, POST, or PATCH
166-
operations if specified in the "attributes" parameter."""
167-
168-
_default = default
169-
170-
171-
class Uniqueness(str, Enum):
172-
"""A single keyword value that specifies how the service provider enforces uniqueness of attribute values."""
173-
174-
none = "none"
175-
"""The values are not intended to be unique in any way."""
176-
177-
server = "server"
178-
"""The value SHOULD be unique within the context of the current SCIM
179-
endpoint (or tenancy) and MAY be globally unique (e.g., a "username", email
180-
address, or other server-generated key or counter).
181-
182-
No two resources on the same server SHOULD possess the same value.
183-
"""
184-
185-
global_ = "global"
186-
"""The value SHOULD be globally unique (e.g., an email address, a GUID, or
187-
other value).
188-
189-
No two resources on any server SHOULD possess the same value.
190-
"""
191-
192-
_default = none
193-
194-
195-
class Required(Enum):
196-
"""A Boolean value that specifies whether the attribute is required or not.
197-
198-
Missing required attributes raise a :class:`~pydantic.ValidationError` on :attr:`~scim2_models.Context.RESOURCE_CREATION_REQUEST` and :attr:`~scim2_models.Context.RESOURCE_REPLACEMENT_REQUEST` validations.
199-
"""
200-
201-
true = True
202-
false = False
203-
204-
_default = false
205-
206-
def __bool__(self) -> bool:
207-
return self.value
208-
209-
210-
class CaseExact(Enum):
211-
"""A Boolean value that specifies whether a string attribute is case- sensitive or not."""
212-
213-
true = True
214-
false = False
215-
216-
_default = false
217-
218-
def __bool__(self) -> bool:
219-
return self.value
220-
221-
222121
class BaseModel(PydanticBaseModel):
223122
"""Base Model for everything."""
224123

scim2_models/rfc7643/resource.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
from pydantic.functional_serializers import SerializationInfo
2020
from pydantic.functional_serializers import SerializerFunctionWrapHandler
2121

22+
from ..annotations import CaseExact
23+
from ..annotations import Mutability
24+
from ..annotations import Required
25+
from ..annotations import Returned
26+
from ..annotations import Uniqueness
2227
from ..base import BaseModel
2328
from ..base import BaseModelType
24-
from ..base import CaseExact
2529
from ..base import ComplexAttribute
2630
from ..base import MultiValuedComplexAttribute
27-
from ..base import Mutability
28-
from ..base import Required
29-
from ..base import Returned
30-
from ..base import Uniqueness
3131
from ..base import is_complex_attribute
3232
from ..reference import ExternalReference
3333
from ..reference import URIReference

scim2_models/rfc7643/resource_type.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from pydantic import Field
77
from typing_extensions import Self
88

9-
from ..base import CaseExact
9+
from ..annotations import CaseExact
10+
from ..annotations import Mutability
11+
from ..annotations import Required
12+
from ..annotations import Returned
1013
from ..base import ComplexAttribute
11-
from ..base import Mutability
12-
from ..base import Required
13-
from ..base import Returned
1414
from ..reference import Reference
1515
from ..reference import URIReference
1616
from ..utils import UNION_TYPES

scim2_models/rfc7643/schema.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
from pydantic.alias_generators import to_snake
1717
from pydantic_core import Url
1818

19+
from ..annotations import CaseExact
20+
from ..annotations import Mutability
21+
from ..annotations import Required
22+
from ..annotations import Returned
23+
from ..annotations import Uniqueness
1924
from ..base import BaseModel
20-
from ..base import CaseExact
2125
from ..base import ComplexAttribute
2226
from ..base import MultiValuedComplexAttribute
23-
from ..base import Mutability
24-
from ..base import Required
25-
from ..base import Returned
26-
from ..base import Uniqueness
2727
from ..base import is_complex_attribute
2828
from ..constants import RESERVED_WORDS
2929
from ..reference import ExternalReference

scim2_models/rfc7643/service_provider_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
from pydantic import Field
66

7+
from ..annotations import Mutability
8+
from ..annotations import Required
9+
from ..annotations import Returned
10+
from ..annotations import Uniqueness
711
from ..base import ComplexAttribute
8-
from ..base import Mutability
9-
from ..base import Required
10-
from ..base import Returned
11-
from ..base import Uniqueness
1212
from ..reference import ExternalReference
1313
from ..reference import Reference
1414
from .resource import Resource

scim2_models/rfc7643/user.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
from pydantic import EmailStr
99
from pydantic import Field
1010

11-
from ..base import CaseExact
11+
from ..annotations import CaseExact
12+
from ..annotations import Mutability
13+
from ..annotations import Required
14+
from ..annotations import Returned
15+
from ..annotations import Uniqueness
1216
from ..base import ComplexAttribute
1317
from ..base import MultiValuedComplexAttribute
14-
from ..base import Mutability
15-
from ..base import Required
16-
from ..base import Returned
17-
from ..base import Uniqueness
1818
from ..reference import ExternalReference
1919
from ..reference import Reference
2020
from ..utils import Base64Bytes

tests/test_dynamic_resources.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from typing import Literal
33
from typing import Union
44

5-
from scim2_models.base import CaseExact
5+
from scim2_models.annotations import CaseExact
6+
from scim2_models.annotations import Mutability
7+
from scim2_models.annotations import Required
8+
from scim2_models.annotations import Returned
9+
from scim2_models.annotations import Uniqueness
610
from scim2_models.base import ComplexAttribute
711
from scim2_models.base import MultiValuedComplexAttribute
8-
from scim2_models.base import Mutability
9-
from scim2_models.base import Required
10-
from scim2_models.base import Returned
11-
from scim2_models.base import Uniqueness
1212
from scim2_models.reference import ExternalReference
1313
from scim2_models.reference import Reference
1414
from scim2_models.reference import URIReference

tests/test_dynamic_schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Annotated
33
from typing import Optional
44

5-
from scim2_models.base import Required
5+
from scim2_models.annotations import Required
66
from scim2_models.context import Context
77
from scim2_models.rfc7643.enterprise_user import EnterpriseUser
88
from scim2_models.rfc7643.group import Group

0 commit comments

Comments
 (0)