def proxy_factory(BaseSchema, label, ProxiedClass, get_key):
def local():<EOL><INDENT>key = get_key()<EOL>try:<EOL><INDENT>return proxies[BaseSchema][label][key]<EOL><DEDENT>except KeyError:<EOL><INDENT>proxies[BaseSchema][label][key] = ProxiedClass()<EOL>return proxies[BaseSchema][label][key]<EOL><DEDENT><DEDENT>return LocalProxy(local)<EOL>
Create a proxy to a class instance stored in ``proxies``.

    :param class BaseSchema: Base schema (e.g. ``StoredObject``)
    :param str label: Name of class variable to set
    :param class ProxiedClass: Class to get or create
    :param function get_key: Extension-specific key function; may return e.g.
        the current Flask request