Split a locale specifier.  The general format is

    language[_territory][.codeset][@modifier] [charmap]

    For example:

    ca_ES.UTF-8@valencia UTF-8

def split_locale(loc):
    '''
    Split a locale specifier.  The general format is

    language[_territory][.codeset][@modifier] [charmap]

    For example:

    ca_ES.UTF-8@valencia UTF-8
    '''
    def split(st, char):
        '''
        Split a string `st` once by `char`; always return a two-element list
        even if the second element is empty.
        '''
        split_st = st.split(char, 1)
        if len(split_st) == 1:
            split_st.append('')
        return split_st

    comps = {}
    work_st, comps['charmap'] = split(loc, ' ')
    work_st, comps['modifier'] = split(work_st, '@')
    work_st, comps['codeset'] = split(work_st, '.')
    comps['language'], comps['territory'] = split(work_st, '_')
    return comps