# 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
    def js_call(self, container_id):
        return 'webflash(%(options)s).render();' % {'options': json_encode({'id': container_id,
                                                                           'name': self.cookie_name})}

    def render(self, container_id, use_js=True):
        if use_js:
            return self._render_js_version(container_id)
        else:
            return self._render_static_version(container_id)

    def _render_static_version(self, container_id):
        payload = self.pop_payload()
        if not payload:
            return ''
        payload['message'] = escape(payload.get('message',''))
        payload['container_id'] = container_id
        return self.static_template % payload

    def _render_js_version(self, container_id):
        return self.template % {'container_id': container_id,
                                'js_code': self.js_code,
                                'js_call': self.js_call(container_id)}

    def pop_payload(self):
        # First try fetching it from the request
        payload = request.environ.get('webflash.payload', {})
        if not payload:
            payload = request.cookies.get(self.cookie_name, {})

        if payload:

# 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

    def js_call(self, container_id):
        return 'webflash(%(options)s).render();' % {'options': json_encode({'id': container_id,
                                                                           'name': self.cookie_name})}

    def render(self, container_id, use_js=True):
        if use_js:
            return self._render_js_version(container_id)
        else:
            return self._render_static_version(container_id)

    def _render_static_version(self, container_id):
        payload = self.pop_payload()
        if not payload:
            return ''
        payload['message'] = escape(payload.get('message',''))
        payload['container_id'] = container_id
        return self.static_template % payload

    def _render_js_version(self, container_id):
        return self.template % {'container_id': container_id,
                                'js_code': self.js_code,
                                'js_call': self.js_call(container_id)}

    def pop_payload(self):
        # First try fetching it from the request
        payload = request.environ.get('webflash.payload', {})
        if not payload:
            payload = request.cookies.get(self.cookie_name, {})

        if payload:

            payload = json_decode(url_unquote(payload))