# Path: shrubbery/authentication/exceptions.py
# class AuthenticationError(Exception): pass
# 
# class Http403(Exception): pass
# 
# Path: shrubbery/conf/base.py
# class Setting(object):
# class Registry(object):
# class SettingsBase(type):
# class Settings(object):
#     def __init__(self, validators=None, legacy_setting=None, help=None, resolve_callable=False, **kwargs):
#     def normalize(self, value):
#     def __get__(self, instance, cls=None):
#     def __set__(self, instance, value):
#     def __delete__(self, instance):
#     def __init__(self):
#     def __getitem__(self, module_name):
#     def __getattr__(self, name):
#     def __new__(cls, name, bases, attribs):     
#     def instance(cls):
#     def configure(cls, config):
#     def __init__(self, config=None):
#     def __iter__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value):
#     def __delitem__(self, name):
#     def as_dict(self):
#     def load(self, config):
#     def validate(self):
#     def app_module(self):
#     def app_label(self):
#     def missing_setting(self, setting):


import threading
from functools import wraps
from django.utils.importlib import import_module
from shrubbery.authentication.exceptions import AuthenticationError, Http403
from shrubbery.conf import settings
    def __enter__(self):
        self.base_user = self.auth.user
        self.auth.user = self.user
        
    def __exit__(self, *exc):
        self.auth.user = self.base_user
        
    def __call__(self, func):
        @wraps(func)
        def decorated(*args, **kwargs):
            with self:
                return func(*args, **kwargs)
        return decorated


_unset = object()


class AuthenticationContext(object):
    def __init__(self, root=None, anonymous=None, session_key=None):
        self.root = root
        self.anonymous = anonymous
        self.stack = threading.local()
        if not session_key:
            session_key = "%s.user-id" % self.__class__.__name__
        self.session_key = session_key
        self.user = self.anonymous
        
    def sudo(self, user=_unset):
        if user is _unset:

# Path: shrubbery/authentication/exceptions.py
# class AuthenticationError(Exception): pass
# 
# class Http403(Exception): pass
# 
# Path: shrubbery/conf/base.py
# class Setting(object):
# class Registry(object):
# class SettingsBase(type):
# class Settings(object):
#     def __init__(self, validators=None, legacy_setting=None, help=None, resolve_callable=False, **kwargs):
#     def normalize(self, value):
#     def __get__(self, instance, cls=None):
#     def __set__(self, instance, value):
#     def __delete__(self, instance):
#     def __init__(self):
#     def __getitem__(self, module_name):
#     def __getattr__(self, name):
#     def __new__(cls, name, bases, attribs):     
#     def instance(cls):
#     def configure(cls, config):
#     def __init__(self, config=None):
#     def __iter__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value):
#     def __delitem__(self, name):
#     def as_dict(self):
#     def load(self, config):
#     def validate(self):
#     def app_module(self):
#     def app_label(self):
#     def missing_setting(self, setting):


# Path: shrubbery/authentication/contexts.py
import threading
from functools import wraps
from django.utils.importlib import import_module
from shrubbery.authentication.exceptions import AuthenticationError, Http403
from shrubbery.conf import settings

    def __enter__(self):
        self.base_user = self.auth.user
        self.auth.user = self.user
        
    def __exit__(self, *exc):
        self.auth.user = self.base_user
        
    def __call__(self, func):
        @wraps(func)
        def decorated(*args, **kwargs):
            with self:
                return func(*args, **kwargs)
        return decorated


_unset = object()


class AuthenticationContext(object):
    def __init__(self, root=None, anonymous=None, session_key=None):
        self.root = root
        self.anonymous = anonymous
        self.stack = threading.local()
        if not session_key:
            session_key = "%s.user-id" % self.__class__.__name__
        self.session_key = session_key
        self.user = self.anonymous
        
    def sudo(self, user=_unset):
        if user is _unset:

            user = self.root