11import os
2+ import urllib .parse
23import warnings
34
45import flask
1415
1516from jinja2 import __version__ as __jinja_version__
1617from jinja2 import Environment , PackageLoader
17- from werkzeug .urls import url_quote_plus
1818
1919from flask_debugtoolbar .compat import iteritems
2020from flask_debugtoolbar .toolbar import DebugToolbar
@@ -76,7 +76,7 @@ def __init__(self, app=None):
7676 autoescape = True ,
7777 extensions = jinja_extensions ,
7878 loader = PackageLoader (__name__ , 'templates' ))
79- self .jinja_env .filters ['urlencode' ] = url_quote_plus
79+ self .jinja_env .filters ['urlencode' ] = urllib . parse . quote_plus
8080 self .jinja_env .filters ['printable' ] = _printable
8181 self .jinja_env .globals ['url_for' ] = url_for
8282
@@ -230,10 +230,11 @@ def process_response(self, response):
230230 response .headers ['content-type' ].startswith ('text/html' )):
231231 return response
232232
233- if 'gzip' in response .headers .get ('Content-Encoding' , '' ):
234- response_html = gzip_decompress (response .data ).decode (response .charset )
233+ content_encoding = response .headers .get ('Content-Encoding' )
234+ if content_encoding and 'gzip' in content_encoding :
235+ response_html = gzip_decompress (response .data ).decode ()
235236 else :
236- response_html = response .data . decode ( response . charset )
237+ response_html = response .get_data ( as_text = True )
237238
238239 no_case = response_html .lower ()
239240 body_end = no_case .rfind ('</body>' )
@@ -257,8 +258,8 @@ def process_response(self, response):
257258 toolbar_html = toolbar .render_toolbar ()
258259
259260 content = '' .join ((before , toolbar_html , after ))
260- content = content .encode (response . charset )
261- if 'gzip' in response . headers . get ( 'Content-Encoding' , '' ) :
261+ content = content .encode ('utf-8' )
262+ if content_encoding and 'gzip' in content_encoding :
262263 content = gzip_compress (content )
263264 response .response = [content ]
264265 response .content_length = len (content )
0 commit comments