From 40178c92b215dd65ec552ae10de8a0ecaf32627a Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Mon, 26 Dec 2016 15:44:23 +0900 Subject: [PATCH] wsgi: Wrapper classes of Request/Response in WebOb 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 Signed-off-by: FUJITA Tomonori --- 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 7d7f1306..fc4c71ac 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):