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

Method _format_disabled_xpath

pyquery/cssselectpatch.py:131–149  ·  view source on GitHub ↗

Format XPath condition for :disabled or :enabled pseudo-classes according to the WHATWG spec. See: https://html.spec.whatwg.org /multipage/semantics-other.html#concept-element-disabled

(self, disabled=True)

Source from the content-addressed store, hash-verified

129 return xpath
130
131 def _format_disabled_xpath(self, disabled=True):
132 """Format XPath condition for :disabled or :enabled pseudo-classes
133 according to the WHATWG spec. See: https://html.spec.whatwg.org
134 /multipage/semantics-other.html#concept-element-disabled
135 """
136 bool_op = '' if disabled else 'not'
137 return '''(
138 ((name(.) = 'button' or name(.) = 'input' or name(.) = 'select'
139 or name(.) = 'textarea' or name(.) = 'fieldset')
140 and %s(@disabled or (ancestor::fieldset[@disabled]
141 and not(ancestor::legend[not(preceding-sibling::legend)])))
142 )
143 or
144 ((name(.) = 'option'
145 and %s(@disabled or ancestor::optgroup[@disabled]))
146 )
147 or
148 ((name(.) = 'optgroup' and %s(@disabled)))
149 )''' % (bool_op, bool_op, bool_op)
150
151 def xpath_disabled_pseudo(self, xpath):
152 """Matches all elements that are disabled::

Callers 2

xpath_disabled_pseudoMethod · 0.95
xpath_enabled_pseudoMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected