def introspect_global_indexes(raw_indexes): """ Given a raw index structure back from a DynamoDB response, parse out & build the high-level Python objects that represent them. """ indexes = [] for field in raw_indexes: index_klass = GlobalAllIndex kwargs = {'parts': []} projection_type = field['Projection']['ProjectionType'] type_names = ['ALL', 'KEYS_ONLY', 'INCLUDE'] type_classes = [ GlobalAllIndex, GlobalKeysOnlyIndex, GlobalIncludeIndex ] type_name_to_class = dict(zip(type_names, type_classes)) try: index_klass = type_name_to_class[projection_type] except KeyError: raise exceptions.UnknownIndexFieldError( "%s was seen, but is unknown. Please report this at " "https://github.com/boto/boto/issues." % projection_type) if projection_type == 'INCLUDE': kwargs['includes'] = field['Projection']['NonKeyAttributes'] name = field['IndexName'] kwargs['parts'] = introspect_schema(field['KeySchema'], None) indexes.append(index_klass(name, **kwargs)) return indexes
def _introspect_indexes(self, raw_indexes): """ Given a raw index structure back from a DynamoDB response, parse out & build the high-level Python objects that represent them. """ indexes = [] for field in raw_indexes: index_klass = AllIndex kwargs = {'parts': []} if field['Projection']['ProjectionType'] == 'ALL': index_klass = AllIndex elif field['Projection']['ProjectionType'] == 'KEYS_ONLY': index_klass = KeysOnlyIndex elif field['Projection']['ProjectionType'] == 'INCLUDE': index_klass = IncludeIndex kwargs['includes'] = field['Projection']['NonKeyAttributes'] else: raise exceptions.UnknownIndexFieldError( "%s was seen, but is unknown. Please report this at " "https://github.com/boto/boto/issues." % \ field['Projection']['ProjectionType'] ) name = field['IndexName'] kwargs['parts'] = self._introspect_schema(field['KeySchema']) indexes.append(index_klass(name, **kwargs)) return indexes