Skip to content

Commit e02b90e

Browse files
committed
refactor: remove pydantic 2.10- compatibility layer
1 parent ad97fde commit e02b90e

File tree

4 files changed

+4
-60
lines changed

4 files changed

+4
-60
lines changed

scim2_models/resources/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Union
1111
from typing import get_origin
1212

13+
from pydantic import Base64Bytes
1314
from pydantic import Field
1415
from pydantic import create_model
1516
from pydantic import field_validator
@@ -29,7 +30,6 @@
2930
from ..reference import ExternalReference
3031
from ..reference import Reference
3132
from ..reference import URIReference
32-
from ..utils import Base64Bytes
3333
from ..utils import _normalize_attribute_name
3434
from .resource import Resource
3535

scim2_models/resources/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import ClassVar
44
from typing import Literal
55

6+
from pydantic import Base64Bytes
67
from pydantic import EmailStr
78
from pydantic import Field
89

@@ -14,7 +15,6 @@
1415
from ..attributes import ComplexAttribute
1516
from ..reference import ExternalReference
1617
from ..reference import Reference
17-
from ..utils import Base64Bytes
1818
from .resource import AnyExtension
1919
from .resource import Resource
2020

scim2_models/utils.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import base64
21
import re
32
from typing import TYPE_CHECKING
4-
from typing import Annotated
5-
from typing import Literal
63
from typing import Union
74

8-
from pydantic import EncodedBytes
9-
from pydantic import EncoderProtocol
105
from pydantic.alias_generators import to_snake
11-
from pydantic_core import PydanticCustomError
126

137
if TYPE_CHECKING:
148
from .base import BaseModel
@@ -29,57 +23,6 @@ def _int_to_str(status: int | None) -> str | None:
2923
return None if status is None else str(status)
3024

3125

32-
# Copied from Pydantic 2.10 repository
33-
class _Base64Encoder(EncoderProtocol): # pragma: no cover
34-
"""Standard (non-URL-safe) Base64 encoder."""
35-
36-
@classmethod
37-
def decode(cls, data: bytes) -> bytes:
38-
"""Decode the data from base64 encoded bytes to original bytes data.
39-
40-
Args:
41-
data: The data to decode.
42-
43-
Returns:
44-
The decoded data.
45-
46-
"""
47-
try:
48-
return base64.b64decode(data)
49-
except ValueError as e:
50-
raise PydanticCustomError(
51-
"base64_decode", "Base64 decoding error: '{error}'", {"error": str(e)}
52-
) from e
53-
54-
@classmethod
55-
def encode(cls, value: bytes) -> bytes:
56-
"""Encode the data from bytes to a base64 encoded bytes.
57-
58-
Args:
59-
value: The data to encode.
60-
61-
Returns:
62-
The encoded data.
63-
64-
"""
65-
return base64.b64encode(value)
66-
67-
@classmethod
68-
def get_json_format(cls) -> Literal["base64"]:
69-
"""Get the JSON format for the encoded data.
70-
71-
Returns:
72-
The JSON format for the encoded data.
73-
74-
"""
75-
return "base64"
76-
77-
78-
# Compatibility with Pydantic <2.10
79-
# https://pydantic.dev/articles/pydantic-v2-10-release#use-b64decode-and-b64encode-for-base64bytes-and-base64str-types
80-
Base64Bytes = Annotated[bytes, EncodedBytes(encoder=_Base64Encoder)]
81-
82-
8326
def _to_camel(string: str) -> str:
8427
"""Transform strings to camelCase.
8528

tests/test_dynamic_resources.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import datetime
22
from typing import Literal
33

4+
from pydantic import Base64Bytes
5+
46
from scim2_models.annotations import CaseExact
57
from scim2_models.annotations import Mutability
68
from scim2_models.annotations import Required
@@ -14,7 +16,6 @@
1416
from scim2_models.resources.resource import Resource
1517
from scim2_models.resources.schema import Attribute
1618
from scim2_models.resources.schema import Schema
17-
from scim2_models.utils import Base64Bytes
1819

1920

2021
def test_make_group_model_from_schema(load_sample):

0 commit comments

Comments
 (0)