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 <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
IWASE Yusuke 2016-12-26 15:44:23 +09:00 committed by FUJITA Tomonori
parent 95702135d4
commit 40178c92b2

View File

@ -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):