From 0174602093dcb097e23f6493bfd4f5d1a9fe2e3c Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Fri, 17 Jan 2020 20:31:42 -0600 Subject: Remove _split_on_dot from base parser and add it to utils Also, change the default behavior to split on every dot and split on only the last dot if specified --- config_file/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 config_file/utils.py (limited to 'config_file/utils.py') diff --git a/config_file/utils.py b/config_file/utils.py new file mode 100644 index 0000000..41ce2a5 --- /dev/null +++ b/config_file/utils.py @@ -0,0 +1,16 @@ +def split_on_dot(line: str, only_last_dot=False): + """ + Split a string on the dot character (.). + + :param line: The line ot split on. + :param only_last_dot: Only split on the last occurrence of the dot. + + :raises ValueError: if the line does not have a dot. + """ + if "." not in line: + raise ValueError( + "section_key must contain the section and key separated by a dot. " + + "e.g. 'section.key'" + ) + + return line.rsplit(".", 1) if only_last_dot else line.split(".") -- cgit v1.2.3