2020-02-03 17:25:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-02-06 14:18:01 +00:00
|
|
|
from benedict.core.keylists import keylists
|
2020-02-03 17:25:54 +00:00
|
|
|
from benedict.utils import type_util
|
|
|
|
|
|
|
|
|
2020-09-21 14:41:44 +00:00
|
|
|
def keypaths(d, separator='.', indexes=False):
|
2020-09-21 17:12:45 +00:00
|
|
|
separator = separator or '.'
|
|
|
|
if not type_util.is_string(separator):
|
2020-02-03 17:25:54 +00:00
|
|
|
raise ValueError('separator argument must be a (non-empty) string.')
|
2020-09-21 14:41:44 +00:00
|
|
|
kls = keylists(d, indexes=indexes)
|
2020-02-04 09:33:20 +00:00
|
|
|
kps = [separator.join(['{}'.format(key) for key in kl]) for kl in kls]
|
|
|
|
kps.sort()
|
|
|
|
return kps
|