def _gc_rule_from_pb(gc_rule_pb): """Convert a protobuf GC rule to a Python version. :type gc_rule_pb: :class:`.data_pb2.GcRule` :param gc_rule_pb: The GC rule to convert. :rtype: :class:`GarbageCollectionRule`, :class:`GarbageCollectionRuleUnion`, :class:`GarbageCollectionRuleIntersection` or :data:`NoneType <types.NoneType>` :returns: An instance of one of the native rules defined in :module:`column_family` or :data:`None` if no values were set on the protobuf passed in. :raises: :class:`ValueError <exceptions.ValueError>` if more than one property has been set on the GC rule. """ all_fields = [field.name for field in gc_rule_pb._fields] if len(all_fields) == 0: return None elif len(all_fields) > 1: raise ValueError('At most one field can be set on a GC rule.') field_name = all_fields[0] if field_name == 'max_num_versions': return GarbageCollectionRule( max_num_versions=gc_rule_pb.max_num_versions) elif field_name == 'max_age': max_age = _duration_pb_to_timedelta(gc_rule_pb.max_age) return GarbageCollectionRule(max_age=max_age) elif field_name == 'union': all_rules = gc_rule_pb.union.rules return GarbageCollectionRuleUnion( rules=[_gc_rule_from_pb(rule) for rule in all_rules]) elif field_name == 'intersection': all_rules = gc_rule_pb.intersection.rules return GarbageCollectionRuleIntersection( rules=[_gc_rule_from_pb(rule) for rule in all_rules])
def _callFUT(self, duration_pb): from gcloud_bigtable._helpers import _duration_pb_to_timedelta return _duration_pb_to_timedelta(duration_pb)