def country(from_key='<STR_LIT:name>', to_key='<STR_LIT>'):
gc = GeonamesCache()<EOL>dataset = gc.get_dataset_by_key(gc.get_countries(), from_key)<EOL>def mapper(input):<EOL><INDENT>if '<STR_LIT:name>' == from_key:<EOL><INDENT>input = mappings.country_names.get(input, input)<EOL><DEDENT>item = dataset.get(input)<EOL>if item:<EOL><INDENT>return item[to_key]<EOL><DEDENT><DEDENT>return mapper<EOL>
Creates and returns a mapper function to access country data.

    The mapper function that is returned must be called with one argument. In
    the default case you call it with a name and it returns a 3-letter
    ISO_3166-1 code, e. g. called with ``Spain`` it would return ``ESP``.

    :param from_key: (optional) the country attribute you give as input.
        Defaults to ``name``.
    :param to_key: (optional) the country attribute you want as output.
        Defaults to ``iso``.
    :return: mapper
    :rtype: function