Skip to content

Commit

Permalink
adding from_dict liveness
Browse files Browse the repository at this point in the history
  • Loading branch information
alexviquez committed Feb 5, 2024
1 parent ffca913 commit 458a69b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mati/resources/verifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class Verification(Resource):
def __post_init__(self):
docs = []
self.steps = [
Liveness(**step) for step in self.steps if step['id'] == 'liveness'
Liveness._from_dict(step)
for step in self.steps
if step['id'] == 'liveness'
]
for doc in self.documents:
doc['steps'] = [
Expand Down
11 changes: 11 additions & 0 deletions mati/types/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ class Liveness:
data: Optional[LivenessMedia] = None
error: Optional[Dict] = None

@classmethod
def _filter_excess_fields(cls, obj_dict: Dict) -> None:
excess = set(obj_dict.keys()) - {f.name for f in fields(cls)}
for f in excess:
del obj_dict[f]

@classmethod
def _from_dict(cls, obj_dict: Dict[str, Any]) -> 'Liveness':
cls._filter_excess_fields(obj_dict)
return cls(**obj_dict)


@dataclass
class DocumentScore:
Expand Down
2 changes: 1 addition & 1 deletion mati/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.5'
__version__ = '2.0.6.dev0'

0 comments on commit 458a69b

Please sign in to comment.