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

Method _get_value

pyquery/pyquery.py:1004–1034  ·  view source on GitHub ↗
(tag)

Source from the content-addressed store, hash-verified

1002
1003 """
1004 def _get_value(tag):
1005 # <textarea>
1006 if tag.tag == 'textarea':
1007 return self._copy(tag).html()
1008 # <select>
1009 elif tag.tag == 'select':
1010 if 'multiple' in tag.attrib:
1011 # Only extract value if selected
1012 selected = self._copy(tag)('option[selected]')
1013 # Rebuild list to avoid serialization error
1014 return list(selected.map(
1015 lambda _, o: self._copy(o).attr('value')
1016 ))
1017 selected_option = self._copy(tag)('option[selected]:last')
1018 if selected_option:
1019 return selected_option.attr('value')
1020 else:
1021 return self._copy(tag)('option').attr('value')
1022 # <input type="checkbox"> or <input type="radio">
1023 elif self.is_(':checkbox,:radio'):
1024 val = self._copy(tag).attr('value')
1025 if val is None:
1026 return 'on'
1027 else:
1028 return val
1029 # <input>
1030 elif tag.tag == 'input':
1031 val = self._copy(tag).attr('value')
1032 return val.replace('\n', '') if val else ''
1033 # everything else.
1034 return self._copy(tag).attr('value') or ''
1035
1036 def _set_value(pq, value):
1037 for tag in pq:

Callers

nothing calls this directly

Calls 5

_copyMethod · 0.95
is_Method · 0.95
htmlMethod · 0.80
mapMethod · 0.80
attrMethod · 0.80

Tested by

no test coverage detected