mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 02:24:27 +05:00
fix: update SimpleConfigParser submodule (#510)
This commit is contained in:
@@ -85,10 +85,46 @@ class DuplicateOptionError(Exception):
|
||||
class SimpleConfigParser:
|
||||
"""A customized config parser targeted at handling Klipper style config files"""
|
||||
|
||||
_SECTION_RE = re.compile(r"\s*\[(\w+\s?.+)]\s*([#;].*)?$")
|
||||
_OPTION_RE = re.compile(r"^\s*(\w+)\s*[:=]\s*([^=:].*)\s*([#;].*)?$")
|
||||
_MLOPTION_RE = re.compile(r"^\s*(\w+)\s*[:=]\s*([#;].*)?$")
|
||||
# definition of section line:
|
||||
# - then line MUST start with an opening square bracket - it is the first section marker
|
||||
# - the section marker MUST be followed by at least one character - it is the section name
|
||||
# - the section name MUST be followed by a closing square bracket - it is the second section marker
|
||||
# - the second section marker MAY be followed by any amount of whitespace characters
|
||||
# - the second section marker MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
_SECTION_RE = re.compile(r"\[(.+)]\s*([#;].*)?$")
|
||||
|
||||
# definition of option line:
|
||||
# - the line MUST start with a word - it is the option name
|
||||
# - the option name MUST be followed by a colon or an equal sign - it is the separator
|
||||
# - the separator MUST be followed by a value
|
||||
# - the separator MAY have any amount of leading or trailing whitespaces
|
||||
# - the separator MUST NOT be directly followed by a colon or equal sign
|
||||
# - the value MAY be of any length and character
|
||||
# - the value MAY contain any amount of trailing whitespaces
|
||||
# - the value MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
_OPTION_RE = re.compile(r"^([^:=\s]+)\s?[:=]\s*([^=:].*)\s*([#;].*)?$")
|
||||
|
||||
# definition of multiline option line:
|
||||
# - the line MUST start with a word - it is the option name
|
||||
# - the option name MUST be followed by a colon or an equal sign - it is the separator
|
||||
# - the separator MUST NOT be followed by a value
|
||||
# - the separator MAY have any amount of leading or trailing whitespaces
|
||||
# - the separator MUST NOT be directly followed by a colon or equal sign
|
||||
# - the separator MAY be followed by a # or ; - it is the comment marker
|
||||
# - the inline comment MAY be of any length and character
|
||||
_MLOPTION_RE = re.compile(r"^([^:=\s]+)\s*[:=]\s*([#;].*)?$")
|
||||
|
||||
# definition of comment line:
|
||||
# - the line MAY start with any amount of whitespace characters
|
||||
# - the line MUST contain a # or ; - it is the comment marker
|
||||
# - the comment marker MAY be followed by any amount of whitespace characters
|
||||
# - the comment MAY be of any length and character
|
||||
_COMMENT_RE = re.compile(r"^\s*([#;].*)?$")
|
||||
|
||||
# definition of empty line:
|
||||
# - the line MUST contain only whitespace characters
|
||||
_EMPTY_LINE_RE = re.compile(r"^\s*$")
|
||||
|
||||
BOOLEAN_STATES = {
|
||||
|
||||
@@ -21,4 +21,8 @@ testcases = [
|
||||
"serial",
|
||||
"/dev/serial/by-id/<your-mcu-id>",
|
||||
),
|
||||
("parameter_temperature_(°C): 155", "parameter_temperature_(°C)", "155"),
|
||||
("parameter_humidity_(%_RH): 45", "parameter_humidity_(%_RH)", "45"),
|
||||
("parameter_spool_weight_(%): 10", "parameter_spool_weight_(%)", "10"),
|
||||
("path: /dev/shm/drying_box.json", "path", "/dev/shm/drying_box.json"),
|
||||
]
|
||||
|
||||
@@ -14,7 +14,7 @@ def parser():
|
||||
return SimpleConfigParser()
|
||||
|
||||
|
||||
class TestLineParsing:
|
||||
class TestSingleLineParsing:
|
||||
@pytest.mark.parametrize("given, expected", [*case_parse_section])
|
||||
def test_parse_section(self, parser, given, expected):
|
||||
parser._parse_section(given)
|
||||
@@ -14,4 +14,14 @@ testcases = [
|
||||
("", False),
|
||||
("# that's a comment", False),
|
||||
("; that's a comment", False),
|
||||
("parameter_humidity_(%_RH):", True),
|
||||
("parameter_spool_weight_(%):", True),
|
||||
("parameter_temperature_(°C):", True),
|
||||
("parameter_humidity_(%_RH): 18.123", False),
|
||||
("parameter_spool_weight_(%): 150", False),
|
||||
("parameter_temperature_(°C): 30,5", False),
|
||||
("trusted_clients:", True),
|
||||
("trusted_clients: 192.168.1.0/24", False),
|
||||
("cors_domains:", True),
|
||||
("cors_domains: http://*.lan", False),
|
||||
]
|
||||
|
||||
@@ -26,5 +26,6 @@ testcases = [
|
||||
("description: homing!", True),
|
||||
("description: inline macro :-)", True),
|
||||
("path: %GCODES_DIR%", True),
|
||||
("path: /dev/shm/drying_box.json", True),
|
||||
("serial = /dev/serial/by-id/<your-mcu-id>", True),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user