# Path: rhizi/rz_req_handling.py
# def common_resp_handle__client_error(data=None, error=None, status=400):
#     return __common_resp_handle(data, error, status)


from flask import current_app
from flask import escape
from flask import render_template
from flask import request
from flask import session
from .rz_api_common import sanitize_input__rzdoc_name
from .rz_req_handling import common_resp_handle__client_error
import logging
    """
    Main application load function.

    [!] Do not use as a flask endpoint as multiple functions redirect here
    """

    # fetch rz_username for welcome message
    email_address = session.get('username')
    rz_username = "Anonymous Stranger"
    role_set = []
    if None != email_address:  # session cookie passed & contains uid (email_address)
        try:
            _uid, u_account = current_app.user_db.lookup_user__by_email_address(email_address)
        except Exception as e:
            # may occur on user_db reset or malicious cookie != stale cookie,
            # for which the user would at least be known to the user_db
            # FIXME: remove the cookie
            pass
        else:
            role_set = u_account.role_set
            rz_username = escape(u_account.rz_username)

    rz_config = current_app.rz_config
    if None == rzdoc_name:
        s_rzdoc_name = rz_config.rzdoc__mainpage_name
    else:
        try:
            s_rzdoc_name = sanitize_input__rzdoc_name(rzdoc_name)
        except Exception as e:
            log.exception(e)

# Path: rhizi/rz_req_handling.py
# def common_resp_handle__client_error(data=None, error=None, status=400):
#     return __common_resp_handle(data, error, status)


# Path: rhizi/rz_api.py
from flask import current_app
from flask import escape
from flask import render_template
from flask import request
from flask import session
from .rz_api_common import sanitize_input__rzdoc_name
from .rz_req_handling import common_resp_handle__client_error
import logging

    """
    Main application load function.

    [!] Do not use as a flask endpoint as multiple functions redirect here
    """

    # fetch rz_username for welcome message
    email_address = session.get('username')
    rz_username = "Anonymous Stranger"
    role_set = []
    if None != email_address:  # session cookie passed & contains uid (email_address)
        try:
            _uid, u_account = current_app.user_db.lookup_user__by_email_address(email_address)
        except Exception as e:
            # may occur on user_db reset or malicious cookie != stale cookie,
            # for which the user would at least be known to the user_db
            # FIXME: remove the cookie
            pass
        else:
            role_set = u_account.role_set
            rz_username = escape(u_account.rz_username)

    rz_config = current_app.rz_config
    if None == rzdoc_name:
        s_rzdoc_name = rz_config.rzdoc__mainpage_name
    else:
        try:
            s_rzdoc_name = sanitize_input__rzdoc_name(rzdoc_name)
        except Exception as e:
            log.exception(e)

            return common_resp_handle__client_error(status=404)