Skip to content

Commit

Permalink
fix(boolean-values): allow 0 and 1 as boolean values (DEV-251) (#131)
Browse files Browse the repository at this point in the history
* allow 0 and 1 as boolean values

* add documentation

* remove complexity

* use f-string for error message
  • Loading branch information
irinaschubert committed Dec 2, 2021
1 parent 6a40fc6 commit fd58ad4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/dsp-tools-xmlupload.md
Expand Up @@ -696,7 +696,7 @@ Attributes:

#### `<boolean>`

The `<boolean>` element must contain the string "true" or "false", or the numeral 1 or 0.
The `<boolean>` element must contain the string "true" or "false", or the numeral 1 (true) or 0 (false).

Attributes:

Expand Down
13 changes: 6 additions & 7 deletions knora/dsplib/models/value.py
Expand Up @@ -601,18 +601,17 @@ def __init__(self,
iri: Optional[str] = None,
ark_url: Optional[str] = None,
vark_url: Optional[str] = None):

if type(value) is bool:
self._value = value

elif type(value) is str:
if value.upper() == 'TRUE':
else:
if value == 1 or value.upper() == 'TRUE' or value == '1':
self._value = True
elif value.upper() == 'FALSE':
elif value == 0 or value.upper() == 'FALSE' or value == '0':
self._value = False
else:
raise BaseError("Invalid boolean format! " + str(value))
elif type(value) is int:
self._value = False if value == 0 else True
raise BaseError(f"ERROR Invalid boolean format {value}!")

super().__init__(iri=iri,
comment=comment,
permissions=permissions,
Expand Down

0 comments on commit fd58ad4

Please sign in to comment.