def parse_format_specifier(specification):
    """
    Parse the given format specification and return a dictionary
    containing relevant values.

    """
    m = _parse_format_specifier_regex.match(specification)
    if m is None:
        raise ValueError(
            "Invalid format specifier: {!r}".format(specification))
    format_dict = m.groupdict('')

    # Convert zero-padding into fill and alignment.
    zeropad = format_dict.pop('zeropad')
    if zeropad:
        # If zero padding is requested, fill and align fields should be absent.
        if format_dict['align']:
            raise ValueError(
                "Invalid format specifier: {!r}".format(specification))
        # Impossible to have 'fill' without 'align'.
        assert not format_dict['fill']
        format_dict['align'] = '='
        format_dict['fill'] = '0'

    # Default alignment is right-aligned.
    if not format_dict['align']:
        format_dict['align'] = '>'

    # Default fill character is space.
    if not format_dict['fill']:
        format_dict['fill'] = ' '

    # Default sign is '-'.
    if not format_dict['sign']:
        format_dict['sign'] = '-'

    # Convert minimum width to an int; default is zero.
    format_dict['minimumwidth'] = int(format_dict['minimumwidth'] or '0')

    # Convert precision to an int, or `None` if no precision given.
    if format_dict['precision']:
        format_dict['precision'] = int(format_dict['precision'][1:])
    else:
        format_dict['precision'] = None

    # If no rounding mode is given, assume 'N'.
    if not format_dict['rounding']:
        format_dict['rounding'] = 'N'

    return format_dict
Parse the given format specification and return a dictionary
    containing relevant values.