def _parse_format_specifier(format_spec):
    """Parse and validate a format specifier.

    Turns a standard numeric format specifier into a dict, with the
    following entries:

      fill: fill character to pad field to minimum width
      align: alignment type, either '<', '>', '=' or '^'
      sign: either '+', '-' or ' '
      minimumwidth: nonnegative integer giving minimum width
      precision: nonnegative integer giving precision, or None
      type: one of the characters 'eEfFgG%', or None
      unicode: either True or False (always True for Python 3.x)

    """
    m = _parse_format_specifier_regex.match(format_spec)
    if m is None:
        raise ValueError("Invalid format specifier: " + format_spec)

    # get the dictionary
    format_dict = m.groupdict()

    # defaults for fill and alignment
    fill = format_dict['fill']
    align = format_dict['align']
    if format_dict.pop('zeropad') is not None:
        # in the face of conflict, refuse the temptation to guess
        if fill is not None and fill != '0':
            raise ValueError("Fill character conflicts with '0'"
                             " in format specifier: " + format_spec)
        if align is not None and align != '=':
            raise ValueError("Alignment conflicts with '0' in "
                             "format specifier: " + format_spec)
        fill = '0'
        align = '='
    format_dict['fill'] = fill or ' '
    format_dict['align'] = align or '<'

    if format_dict['sign'] is None:
        format_dict['sign'] = '-'

    # turn minimumwidth and precision entries into integers.
    # minimumwidth defaults to 0; precision remains None if not given
    format_dict['minimumwidth'] = int(format_dict['minimumwidth'] or '0')
    if format_dict['precision'] is not None:
        format_dict['precision'] = int(format_dict['precision'])

    # if format type is 'g' or 'G' then a precision of 0 makes little
    # sense; convert it to 1.  Same if format type is unspecified.
    if format_dict['precision'] == 0:
        if 'gG' in format_dict['type'] or format_dict['type'] is None:
            format_dict['precision'] = 1

    # record whether return type should be str or unicode
    format_dict['unicode'] = isinstance(format_spec, unicode)

    return format_dict
dataset/ETHPy150Open deanhiller/databus/webapp/play1.3.x/python/Lib/decimal.py/_parse_format_specifier/swapped operands of `in`