5252
5353
5454def _utcnow () -> datetime .datetime :
55+ """Return the current time, in UTC."""
5556 return datetime .datetime .now (datetime .UTC )
5657
5758
@@ -129,11 +130,11 @@ def _cursor_page(
129130
130131
131132def _nothing () -> None :
132- pass
133+ """Check nothing, as the default uniqueness check of a flush."""
133134
134135
135136async def _nothing_async () -> None :
136- pass
137+ """Check nothing, as the default uniqueness check of a flush."""
137138
138139
139140class _StorageBase :
@@ -156,6 +157,7 @@ def __init__(
156157 mapping ._bind (self .mappings )
157158
158159 def _mapping (self , resource_type : ResourceType ) -> ResourceMapping :
160+ """Return the mapping of a resource type."""
159161 return self .mappings [resource_type .name ] # type: ignore[index]
160162
161163 def _root_page (
@@ -253,6 +255,7 @@ def _check_storable(
253255 def _not_found (
254256 resource_type : ResourceType , resource_id : str | None
255257 ) -> NotFoundException :
258+ """Return the error of a resource that does not exist."""
256259 return NotFoundException (
257260 detail = f"{ resource_type .name } { resource_id !r} not found"
258261 )
@@ -261,6 +264,7 @@ def _not_found(
261264 def _check_version (
262265 mapping : ResourceMapping , record : Any , expected_version : str | None
263266 ) -> None :
267+ """Refuse to change a record whose version is not the expected one."""
264268 if (
265269 expected_version is not None
266270 and _version (mapping , record ) != expected_version
@@ -421,6 +425,7 @@ def get(
421425 * ,
422426 response_parameters : ResponseParameters [Any ] | None = None ,
423427 ) -> Resource [Any ]:
428+ """Return a resource, with the attributes the response keeps."""
424429 record = self ._load (resource_type , resource_id , response_parameters )
425430 return self ._to_scim (resource_type , record , response_parameters )
426431
@@ -431,6 +436,7 @@ def search(
431436 * ,
432437 position : Any = None ,
433438 ) -> SearchPage :
439+ """Return a page of the resources matching a search, on one resource type or at the root."""
434440 if not resource_types :
435441 return SearchPage (0 , [])
436442 session = self .session ()
@@ -464,6 +470,7 @@ def search(
464470 def create (
465471 self , resource_type : ResourceType , resource : Resource [Any ]
466472 ) -> Resource [Any ]:
473+ """Store a new resource, and return it as stored."""
467474 mapping = self ._mapping (resource_type )
468475 self ._check_storable (resource_type , resource , None )
469476 self ._check_uniqueness (mapping , resource )
@@ -484,6 +491,7 @@ def update(
484491 * ,
485492 expected_version : str | None = None ,
486493 ) -> Resource [Any ]:
494+ """Replace a resource, and return it as stored."""
487495 mapping = self ._mapping (resource_type )
488496 record = self ._load (resource_type , resource .id )
489497 self ._check_version (mapping , record , expected_version )
@@ -503,6 +511,7 @@ def delete(
503511 * ,
504512 expected_version : str | None = None ,
505513 ) -> None :
514+ """Delete a resource."""
506515 mapping = self ._mapping (resource_type )
507516 record = self ._load (resource_type , resource_id )
508517 self ._check_version (mapping , record , expected_version )
@@ -526,6 +535,7 @@ def _load(
526535 def _check_uniqueness (
527536 self , mapping : ResourceMapping , resource : Resource [Any ]
528537 ) -> None :
538+ """Refuse a resource with a unique value another resource already has."""
529539 session = self .session ()
530540 comparator = self ._ready_comparator (session )
531541 for statement in self ._unique_statements (mapping , resource , comparator ):
@@ -542,6 +552,7 @@ def _ready_comparator(self, session: Session) -> _Comparator:
542552 def _links (
543553 self , mapping : ResourceMapping , resource : Resource [Any ]
544554 ) -> dict [_Collection , list [Any ]]:
555+ """Return the records each Link of a resource links to, refusing a value that links to nothing."""
545556 links : dict [_Collection , list [Any ]] = {}
546557 for collections , entries in _link_entries (mapping , resource ):
547558 ids = [entry .value for entry in entries ]
@@ -620,6 +631,7 @@ async def get(
620631 * ,
621632 response_parameters : ResponseParameters [Any ] | None = None ,
622633 ) -> Resource [Any ]:
634+ """Return a resource, with the attributes the response keeps."""
623635 record = await self ._load (resource_type , resource_id , response_parameters )
624636 return self ._to_scim (resource_type , record , response_parameters )
625637
@@ -630,6 +642,7 @@ async def search(
630642 * ,
631643 position : Any = None ,
632644 ) -> SearchPage :
645+ """Return a page of the resources matching a search, on one resource type or at the root."""
633646 if not resource_types :
634647 return SearchPage (0 , [])
635648 session = self .session ()
@@ -663,6 +676,7 @@ async def search(
663676 async def create (
664677 self , resource_type : ResourceType , resource : Resource [Any ]
665678 ) -> Resource [Any ]:
679+ """Store a new resource, and return it as stored."""
666680 mapping = self ._mapping (resource_type )
667681 self ._check_storable (resource_type , resource , None )
668682 await self ._check_uniqueness (mapping , resource )
@@ -683,6 +697,7 @@ async def update(
683697 * ,
684698 expected_version : str | None = None ,
685699 ) -> Resource [Any ]:
700+ """Replace a resource, and return it as stored."""
686701 mapping = self ._mapping (resource_type )
687702 record = await self ._load (resource_type , resource .id )
688703 self ._check_version (mapping , record , expected_version )
@@ -703,6 +718,7 @@ async def delete(
703718 * ,
704719 expected_version : str | None = None ,
705720 ) -> None :
721+ """Delete a resource."""
706722 mapping = self ._mapping (resource_type )
707723 record = await self ._load (resource_type , resource_id )
708724 self ._check_version (mapping , record , expected_version )
@@ -730,6 +746,7 @@ async def _load(
730746 async def _check_uniqueness (
731747 self , mapping : ResourceMapping , resource : Resource [Any ]
732748 ) -> None :
749+ """Refuse a resource with a unique value another resource already has."""
733750 session = self .session ()
734751 comparator = await self ._ready_comparator (session )
735752 for statement in self ._unique_statements (mapping , resource , comparator ):
@@ -747,6 +764,7 @@ async def _ready_comparator(self, session: AsyncSession) -> _Comparator:
747764 async def _links (
748765 self , mapping : ResourceMapping , resource : Resource [Any ]
749766 ) -> dict [_Collection , list [Any ]]:
767+ """Return the records each Link of a resource links to, refusing a value that links to nothing."""
750768 links : dict [_Collection , list [Any ]] = {}
751769 for collections , entries in _link_entries (mapping , resource ):
752770 ids = [entry .value for entry in entries ]
0 commit comments