MCPcopy Create free account
hub / github.com/gawel/pyquery / _set_value

Method _set_value

pyquery/pyquery.py:1036–1062  ·  view source on GitHub ↗
(pq, value)

Source from the content-addressed store, hash-verified

1034 return self._copy(tag).attr('value') or ''
1035
1036 def _set_value(pq, value):
1037 for tag in pq:
1038 # <select>
1039 if tag.tag == 'select':
1040 if not isinstance(value, list):
1041 value = [value]
1042
1043 def _make_option_selected(_, elem):
1044 pq = self._copy(elem)
1045 if pq.attr('value') in value:
1046 pq.attr('selected', 'selected')
1047 if 'multiple' not in tag.attrib:
1048 del value[:] # Ensure it toggles first match
1049 else:
1050 pq.removeAttr('selected')
1051
1052 self._copy(tag)('option').each(_make_option_selected)
1053 continue
1054 # Stringify array
1055 if isinstance(value, list):
1056 value = ','.join(value)
1057 # <textarea>
1058 if tag.tag == 'textarea':
1059 self._copy(tag).text(value)
1060 continue
1061 # <input> and everything else.
1062 self._copy(tag).attr('value', value)
1063
1064 if value is no_default:
1065 if len(self):

Callers

nothing calls this directly

Calls 5

_copyMethod · 0.95
eachMethod · 0.80
joinMethod · 0.80
textMethod · 0.80
attrMethod · 0.80

Tested by

no test coverage detected