# 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/app.py
# class App(object):
# 
# 
#     hookpoints = ['on_start_resource', 'before_handler',
#                 'on_end_resource', 'on_end_request',
#                 'before_error_response', 'after_error_response']
# 
# 
#     def __init__(self, name='Lilac', encoding='utf8', debug=False, dispatcher=None):
#         self.dispatcher = dispatcher or RoutesDispatcher()
#         self.name = name
#         self.error_pages = {}
#         self.encoding = encoding
#         self.debug = debug
#         self.hooks = HookMap()
#         self.error_response = self._error_response
#         self.initialize()
# 
#     def initialize(self):
#         pass
# 
#     def route(self):
#         return self.dispatcher
# 
#     def attach(self, point, callback, failsafe=None, priority=None, **kwargs):
#         if point not in self.hookpoints:
#             return
#         self.hooks.attach(point, callback, failsafe, priority, **kwargs)
# 
#     def asset(self, name, path, asset_path, default_filename=None, block_size=None):
#         """Set servering Static directory"""
#         from solo.web.asset import AssetController
#         path = '' if path == '/' else path
#         ctl = AssetController(asset_path, default_filename, block_size)
#         self.dispatcher.connect(name, path + "/{path:.*?}", controller=ctl, action='asset', conditions=dict(method=["HEAD", "GET"]))
# 
# 
#     def error_page(self, code, callback):
#         if type(code) is not int:
#             raise TypeError("code:%d is not int type" %(code))
#         self.error_pages[str(code)] = callback
# 
#     def __call__(self, environ, start_response):
#         try:
#             try:
#                 request = Request(environ)
#                 response = Response()
#                 serving.load(request, response)
#                 if request.charset is None:
#                     request.charset = self.encoding
# 
#                 self.hooks.run('on_start_resource')
# 
#                 path_info = environ['PATH_INFO']
#                 action, handler = self.dispatcher.match(request, path_info)
#                 body = None
#                 self.hooks.run('before_handler')
# 
#                 if handler:
#                     body = handler()
#                     if type(body) is str:
#                         response.body = body
#                     elif body:
#                         response.text = body
#                     self.hooks.run('on_end_resource')
#                     return response(environ, start_response)
#                 else:
#                     raise exc.HTTPNotFound('Path %s Not Found' % (path_info)) 
# 
#             except exc.HTTPRedirection as e:
#                 serving.response.location = e.location
#                 serving.response.status = e.status
#                 response = serving.response
#                 self.hooks.run('on_end_resource')
#             except exc.HTTPException as e:
#                 response = serving.response = self.handle_error_page(request, response, e)
#             except Exception as e:
#                 LOGGER.error(e)
#                 self.error_response(request, response, e)
#             return response(environ, start_response)
#         finally:
#             try:
#                 self.hooks.run('on_end_request')
#             finally:
#                 serving.clear()
# 
# 
#     def handle_error_page(self, request, response, exception):
#         """Handle the last unanticipated exception. (Core)"""
#         try:
#             self.hooks.run("before_error_response")
#             response.status = exception.status
#             #response.status = exception.status
#             handler = self.error_pages.get(str(exception.code), None)
#             if handler:
#                 body = handler()
#                 if type(body) is str:
#                     response.body = body
#                 elif text:
#                     response.text = body
#                 return response
#             else:
#                 return exception
#         finally:
#             self.hooks.run("after_error_response")
# 
#     def _error_response(self, request, response, exception):
#         """Handle the unknow exception and also throw 5xx status and message to frontend"""
#         cls, e, tb = exc_info()
# 
#         LOGGER.exception('Unhandled Error: %s', e)
# 
#         response.status_code = 500
#         response.content_type = 'text/html; charset=UTF-8'
# 
#         if request.method != 'HEAD':
#             response.unicode_body = u"""<html>
# <head><title>Internal Server Error </title></head>
# <body><p>An error occurred: <b>%s</b></p></body>
# </html> 
# """ % (str(e))
# 
# Path: solo/util.py
# def json_encode(value, ensure_ascii=True, default=as_json):
#     """Returns the json serialize stream"""
#     return json.dumps(value, default=default, ensure_ascii=ensure_ascii)
# 
# Path: solo/web/util.py
# def jsonify(f):
#     """The decorator will set response content type to application/json; charset=UTF-8,
#     and als handle the object which has as_json method"""
#     @wraps(f)
#     def __(*args, **kwargs):
#         response.content_type = 'application/json; charset=UTF-8'
#         return json_encode(f(*args, **kwargs))
# 
#     return __


import unittest
import os.path
from webob import exc
from solo.web.ctx import serving, response
from solo.web.app import App
from webob import Request
from solo.util import json_encode
from solo.web.util import jsonify





class AppTest(unittest.TestCase):

    def setUp(self):
        self.app = App()

        class Hello():

            def index(self):
                return 'index'

            def internal_error(self):
                raise Exception('internal_error')


