def iec2bytes(size_spec, only_positive=True):
scale = <NUM_LIT:1><EOL>try:<EOL><INDENT>size = int(<NUM_LIT:0> + size_spec)  <EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>spec = size_spec.strip().lower()<EOL>for exp, iec_unit in enumerate(IEC_UNITS[<NUM_LIT:1>:], <NUM_LIT:1>):<EOL><INDENT>iec_unit = iec_unit.lower()<EOL>if spec.endswith(iec_unit):<EOL><INDENT>spec = spec[:-len(iec_unit)]<EOL>scale = <NUM_LIT:2> ** (<NUM_LIT:10> * exp)<EOL>break<EOL><DEDENT>elif spec.endswith(iec_unit[<NUM_LIT:0>]):<EOL><INDENT>spec = spec[:-<NUM_LIT:1>]<EOL>scale = <NUM_LIT:2> ** (<NUM_LIT:10> * exp)<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if spec.endswith('<STR_LIT:b>'):<EOL><INDENT>spec = spec[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>try:<EOL><INDENT>if '<STR_LIT:.>' in spec:<EOL><INDENT>size = float(spec.strip())<EOL><DEDENT>else:<EOL><INDENT>size = int(spec.strip(), base=<NUM_LIT:0>)<EOL><DEDENT><DEDENT>except (TypeError, ValueError) as cause:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(size_spec, cause))<EOL><DEDENT><DEDENT>if only_positive and size < <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(size_spec))<EOL><DEDENT>return int(size * scale)<EOL>
Convert a size specification, optionally containing a scaling
        unit in IEC notation, to a number of bytes.

        Parameters:
            size_spec (str): Number, optionally followed by a unit.
            only_positive (bool): Allow only positive values?

        Return:
            Numeric bytes size.

        Raises:
            ValueError: Unknown unit specifiers, or bad leading integer.