import itertools


def _MakeBytes(bits, toks):
  """Creates a multi-byte string from ASCII strings and/or ASCII codes.

  Args:
    bits: Number of bits per character, must be in {8, 16, 32}.
    toks: A list of tokens, each of which is a ASCII strings or an integer
      representing a character's ASCII value (e.g., 0 for terminating null).

  Returns: A flattened string of the |bits|-bit string formed by |bit|-extending
    the result of concatanating tokens.
  """
  cfi = itertools.chain.from_iterable
  chars = cfi(map(ord, t) if isinstance(t, str) else (t, ) for t in toks)
  return bytes(cfi((c >> (8 * i) for i in range(bits // 8)) for c in chars))