# 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/app.py
# class App(object):
# 
# 
#     hookpoints = ['on_start_resource', 'before_handler',
#                 'on_end_resource', 'on_end_request',
#                 'before_error_response', 'after_error_response']
# 
# 
#     def __init__(self, name='Lilac', encoding='utf8', debug=False, dispatcher=None):
#         self.dispatcher = dispatcher or RoutesDispatcher()
#         self.name = name
#         self.error_pages = {}
#         self.encoding = encoding
#         self.debug = debug
#         self.hooks = HookMap()
#         self.error_response = self._error_response
#         self.initialize()
# 
#     def initialize(self):
#         pass
# 
#     def route(self):
#         return self.dispatcher
# 
#     def attach(self, point, callback, failsafe=None, priority=None, **kwargs):
#         if point not in self.hookpoints:
#             return
#         self.hooks.attach(point, callback, failsafe, priority, **kwargs)
# 
#     def asset(self, name, path, asset_path, default_filename=None, block_size=None):
#         """Set servering Static directory"""
#         from solo.web.asset import AssetController
#         path = '' if path == '/' else path
#         ctl = AssetController(asset_path, default_filename, block_size)
#         self.dispatcher.connect(name, path + "/{path:.*?}", controller=ctl, action='asset', conditions=dict(method=["HEAD", "GET"]))
# 
# 
#     def error_page(self, code, callback):
#         if type(code) is not int:
#             raise TypeError("code:%d is not int type" %(code))
#         self.error_pages[str(code)] = callback
# 
#     def __call__(self, environ, start_response):
#         try:
#             try:
#                 request = Request(environ)
#                 response = Response()
#                 serving.load(request, response)
#                 if request.charset is None:
#                     request.charset = self.encoding
# 
#                 self.hooks.run('on_start_resource')
# 
#                 path_info = environ['PATH_INFO']
#                 action, handler = self.dispatcher.match(request, path_info)
#                 body = None
#                 self.hooks.run('before_handler')
# 
#                 if handler:
#                     body = handler()
#                     if type(body) is str:
#                         response.body = body
#                     elif body:
#                         response.text = body
#                     self.hooks.run('on_end_resource')
#                     return response(environ, start_response)
#                 else:
#                     raise exc.HTTPNotFound('Path %s Not Found' % (path_info)) 
# 
#             except exc.HTTPRedirection as e:
#                 serving.response.location = e.location
#                 serving.response.status = e.status
#                 response = serving.response
#                 self.hooks.run('on_end_resource')
#             except exc.HTTPException as e:
#                 response = serving.response = self.handle_error_page(request, response, e)
#             except Exception as e:
#                 LOGGER.error(e)
#                 self.error_response(request, response, e)
#             return response(environ, start_response)
#         finally:
#             try:
#                 self.hooks.run('on_end_request')
#             finally:
#                 serving.clear()
# 
# 
#     def handle_error_page(self, request, response, exception):
#         """Handle the last unanticipated exception. (Core)"""
#         try:
#             self.hooks.run("before_error_response")
#             response.status = exception.status
#             #response.status = exception.status
#             handler = self.error_pages.get(str(exception.code), None)
#             if handler:
#                 body = handler()
#                 if type(body) is str:
#                     response.body = body
#                 elif text:
#                     response.text = body
#                 return response
#             else:
#                 return exception
#         finally:
#             self.hooks.run("after_error_response")
# 
#     def _error_response(self, request, response, exception):
#         """Handle the unknow exception and also throw 5xx status and message to frontend"""
#         cls, e, tb = exc_info()
# 
#         LOGGER.exception('Unhandled Error: %s', e)
# 
#         response.status_code = 500
#         response.content_type = 'text/html; charset=UTF-8'
# 
#         if request.method != 'HEAD':
#             response.unicode_body = u"""<html>
# <head><title>Internal Server Error </title></head>
# <body><p>An error occurred: <b>%s</b></p></body>
# </html> 
# """ % (str(e))
# 
# Path: solo/util.py
# def json_encode(value, ensure_ascii=True, default=as_json):
#     """Returns the json serialize stream"""
#     return json.dumps(value, default=default, ensure_ascii=ensure_ascii)
# 
# Path: solo/web/util.py
# def jsonify(f):
#     """The decorator will set response content type to application/json; charset=UTF-8,
#     and als handle the object which has as_json method"""
#     @wraps(f)
#     def __(*args, **kwargs):
#         response.content_type = 'application/json; charset=UTF-8'
#         return json_encode(f(*args, **kwargs))
# 
#     return __


# Path: tests/webt.py
import unittest
import os.path
from webob import exc
from solo.web.ctx import serving, response
from solo.web.app import App
from webob import Request
from solo.util import json_encode
from solo.web.util import jsonify






class AppTest(unittest.TestCase):

    def setUp(self):
        self.app = App()

        class Hello():

            def index(self):
                return 'index'

            def internal_error(self):
                raise Exception('internal_error')


            @jsonify