# Path: snakeguice/providers.py
# def create_simple_provider(cls):
#         def __init__(self, injector):
#         def get(self):
# def create_instance_provider(obj):
#         def get(self):
#     class DynamicSimpleProvider(object):
#     class DynamicInstanceProvider(object):


import cherrypy
from snakeguice.providers import InstanceProvider


class CherrypyRequestScope(object):

    def scope(self, key, provider):
        class SessionProvider(object):
            def get(self):
                if not hasattr(cherrypy.request, '__guicy__'):
                    cherrypy.request.__guicy__ = {}

                value = cherrypy.request.__guicy__.get(key)
                if not value:
                    value = cherrypy.request.__guicy__[key] = provider.get()
                return value
        return InstanceProvider(SessionProvider())


class CherrypySessionScope(object):

    def scope(self, key, provider):
        class SessionProvider(object):
            def get(self):
                value = cherrypy.session.get(key)
                if not value:
                    value = cherrypy.session[key] = provider.get()
                return value

# Path: snakeguice/providers.py
# def create_simple_provider(cls):
#         def __init__(self, injector):
#         def get(self):
# def create_instance_provider(obj):
#         def get(self):
#     class DynamicSimpleProvider(object):
#     class DynamicInstanceProvider(object):


# Path: examples/cherrypy/scopes.py
import cherrypy
from snakeguice.providers import InstanceProvider



class CherrypyRequestScope(object):

    def scope(self, key, provider):
        class SessionProvider(object):
            def get(self):
                if not hasattr(cherrypy.request, '__guicy__'):
                    cherrypy.request.__guicy__ = {}

                value = cherrypy.request.__guicy__.get(key)
                if not value:
                    value = cherrypy.request.__guicy__[key] = provider.get()
                return value
        return InstanceProvider(SessionProvider())


class CherrypySessionScope(object):

    def scope(self, key, provider):
        class SessionProvider(object):
            def get(self):
                value = cherrypy.session.get(key)
                if not value:
                    value = cherrypy.session[key] = provider.get()
                return value

        return InstanceProvider(SessionProvider())