def decode_union(self, data_type, obj):
val = None<EOL>if isinstance(obj, six.string_types):<EOL><INDENT>tag = obj<EOL>if data_type.definition._is_tag_present(tag, self.caller_permissions):<EOL><INDENT>val_data_type = data_type.definition._get_val_data_type(<EOL>tag, self.caller_permissions)<EOL>if not isinstance(val_data_type, (bv.Void, bv.Nullable)):<EOL><INDENT>raise bv.ValidationError(<EOL>"<STR_LIT>" % tag)<EOL><DEDENT>if tag == data_type.definition._catch_all:<EOL><INDENT>raise bv.ValidationError(<EOL>"<STR_LIT>" % tag)<EOL><DEDENT><DEDENT>elif not self.strict and data_type.definition._catch_all:<EOL><INDENT>tag = data_type.definition._catch_all<EOL><DEDENT>else:<EOL><INDENT>raise bv.ValidationError("<STR_LIT>" % tag)<EOL><DEDENT><DEDENT>elif isinstance(obj, dict):<EOL><INDENT>tag, val = self.decode_union_dict(<EOL>data_type, obj)<EOL><DEDENT>else:<EOL><INDENT>raise bv.ValidationError("<STR_LIT>" %<EOL>bv.generic_type_name(obj))<EOL><DEDENT>return data_type.definition(tag, val)<EOL>
The data_type argument must be a Union.
See json_compat_obj_decode() for argument descriptions.