def replace_arguments(cmd, args):
    def arg_sub(m):
        """Replace a positional variable with the appropriate argument."""
        index = int(m.group(1)) - 1

        try:
            return args[index]
        except IndexError:
            return ''

    did_replacement = False

    shlex_convert_text_type = (not _SHLEX_SUPPORTS_UNICODE and
                               isinstance(cmd, six.text_type))

    if shlex_convert_text_type:
        cmd = cmd.encode('utf-8')

    for part in shlex.split(cmd):
        if part == '$*':
            did_replacement = True

            for arg in args:
                yield arg
        else:
            part, subs = _arg_re.subn(arg_sub, part)

            if subs != 0:
                did_replacement = True

            if shlex_convert_text_type:
                part = part.decode('utf-8')

            yield part

    if not did_replacement:
        for arg in args:
            yield arg
Close and unlock the file using the fcntl.lockf primitive.
dataset/ETHPy150Open reviewboard/rbtools/rbtools/utils/aliases.py/replace_arguments--crossover with--dataset/ETHPy150Open google/oauth2client/oauth2client/contrib/_fcntl_opener.py/_FcntlOpener.unlock_and_close