# backport of broken code for python 3.11 on webhelpers2
import collections
from webhelpers2.misc import NotGiven
from webhelpers2.html.tags import _set_id_attr, NL, _OptionsList, OptGroup, HTML
class Options(_OptionsList):
"""A list of options and/or optgroups for a select or datalist.
I'm a subclass of ``list``. My elements are ``Option`` and/or ``OptGroup``
instances. Do not add other element types or they may cause
``options.render`` or ``str(options)`` to fail.
"""
def __init__(self, options=None, prompt=None):
"""Construct an ``Options`` instance.
**options**: An iterable of ``Option`` instances, ``OptGroup``
instances and/or strings. If you pass strings, they will be converted
to simple ``Option`` instances (i.e., the label will be the string, and
the value will be ``None``).
**prompt**: If passed, this will be turned into an extra option before
the others. The string argument will become the option's label, and
the option's value will be the empty string.
"""
if prompt:
self.add_option(prompt, "")
if options:
self._parse_options(options)
def __repr__(self):
classname = self.__class__.__name__
return "{0}({1!r})".format(classname, list(self))
def add_optgroup(self, label, options=None):
"""Create an ``OptGroup``, append it, and return it.
The return value is the ``OptGroup`` instance. Call its
``.add_option`` method to add options to the group.
"""
group = OptGroup(label, options)
self.append(group)
return group
def render(self, selected_values=None):
"""
Render the options as a concatenated literal of