def _replace_star(fmt, size):
n_stars = fmt.count('<STR_LIT:*>')<EOL>if n_stars > <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>" % fmt)<EOL><DEDENT>if n_stars:<EOL><INDENT>i = fmt.find('<STR_LIT:*>')<EOL>s = struct.calcsize(fmt.replace(fmt[i:i + <NUM_LIT:2>], '<STR_LIT>'))<EOL>n = old_div((size - s), struct.calcsize(fmt[i + <NUM_LIT:1>]))<EOL>fmt = fmt.replace('<STR_LIT:*>', str(n))<EOL><DEDENT>return fmt<EOL>
Replace the `*` placeholder in a format string (fmt), so that
struct.calcsize(fmt) is equal to the given `size` using the format
following the placeholder.

Raises `ValueError` if number of `*` is larger than 1. If no `*`
in `fmt`, returns `fmt` without checking its size!

Examples
--------
>>> _replace_star('ii*fi', 40)
'ii7fi'