1# Copyright 2014 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5MERGE_FAILURE_REASON = ( 6 'Merging values containing a None value results in a None value.') 7 8class NoneValueMissingReason(Exception): 9 pass 10 11class ValueMustHaveNoneValue(Exception): 12 pass 13 14def ValidateNoneValueReason(value, none_value_reason): 15 """Ensures that the none_value_reason is appropriate for the given value. 16 17 There is a logical equality between having a value of None and having a 18 reason for being None. That is to say, value is None if and only if 19 none_value_reason is a string. 20 """ 21 if value is None and not isinstance(none_value_reason, basestring): 22 raise NoneValueMissingReason() 23 if value is not None and none_value_reason is not None: 24 raise ValueMustHaveNoneValue() 25