def get_patched_request(requires, patchlist):
<EOL>rules = {<EOL>'<STR_LIT>':  (True,  True,  True ),<EOL>'<STR_LIT:!>': (False, False, False),<EOL>'<STR_LIT>': (False, False, True ),<EOL>'<STR_LIT>': (True,  True,  True )<EOL>}<EOL>requires = [Requirement(x) if not isinstance(x, Requirement) else x<EOL>for x in requires]<EOL>appended = []<EOL>for patch in patchlist:<EOL><INDENT>if patch and patch[<NUM_LIT:0>] in ('<STR_LIT:!>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>ch = patch[<NUM_LIT:0>]<EOL>name = Requirement(patch[<NUM_LIT:1>:]).name<EOL><DEDENT>else:<EOL><INDENT>ch = '<STR_LIT>'<EOL>name = Requirement(patch).name<EOL><DEDENT>rule = rules[ch]<EOL>replaced = (ch == '<STR_LIT>')<EOL>for i, req in enumerate(requires):<EOL><INDENT>if req is None or req.name != name:<EOL><INDENT>continue<EOL><DEDENT>if not req.conflict:<EOL><INDENT>replace = rule[<NUM_LIT:0>]  <EOL><DEDENT>elif not req.weak:<EOL><INDENT>replace = rule[<NUM_LIT:1>]  <EOL><DEDENT>else:<EOL><INDENT>replace = rule[<NUM_LIT:2>]  <EOL><DEDENT>if replace:<EOL><INDENT>if replaced:<EOL><INDENT>requires[i] = None<EOL><DEDENT>else:<EOL><INDENT>requires[i] = Requirement(patch)<EOL>replaced = True<EOL><DEDENT><DEDENT><DEDENT>if not replaced:<EOL><INDENT>appended.append(Requirement(patch))<EOL><DEDENT><DEDENT>result = [x for x in requires if x is not None] + appended<EOL>return result<EOL>
Apply patch args to a request.

    For example, consider:

        >>> print get_patched_request(["foo-5", "bah-8.1"], ["foo-6"])
        ["foo-6", "bah-8.1"]
        >>> print get_patched_request(["foo-5", "bah-8.1"], ["^bah"])
        ["foo-5"]

    The following rules apply wrt how normal/conflict/weak patches override
    (note though that the new request is always added, even if it doesn't
    override an existing request):

    PATCH  OVERRIDES: foo  !foo  ~foo
    -----  ---------- ---  ----  -----
    foo               Y    Y     Y
    !foo              N    N     N
    ~foo              N    N     Y
    ^foo              Y    Y     Y

    Args:
        requires (list of str or `version.Requirement`): Request.
        patchlist (list of str): List of patch requests.

    Returns:
        List of `version.Requirement`: Patched request.