human
Complete the below
@directive('patches')
def patch(url_or_filename, level=1, when=None, **kwargs):

    ''''Packages can declare patches to apply to source.  You can
    optionally provide a when spec to indicate that a particular
    patch should only be applied when the package\'s spec meets
    certain conditions (e.g. a particular version).'
    '''

=====
What is a the Python code you requested?
assistant
#Here is the Python code you requested.
    def _execute(pkg):
        constraint = (pkg.name if (when is None) else when)
        when_spec = parse_anonymous_spec(constraint, pkg.name)
        cur_patches = pkg.patches.setdefault(when_spec, [])
        cur_patches.append(Patch.create(pkg, url_or_filename, level, **kwargs))
    return _execute