Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
xor gate in voluptuous
def xor(fields, group_name):
"""Creates an Exclusive OR (XOR) logical gate voluptuous schema.
:param fields: fields comprising the exclusive group.
:type fields: Dict[str, Schema]
:param group_name: exclusive group identifier.
:type group_name: str
:returns: XOR gated voluptuous schema.
:rtype: Schema
return vl.All(
vl.Any(*(vl.Schema({vl.Required(name): schema}, extra=vl.ALLOW_EXTRA) for name, schema in fields.iteritems())),
vl.Schema({vl.Exclusive(name, group_name): schema for name, schema in fields.iteritems()}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment