MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / parse_int_field

Function parse_int_field

main.py:110–127  ·  view source on GitHub ↗
(
    data: dict,
    key: str,
    default: int,
    label: str,
    min_value: int = 0,
    max_value: int | None = None,
)

Source from the content-addressed store, hash-verified

108
109
110def parse_int_field(
111 data: dict,
112 key: str,
113 default: int,
114 label: str,
115 min_value: int = 0,
116 max_value: int | None = None,
117) -> int:
118 raw_value = get_form_value(data, key, str(default)).strip()
119 try:
120 value = int(raw_value)
121 except ValueError:
122 raise ValueError(f"{label} 必须是整数")
123 if value < min_value:
124 raise ValueError(f"{label} 不能小于 {min_value}")
125 if max_value is not None and value > max_value:
126 raise ValueError(f"{label} 不能大于 {max_value}")
127 return value
128
129
130def parse_allowed_file_types(value: str) -> list[str]:

Callers 1

parse_setup_optionsFunction · 0.85

Calls 1

get_form_valueFunction · 0.85

Tested by

no test coverage detected