MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / set_value_by_label

Method set_value_by_label

thirdparty/clientform/clientform.py:2181–2225  ·  view source on GitHub ↗

Set the value of control by item labels. value is expected to be an iterable of strings that are substrings of the item labels that should be selected. Before substring matching is performed, the original label text is whitespace-compressed (consecutive whitespace c

(self, value)

Source from the content-addressed store, hash-verified

2179 item.selected = True
2180
2181 def set_value_by_label(self, value):
2182 """Set the value of control by item labels.
2183
2184 value is expected to be an iterable of strings that are substrings of
2185 the item labels that should be selected. Before substring matching is
2186 performed, the original label text is whitespace-compressed
2187 (consecutive whitespace characters are converted to a single space
2188 character) and leading and trailing whitespace is stripped. Ambiguous
2189 labels are accepted without complaint if the form's backwards_compat is
2190 True; otherwise, it will not complain as long as all ambiguous labels
2191 share the same item name (e.g. OPTION value).
2192
2193 """
2194 if isstringlike(value):
2195 raise TypeError(value)
2196 if not self.multiple and len(value) > 1:
2197 raise ItemCountError(
2198 "single selection list, must set sequence of "
2199 "length 0 or 1")
2200 items = []
2201 for nn in value:
2202 found = self.get_items(label=nn)
2203 if len(found) > 1:
2204 if not self._form.backwards_compat:
2205 # ambiguous labels are fine as long as item names (e.g.
2206 # OPTION values) are same
2207 opt_name = found[0].name
2208 if [o for o in found[1:] if o.name != opt_name]:
2209 raise AmbiguityError(nn)
2210 else:
2211 # OK, we'll guess :-( Assume first available item.
2212 found = found[:1]
2213 for o in found:
2214 # For the multiple-item case, we could try to be smarter,
2215 # saving them up and trying to resolve, but that's too much.
2216 if self._form.backwards_compat or o not in items:
2217 items.append(o)
2218 break
2219 else: # all of them are used
2220 raise ItemNotFoundError(nn)
2221 # now we have all the items that should be on
2222 # let's just turn everything off and then back on.
2223 self.value = []
2224 for o in items:
2225 o.selected = True
2226
2227 def get_value_by_label(self):
2228 """Return the value of the control as given by normalized labels."""

Callers

nothing calls this directly

Calls 6

get_itemsMethod · 0.95
isstringlikeFunction · 0.85
ItemCountErrorClass · 0.85
AmbiguityErrorClass · 0.85
ItemNotFoundErrorClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected