-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #607 from lindsay-stevens/pyxform-605
fix: survey json->xml round trip not working for some question types
- Loading branch information
Showing
8 changed files
with
117 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Any, Dict, Sequence | ||
|
||
from pyxform.errors import PyXFormError | ||
|
||
PARAMETERS_TYPE = Dict[str, Any] | ||
|
||
|
||
def parse(raw_parameters: str) -> PARAMETERS_TYPE: | ||
parts = raw_parameters.split(";") | ||
if len(parts) == 1: | ||
parts = raw_parameters.split(",") | ||
if len(parts) == 1: | ||
parts = raw_parameters.split() | ||
|
||
params = {} | ||
for param in parts: | ||
if "=" not in param: | ||
raise PyXFormError( | ||
"Expecting parameters to be in the form of " | ||
"'parameter1=value parameter2=value'." | ||
) | ||
k, v = param.split("=")[:2] | ||
key = k.lower().strip() | ||
params[key] = v.lower().strip() | ||
|
||
return params | ||
|
||
|
||
def validate( | ||
parameters: PARAMETERS_TYPE, | ||
allowed: Sequence[str], | ||
) -> Dict[str, str]: | ||
""" | ||
Raise an error if 'parameters' includes any keys not named in 'allowed'. | ||
""" | ||
extras = set(parameters.keys()) - (set(allowed)) | ||
if 0 < len(extras): | ||
msg = ( | ||
"Accepted parameters are '{a}'. " | ||
"The following are invalid parameter(s): '{e}'." | ||
).format(a=", ".join(sorted(allowed)), e=", ".join(sorted(extras))) | ||
raise PyXFormError(msg) | ||
return parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters