def handle_extension(environ, resource_name):
    """
    Look for an extension (as defined in :py:mod:`config <tiddlyweb.config>`)
    on the provided ``resource_name`` and trim it off to give the
    "real" resource name.
    """
    extension = environ.get('tiddlyweb.extension')
    extension_types = environ['tiddlyweb.config']['extension_types']
    if extension and extension in extension_types:
        try:
            resource_name = resource_name[0:resource_name.rindex('.' +
                extension)]
        except ValueError:
            pass
    else:
        try:
            del environ['tiddlyweb.extension']
        except KeyError:
            pass
    return resource_name
