@@ -568,6 +568,30 @@ def _produce_instance(self, response):
568568 new_instance ._activate_URI (new_instance .selfLink )
569569 return new_instance
570570
571+ def _reduce_boolean_pair (self , config_dict , key1 , key2 ):
572+ '''Ensure only one key with a boolean value is present in dict.
573+
574+ :param config_dict: dict -- dictionary of config or kwargs
575+ :param key1: string -- first key name
576+ :param key2: string -- second key name
577+ :raises: BooleansToReduceHaveSameValue
578+ '''
579+
580+ if key1 in config_dict and key2 in config_dict \
581+ and config_dict [key1 ] == config_dict [key2 ]:
582+ msg = 'Boolean pair, %s and %s, have same value: %s. If both ' \
583+ 'are given to this method, they cannot be the same, as this ' \
584+ 'method cannot decide which one should be True.' \
585+ % (key1 , key2 , config_dict [key1 ])
586+ raise BooleansToReduceHaveSameValue (msg )
587+ elif key1 in config_dict and not config_dict [key1 ]:
588+ config_dict [key2 ] = True
589+ config_dict .pop (key1 )
590+ elif key2 in config_dict and not config_dict [key2 ]:
591+ config_dict [key1 ] = True
592+ config_dict .pop (key2 )
593+ return config_dict
594+
571595
572596class OrganizingCollection (ResourceBase ):
573597 """Base class for objects that collect resources under them.
@@ -762,30 +786,6 @@ def _activate_URI(self, selfLinkuri):
762786 'creation_uri_frag' : frag ,
763787 'allowed_lazy_attributes' : attrs })
764788
765- def _reduce_boolean_pair (self , config_dict , key1 , key2 ):
766- '''Ensure only one key with a boolean value is present in dict.
767-
768- :param config_dict: dict -- dictionary of config or kwargs
769- :param key1: string -- first key name
770- :param key2: string -- second key name
771- :raises: BooleansToReduceHaveSameValue
772- '''
773-
774- if key1 in config_dict and key2 in config_dict \
775- and config_dict [key1 ] == config_dict [key2 ]:
776- msg = 'Boolean pair, %s and %s, have same value: %s. If both ' \
777- 'are given to this method, they cannot be the same, as this ' \
778- 'method cannot decide which one should be True.' \
779- % (key1 , key2 , config_dict [key1 ])
780- raise BooleansToReduceHaveSameValue (msg )
781- elif key1 in config_dict and not config_dict [key1 ]:
782- config_dict [key2 ] = True
783- config_dict .pop (key1 )
784- elif key2 in config_dict and not config_dict [key2 ]:
785- config_dict [key1 ] = True
786- config_dict .pop (key2 )
787- return config_dict
788-
789789 def _create (self , ** kwargs ):
790790 """wrapped by `create` override that in subclasses to customize"""
791791 if 'uri' in self ._meta_data :
0 commit comments