Skip to content

Commit

Permalink
Add JS value dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Aug 17, 2021
1 parent c743caf commit a17e3f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/ska/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta
from importlib import import_module
import json
import time
from typing import Callable, Dict, List, Tuple, Union, Optional
from urllib.parse import quote
Expand All @@ -10,13 +11,14 @@
__copyright__ = "2013-2021 Artur Barseghyan"
__license__ = "GPL 2.0/LGPL 2.1"
__all__ = (
"get_callback_func",
"default_value_dumper",
"dict_keys",
"dict_to_ordered_list",
"sorted_urlencode",
"extract_signed_data",
"get_callback_func",
"javascript_value_dumper",
"make_valid_until",
"sorted_urlencode",
)


Expand Down Expand Up @@ -92,6 +94,13 @@ def default_value_dumper(value):
return value


def javascript_value_dumper(value):
if isinstance(value, (int, float, str)):
return value
else:
return json.dumps(value, separators=(",", ":"))


def sorted_urlencode(
data: Dict[str, Union[bytes, str, float, int]],
quoted: bool = True,
Expand Down
4 changes: 3 additions & 1 deletion src/ska/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ def validate_signed_request_data(
)

validation_result = request_helper.validate_request_data(
data=data, secret_key=secret_key, value_dumper=value_dumper,
data=data,
secret_key=secret_key,
value_dumper=value_dumper,
)

return validation_result
Expand Down

0 comments on commit a17e3f6

Please sign in to comment.