diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-01-17 20:31:42 -0600 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-01-17 20:31:42 -0600 |
| commit | 0174602093dcb097e23f6493bfd4f5d1a9fe2e3c (patch) | |
| tree | ced5d54e2cb5e80008adc39cf0f9fdb2c53eadc8 /config_file/utils.py | |
| parent | Fix bug with isinstance use in config file (diff) | |
| download | config-file-0174602093dcb097e23f6493bfd4f5d1a9fe2e3c.zip | |
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
Diffstat (limited to 'config_file/utils.py')
| -rw-r--r-- | config_file/utils.py | 16 |
1 files changed, 16 insertions, 0 deletions
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(".") |