def get_reference(proxy):
        '''
        Return the object that is referenced by the specified proxy.

        If the proxy has not been bound to a reference for the current thread,
        the behavior depends on th the ``fallback_to_shared`` flag that has
        been specified when creating the proxy. If the flag has been set, the
        last reference that has been set by any thread is returned (and
        silently set as the reference for the current thread). If the flag has
        not been set, an ``AttributeError`` is raised.

        If the object references by this proxy is itself a proxy, that proxy is
        returned. Use ``unproxy`` for unwrapping the referenced object until it
        is not a proxy.

        proxy:
            proxy object for which the reference shall be returned. If the
            specified object is not an instance of `ThreadLocalProxy`, the
            behavior is unspecified. Typically, an ``AttributeError`` is
            going to be raised.
        '''
        thread_local = object.__getattribute__(proxy, '_thread_local')
        try:
            return thread_local.reference
        except AttributeError:
            fallback_to_shared = object.__getattribute__(
                proxy, '_fallback_to_shared')
            if fallback_to_shared:
                # If the reference has never been set in the current thread of
                # execution, we use the reference that has been last set by any
                # thread.
                reference = object.__getattribute__(proxy, '_last_reference')
                # We save the reference in the thread local so that future
                # calls to get_reference will have consistent results.
                ThreadLocalProxy.set_reference(proxy, reference)
                return reference
            else:
                # We could simply return None, but this would make it hard to
                # debug situations where the reference has not been set (the
                # problem might go unnoticed until some code tries to do
                # something with the returned object and it might not be easy to
                # find out from where the None value originates).
                # For this reason, we raise an AttributeError with an error
                # message explaining the problem.
                raise AttributeError(
                    'The proxy object has not been bound to a reference in this thread of execution.')
Return the object that is referenced by the specified proxy.

        If the proxy has not been bound to a reference for the current thread,
        the behavior depends on th the ``fallback_to_shared`` flag that has
        been specified when creating the proxy. If the flag has been set, the
        last reference that has been set by any thread is returned (and
        silently set as the reference for the current thread). If the flag has
        not been set, an ``AttributeError`` is raised.

        If the object references by this proxy is itself a proxy, that proxy is
        returned. Use ``unproxy`` for unwrapping the referenced object until it
        is not a proxy.

        proxy:
            proxy object for which the reference shall be returned. If the
            specified object is not an instance of `ThreadLocalProxy`, the
            behavior is unspecified. Typically, an ``AttributeError`` is
            going to be raised.