# Path: solo/util.py
# def as_json(o):
# def json_encode(value, ensure_ascii=True, default=as_json):
# 
# Path: solo/web/ctx.py
# LOGGER = logging.getLogger('solo.web')
# class GreenletServing(object):
# class _ThreadLocalProxy(object):
#     def __init__(self):
#     def load(self, request, response):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def clear(self):
#     def __init__(self, attrname):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __delattr__(self, name):
#     def _get_dict(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def __contains__(self, key):
#     def __len__(self):
#     def __nonzero__(self):


import sys
import logging
    from urllib.parse import unquote as url_unquote
    from urllib.parse import quote as url_quote
    from urllib import unquote as url_unquote
    from urllib import quote as url_quote
from solo.util import json_decode,json_encode
from solo.web.ctx import response, request
from markupsafe import escape_silent as escape
j.addEventListener(m,function(){j.removeEventListener(m,arguments.callee,false);i()},false);\
window.addEventListener("load",i,false)}else{if(c){var m="onreadystatechange";\
j.attachEvent(m,function(){j.detachEvent(m,arguments.callee);i()});\
if(j.documentElement.doScroll&&!frameElement){(function(){if(e){return}try{j.documentElement.doScroll("left")}\
catch(n){setTimeout(arguments.callee,0);return}i()})()}window.attachEvent("load",i)}}};\
return function(m){f=m.name||"webflash";g=m.id||"webflash";l=b(m.on_display,l);a=b(m.create_node,a);\
return{payload:h,render:d}}})();webflash.lj=function(s){var r;eval("r="+s);return r}};'''

    def __init__(self, cookie_name="webflash", default_status="ok"):
        self.default_status = default_status
        self.cookie_name = cookie_name

    def __call__(self, message, status=None, **extra_payload):
        # Force the message to be unicode so lazystrings, etc... are coerced
        message = unicode_text(message)

        payload = self.prepare_payload(message = message,
                                       status = status or self.default_status,
                                       **extra_payload)

        if request is not None:
            # Save the payload in environ too in case JavaScript is not being
            # used and the message is being displayed in the same request.
            request.environ['webflash.payload'] = payload

        response.set_cookie(self.cookie_name, payload)
        if len(response.headers['Set-Cookie']) > 4096:
            raise ValueError('Flash value is too long (cookie would be >4k)')

    def prepare_payload(self, **data):

# Path: solo/util.py
# def as_json(o):
# def json_encode(value, ensure_ascii=True, default=as_json):
# 
# Path: solo/web/ctx.py
# LOGGER = logging.getLogger('solo.web')
# class GreenletServing(object):
# class _ThreadLocalProxy(object):
#     def __init__(self):
#     def load(self, request, response):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def clear(self):
#     def __init__(self, attrname):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __delattr__(self, name):
#     def _get_dict(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def __contains__(self, key):
#     def __len__(self):
#     def __nonzero__(self):


# Path: solo/web/flash.py
import sys
import logging
    from urllib.parse import unquote as url_unquote
    from urllib.parse import quote as url_quote
    from urllib import unquote as url_unquote
    from urllib import quote as url_quote
from solo.util import json_decode,json_encode
from solo.web.ctx import response, request
from markupsafe import escape_silent as escape

j.addEventListener(m,function(){j.removeEventListener(m,arguments.callee,false);i()},false);\
window.addEventListener("load",i,false)}else{if(c){var m="onreadystatechange";\
j.attachEvent(m,function(){j.detachEvent(m,arguments.callee);i()});\
if(j.documentElement.doScroll&&!frameElement){(function(){if(e){return}try{j.documentElement.doScroll("left")}\
catch(n){setTimeout(arguments.callee,0);return}i()})()}window.attachEvent("load",i)}}};\
return function(m){f=m.name||"webflash";g=m.id||"webflash";l=b(m.on_display,l);a=b(m.create_node,a);\
return{payload:h,render:d}}})();webflash.lj=function(s){var r;eval("r="+s);return r}};'''

    def __init__(self, cookie_name="webflash", default_status="ok"):
        self.default_status = default_status
        self.cookie_name = cookie_name

    def __call__(self, message, status=None, **extra_payload):
        # Force the message to be unicode so lazystrings, etc... are coerced
        message = unicode_text(message)

        payload = self.prepare_payload(message = message,
                                       status = status or self.default_status,
                                       **extra_payload)

        if request is not None:
            # Save the payload in environ too in case JavaScript is not being
            # used and the message is being displayed in the same request.
            request.environ['webflash.payload'] = payload

        response.set_cookie(self.cookie_name, payload)
        if len(response.headers['Set-Cookie']) > 4096:
            raise ValueError('Flash value is too long (cookie would be >4k)')

    def prepare_payload(self, **data):

        return url_quote(json_encode(data))