def _parse_global_index(self, clause, attrs):
index_type, name = clause[:<NUM_LIT:2>]<EOL>name = resolve(name)<EOL>def get_key(field, data_type=None):<EOL><INDENT>"""<STR_LIT>"""<EOL>if field in attrs:<EOL><INDENT>key = attrs[field]<EOL>if data_type is not None:<EOL><INDENT>if TYPES[data_type] != key.data_type:<EOL><INDENT>raise SyntaxError(<EOL>"<STR_LIT>" % field,<EOL>data_type,<EOL>key.data_type,<EOL>)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if data_type is None:<EOL><INDENT>raise SyntaxError("<STR_LIT>" % field)<EOL><DEDENT>key = DynamoKey(field, data_type=TYPES[data_type])<EOL>attrs[field] = key<EOL><DEDENT>return key<EOL><DEDENT>g_hash_key = get_key(*clause.hash_key)<EOL>g_range_key = None<EOL>tp_index = <NUM_LIT:3><EOL>if clause.range_key:<EOL><INDENT>tp_index += <NUM_LIT:1><EOL>g_range_key = get_key(*clause.range_key)<EOL><DEDENT>if clause.include_vars:<EOL><INDENT>tp_index += <NUM_LIT:1><EOL><DEDENT>kwargs = {}<EOL>if tp_index < len(clause):<EOL><INDENT>throughput = clause[tp_index]<EOL>kwargs["<STR_LIT>"] = Throughput(*map(resolve, throughput))<EOL><DEDENT>index_type = clause.index_type[<NUM_LIT:0>]<EOL>if index_type in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>factory = GlobalIndex.all<EOL><DEDENT>elif index_type == "<STR_LIT>":<EOL><INDENT>factory = GlobalIndex.keys<EOL><DEDENT>elif index_type == "<STR_LIT>":<EOL><INDENT>factory = GlobalIndex.include<EOL>if not clause.include_vars:<EOL><INDENT>raise SyntaxError("<STR_LIT>" % name)<EOL><DEDENT>kwargs["<STR_LIT>"] = [resolve(v) for v in clause.include_vars]<EOL><DEDENT>return factory(name, g_hash_key, g_range_key, **kwargs)<EOL>
Parse a global index clause and return a GlobalIndex