mirror of
https://github.com/qurator-spk/dinglehopper.git
synced 2025-06-09 11:50:00 +02:00
✨ dinglehopper: Validate ExtractedText.{segments,_text} in both directions
This commit is contained in:
parent
1f9a680fe7
commit
f3aafb6fdf
1 changed files with 2 additions and 1 deletions
|
@ -41,7 +41,6 @@ class ExtractedText:
|
||||||
# An object contains either
|
# An object contains either
|
||||||
# a. _text itself
|
# a. _text itself
|
||||||
# b. or segments (ExtractedText) and a joiner
|
# b. or segments (ExtractedText) and a joiner
|
||||||
# TODO validator
|
|
||||||
|
|
||||||
segments = attr.ib(type=Optional[list], converter=attr.converters.optional(list))
|
segments = attr.ib(type=Optional[list], converter=attr.converters.optional(list))
|
||||||
joiner = attr.ib(type=Optional[str])
|
joiner = attr.ib(type=Optional[str])
|
||||||
|
@ -54,6 +53,8 @@ class ExtractedText:
|
||||||
|
|
||||||
@_text.validator
|
@_text.validator
|
||||||
def check(self, _, value):
|
def check(self, _, value):
|
||||||
|
if value is not None and self.segments is not None:
|
||||||
|
raise ValueError("Can't have both segments and text")
|
||||||
if value is not None and unicodedata.normalize('NFC', value) != value:
|
if value is not None and unicodedata.normalize('NFC', value) != value:
|
||||||
raise ValueError('String "{}" is not in NFC.'.format(value))
|
raise ValueError('String "{}" is not in NFC.'.format(value))
|
||||||
if value is not None and normalize(value, self.normalization) != value:
|
if value is not None and normalize(value, self.normalization) != value:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue