Skip to content

Commit 3498c94

Browse files
committed
Deprecated public sort_params
1 parent 1571323 commit 3498c94

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

laterpay/signing.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import hashlib
55
import hmac
6+
import warnings
67

78
import six
89
from six.moves.urllib.parse import quote, urlparse
@@ -51,6 +52,23 @@ def sort_params(param_dict):
5152
5253
This function should probably not be part of the public API, and thus will
5354
be deprecated in a future release to be replaced with a internal function.
55+
56+
.. deprecated:: 5.0.0
57+
58+
Use :func:`laterpay.signing.normalise_param_structure` instead.
59+
"""
60+
warnings.warn(
61+
'laterpay.signing.sort_params is deprecated and will be removed in '
62+
'future versions. Use laterpay.signing.normalise_param_structure '
63+
'instead.',
64+
DeprecationWarning
65+
)
66+
return _sort_params(param_dict)
67+
68+
69+
def _sort_params(param_dict):
70+
"""
71+
Sort a key-value mapping with non-unique keys.
5472
"""
5573
param_list = []
5674
for name, value_list in six.iteritems(param_dict):

tests/test_signing.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import hashlib
66
import unittest
7+
import warnings
78

89
import furl
910

@@ -239,14 +240,24 @@ def test_sort_params(self):
239240
'key2': ['value22', 'value21'],
240241
'key3': ('value32', 'value31'),
241242
}
242-
self.assertEqual(signing.sort_params(params), [
243+
self.assertEqual(signing._sort_params(params), [
243244
('key1', 'value1'),
244245
('key2', 'value21'),
245246
('key2', 'value22'),
246247
('key3', 'value31'),
247248
('key3', 'value32'),
248249
])
249250

251+
def test_sort_params_public_deprecation(self):
252+
with warnings.catch_warnings(record=True) as w:
253+
warnings.simplefilter("always")
254+
signing.sort_params({})
255+
self.assertEqual(
256+
w[0].message.args[0],
257+
'laterpay.signing.sort_params is deprecated and will be removed in future '
258+
'versions. Use laterpay.signing.normalise_param_structure instead.'
259+
)
260+
250261

251262
if __name__ == '__main__':
252263
unittest.main()

0 commit comments

Comments
 (0)