human
Complete this python program:
def http_session(func):
assistant
#Here is the Python program you requested.

    """Wraps a HTTP or WebSocket connect consumer (or any consumer of messages
    that provides a "cookies" or "get" attribute) to provide a "http_session"
    attribute that behaves like request.session; that is, it\s hung off of
    a per-user session key that is saved in a cookie or passed as the
    "session_key" GET parameter.
    It won\t automatically create and set a session cookie for users who
    don\t have one - that\s what SessionMiddleware is for, this is a simpler
    read-only version for more low-level code.
    If a message does not have a session we can inflate, the "session" attribute
    will be None, rather than an empty session you can write to.
    Does not allow a new session to be set; that must be done via a view. This
    is only an accessor for any existing session.
    """
    @functools.wraps(func)
    def inner(message, *args, **kwargs):
        if hasattr(message, 'http_session'):
            try:
                return func(message, *args, **kwargs)
            finally:
                if ((message.http_session is not None) and message.http_session.modified):
                    message.http_session.save()
        try:
            if ('method' not in message.content):
                message.content['method'] = 'FAKE'
            request = AsgiRequest(message)
        except Exception as e:
            raise ValueError(('Cannot    parse    HTTP    message    -    are    you    sure    this    is    a    HTTP    consumer?    %s' % e))
        session_key = request.GET.get('session_key', None)
        if (session_key is None):
            session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None)
        if session_key:
            session_engine = import_module(settings.SESSION_ENGINE)
            session = session_engine.SessionStore(session_key=session_key)
        else:
            session = None
        message.http_session = session
        result = func(message, *args, **kwargs)
        if ((session is not None) and session.modified):
            session.save()
        return result
    return inner