summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2016-12-26 15:44:23 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-12-29 22:13:56 +0900
commit40178c92b215dd65ec552ae10de8a0ecaf32627a (patch)
treeaeb8821d5ffbda13249667cfa42d44c13620791a
parent95702135d401c99d852f00aad3c6e7b0c0fdfdea (diff)
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>
-rw-r--r--ryu/app/wsgi.py30
1 files changed, 29 insertions, 1 deletions
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):