From e9e9eb62f25544f98356b3ac5141ba3fd93cfe11 Mon Sep 17 00:00:00 2001 From: Mark Hetherington Date: Tue, 17 Sep 2019 16:46:15 +1000 Subject: [PATCH 1/3] Allow writing bytes to browser --- webapp2.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/webapp2.py b/webapp2.py index e48e7bf..d57a7d9 100755 --- a/webapp2.py +++ b/webapp2.py @@ -416,9 +416,6 @@ def write(self, text): """Appends a text to the response body.""" # webapp uses StringIO as Response.out, so we need to convert anything # that is not str or unicode to string to keep same behavior. - if six.PY3 and isinstance(text, bytes): - text = text.decode(self.default_charset) - if not isinstance(text, six.string_types): text = six.text_type(text) From fc6fc02dbfdcceb79c3e3508c3ef7af510d4e783 Mon Sep 17 00:00:00 2001 From: Mark Hetherington Date: Wed, 18 Sep 2019 09:42:03 +1000 Subject: [PATCH 2/3] Do no processing if bytes Otherwise we get a repr style 'b\'\'' --- webapp2.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/webapp2.py b/webapp2.py index d57a7d9..178c7d7 100755 --- a/webapp2.py +++ b/webapp2.py @@ -416,11 +416,12 @@ def write(self, text): """Appends a text to the response body.""" # webapp uses StringIO as Response.out, so we need to convert anything # that is not str or unicode to string to keep same behavior. - if not isinstance(text, six.string_types): - text = six.text_type(text) + if not isinstance(text, bytes): + if not isinstance(text, six.string_types): + text = six.text_type(text) - if isinstance(text, six.text_type) and not self.charset: - self.charset = self.default_charset + if isinstance(text, six.text_type) and not self.charset: + self.charset = self.default_charset super(Response, self).write(text) From 492fb9ac359684c633fc733e545cf9ca452e5bf1 Mon Sep 17 00:00:00 2001 From: Mark Hetherington Date: Wed, 9 Oct 2019 15:21:01 +1100 Subject: [PATCH 3/3] Use request.domain to match request routes On paste.httpserver SERVER_NAME is 127.0.0.1, on waitress SERVER_NAME is local machine name. --- webapp2_extras/routes.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/webapp2_extras/routes.py b/webapp2_extras/routes.py index 24b5bfc..347e85e 100644 --- a/webapp2_extras/routes.py +++ b/webapp2_extras/routes.py @@ -108,9 +108,7 @@ def get_match_routes(self): yield self def match(self, request): - # Use SERVER_NAME to ignore port number that comes with request.host? - # host_match = self.regex.match(request.host.split(':', 1)[0]) - host_match = self.regex.match(request.environ['SERVER_NAME']) + host_match = self.regex.match(request.domain) if host_match: args, kwargs = webapp2._get_route_variables(host_match)