Skip to content

Commit e5ef95b

Browse files
committed
Docstring explaining the argtree.add_path function
1 parent a17f233 commit e5ef95b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/saml2/argtree.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,34 @@ def set_arg(cls, arg, value):
5353

5454
def add_path(tdict, path):
5555
"""
56+
Create or extend an argument tree `tdict` from `path`.
5657
5758
:param tdict: a dictionary representing a argument tree
5859
:param path: a path list
5960
:return: a dictionary
61+
62+
Convert a list of items in a 'path' into a nested dict, where the
63+
second to last item becomes the key for the final item. The remaining
64+
items in the path become keys in the nested dict around that final pair
65+
of items.
66+
67+
For example, for input values of:
68+
tdict={}
69+
path = ['assertion', 'subject', 'subject_confirmation',
70+
'method', 'urn:oasis:names:tc:SAML:2.0:cm:bearer']
71+
72+
Returns an output value of:
73+
{'assertion': {'subject': {'subject_confirmation':
74+
{'method': 'urn:oasis:names:tc:SAML:2.0:cm:bearer'}}}}
75+
76+
Another example, this time with a non-empty tdict input:
77+
78+
tdict={'method': 'urn:oasis:names:tc:SAML:2.0:cm:bearer'},
79+
path=['subject_confirmation_data', 'in_response_to', '_012345']
80+
81+
Returns an output value of:
82+
{'subject_confirmation_data': {'in_response_to': '_012345'},
83+
'method': 'urn:oasis:names:tc:SAML:2.0:cm:bearer'}
6084
"""
6185
t = tdict
6286
for step in path[:-2]:

0 commit comments

Comments
 (0)