With WebOB 1.7.0+, "charset" can not be omitted when constructing Request/Response instance and exception will occur if omitted. This patch adds wrapper classes of Request/Response for setting charset="UTF-8" by default.
Signed-off-by: IWASE Yusuke <[email protected]> --- ryu/app/wsgi.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ryu/app/wsgi.py b/ryu/app/wsgi.py index 7d7f130..fc4c71a 100644 --- a/ryu/app/wsgi.py +++ b/ryu/app/wsgi.py @@ -28,7 +28,8 @@ from tinyrpc.transports import ServerTransport, ClientTransport from tinyrpc.client import RPCClient import webob.dec import webob.exc -from webob.response import Response +from webob.request import Request as webob_Request +from webob.response import Response as webob_Response from ryu import cfg from ryu.lib import hub @@ -56,6 +57,33 @@ def route(name, path, methods=None, requirements=None): return _route +class Request(webob_Request): + """ + Wrapper class for webob.request.Request. + + The behavior of this class is the same as webob.request.Request + except for setting "charset" to "UTF-8" automatically. + """ + DEFAULT_CHARSET = "UTF-8" + + def __init__(self, environ, charset=DEFAULT_CHARSET, *args, **kwargs): + super(Request, self).__init__( + environ, charset=charset, *args, **kwargs) + + +class Response(webob_Response): + """ + Wrapper class for webob.response.Response. + + The behavior of this class is the same as webob.response.Response + except for setting "charset" to "UTF-8" automatically. + """ + DEFAULT_CHARSET = "UTF-8" + + def __init__(self, charset=DEFAULT_CHARSET, *args, **kwargs): + super(Response, self).__init__(charset=charset, *args, **kwargs) + + class WebSocketRegistrationWrapper(object): def __init__(self, func, controller): -- 2.7.4 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today.http://sdm.link/intel _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
