@classmethod
def getcontext(cls, key=None):
    """Returns the thread-local value for given key or a default global value
        if it doesn't exist. Returns the whole context if no key is given."""
    with cls.__default_context_lock:
        if key is None:
            return {**cls.__default_context, **cls.__context.__dict__}
        else:
            return cls.__context.__dict__.get(key, cls.__default_context.
                get(key))
