def _setattr(obj, value, value_name, regex, selector):
    'Either apply setattr on `obj` with value `value`, if `value` is not None, otherwise\n    select a `value` from the available range of allowed values, selected by a custom `selector`\n    function.\n\n    Args:\n        obj: An object on which to run setattr\n        value: A value which if not None will be set as an attribute of object\n        value_name (str): The name of the new attribute\n        regex (str): regex string by which to find allowed values on the NUTS website.\n        selector (function): Function which takes an iterable and selects a value.\n    '
    allowed_values = _get_available(regex)
    if (value is None):
        value = selector(allowed_values)
    if (value not in allowed_values):
        raise ValueError(f"'{value_name}' must be one of {allowed_values}")
    setattr(obj, value_name, value)
Either apply setattr on `obj` with value `value`, if `value` is not None, otherwise
select a `value` from the available range of allowed values, selected by a custom `selector`
function.

Args:
    obj: An object on which to run setattr
    value: A value which if not None will be set as an attribute of object
    value_name (str): The name of the new attribute
    regex (str): regex string by which to find allowed values on the NUTS website.
    selector (function): Function which takes an iterable and selects a value.
def _setattr(obj, value, value_name, regex, selector):
    'Either apply setattr on `obj` with value `value`, if `value` is not None, otherwise\n    select a `value` from the available range of allowed values, selected by a custom `selector`\n    function.\n\n    Args:\n        obj: An object on which to run setattr\n        value: A value which if not None will be set as an attribute of object\n        value_name (str): The name of the new attribute\n        regex (str): regex string by which to find allowed values on the NUTS website.\n        selector (function): Function which takes an iterable and selects a value.\n    '
    allowed_values = _get_available(regex)
    if (value is None):
        value = selector(allowed_values)
    if (value not in allowed_values):
        raise ValueError(f"'{value_name}' must be one of {allowed_values}")
    setattr(obj, value_name, value)