MCPcopy Create free account
hub / github.com/ceph/ceph / validate

Function validate

src/pybind/ceph_argparse.py:1132–1321  ·  view source on GitHub ↗

validate(args, signature, flags=0, partial=False) args is a list of strings representing a possible command input following format of signature. Runs a validation; no exception means it's OK. Return a dict containing all arguments keyed by their descriptor name, with duplicat

(args: List[str],
             signature: Sequence[argdesc],
             flags: int = 0,
             partial: Optional[bool] = False)

Source from the content-addressed store, hash-verified

1130
1131
1132def validate(args: List[str],
1133 signature: Sequence[argdesc],
1134 flags: int = 0,
1135 partial: Optional[bool] = False) -> ValidatedArgs:
1136 """
1137 validate(args, signature, flags=0, partial=False)
1138
1139 args is a list of strings representing a possible
1140 command input following format of signature. Runs a validation; no
1141 exception means it's OK. Return a dict containing all arguments keyed
1142 by their descriptor name, with duplicate args per name accumulated
1143 into a list (or space-separated value for CephPrefix).
1144
1145 Mismatches of prefix are non-fatal, as this probably just means the
1146 search hasn't hit the correct command. Mismatches of non-prefix
1147 arguments are treated as fatal, and an exception raised.
1148
1149 This matching is modified if partial is set: allow partial matching
1150 (with partial dict returned); in this case, there are no exceptions
1151 raised.
1152 """
1153
1154 myargs = copy.deepcopy(args)
1155 mysig = copy.deepcopy(signature)
1156 reqsiglen = len([desc for desc in mysig if desc.req])
1157 matchcnt = 0
1158 d: ValidatedArgs = dict()
1159 save_exception = None
1160
1161 arg_descs_by_name: Dict[str, argdesc] = \
1162 dict((desc.name, desc) for desc in mysig if desc.t != CephPrefix)
1163
1164 # Special case: detect "injectargs" (legacy way of modifying daemon
1165 # configs) and permit "--" string arguments if so.
1166 injectargs = myargs and myargs[0] == "injectargs"
1167
1168 # Make a pass through all arguments
1169 for desc in mysig:
1170 desc.numseen = 0
1171
1172 while desc.numseen < desc.n:
1173 if myargs:
1174 myarg: Optional[str] = myargs.pop(0)
1175 else:
1176 myarg = None
1177
1178 # no arg, but not required? Continue consuming mysig
1179 # in case there are later required args
1180 if myarg in (None, []):
1181 if not desc.req:
1182 break
1183 # did we already get this argument (as a named arg, earlier?)
1184 if desc.name in d:
1185 break
1186
1187 # A keyword argument?
1188 if myarg:
1189 # argdesc for the keyword argument, if we find one

Callers 6

_arg_kwarg_testMethod · 0.90
validate_commandFunction · 0.70
find_cmd_targetFunction · 0.70
test_schemaFunction · 0.50
test_create_formMethod · 0.50

Calls 15

validate_oneFunction · 0.85
store_argFunction · 0.85
ArgumentValidClass · 0.85
ArgumentNumberClass · 0.85
ArgumentMissingClass · 0.85
ArgumentTooFewClass · 0.85
printFunction · 0.85
ArgumentErrorClass · 0.70
popMethod · 0.45
matchMethod · 0.45
groupsMethod · 0.45
replaceMethod · 0.45

Tested by 3

_arg_kwarg_testMethod · 0.72
test_schemaFunction · 0.40
test_create_formMethod · 0.40