summaryrefslogtreecommitdiff
path: root/cherrypy/lib/encoding.py
diff options
context:
space:
mode:
authorGustavo Picon <tabo@tabo.pe>2014-01-12 13:57:44 -0500
committerGustavo Picon <tabo@tabo.pe>2014-01-12 13:57:44 -0500
commitc26eb490862e664dc4ef4ea6e55c1dbd106146c4 (patch)
treef997c23aa6d04fc7db78e66ad5f58429b3be824e /cherrypy/lib/encoding.py
parentfb84f7713d6ced0031dacb0e7e59d516cc681a4d (diff)
downloadcherrypy-git-c26eb490862e664dc4ef4ea6e55c1dbd106146c4.tar.gz
Running: autopep8 -vvvvv -i `find . -name '*.py'`
--HG-- branch : autopep8
Diffstat (limited to 'cherrypy/lib/encoding.py')
-rw-r--r--cherrypy/lib/encoding.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py
index 02a50f87..d0b66b49 100644
--- a/cherrypy/lib/encoding.py
+++ b/cherrypy/lib/encoding.py
@@ -96,7 +96,8 @@ class ResponseEncoder:
response = cherrypy.serving.response
if self.debug:
- cherrypy.log('response.stream %r' % response.stream, 'TOOLS.ENCODE')
+ cherrypy.log('response.stream %r' %
+ response.stream, 'TOOLS.ENCODE')
if response.stream:
encoder = self.encode_stream
else:
@@ -125,10 +126,12 @@ class ResponseEncoder:
# If specified, force this encoding to be used, or fail.
encoding = self.encoding.lower()
if self.debug:
- cherrypy.log('Specified encoding %r' % encoding, 'TOOLS.ENCODE')
+ cherrypy.log('Specified encoding %r' %
+ encoding, 'TOOLS.ENCODE')
if (not charsets) or "*" in charsets or encoding in charsets:
if self.debug:
- cherrypy.log('Attempting encoding %r' % encoding, 'TOOLS.ENCODE')
+ cherrypy.log('Attempting encoding %r' %
+ encoding, 'TOOLS.ENCODE')
if encoder(encoding):
return encoding
else:
@@ -140,7 +143,8 @@ class ResponseEncoder:
if encoder(self.default_encoding):
return self.default_encoding
else:
- raise cherrypy.HTTPError(500, self.failmsg % self.default_encoding)
+ raise cherrypy.HTTPError(500, self.failmsg %
+ self.default_encoding)
else:
for element in encs:
if element.qvalue > 0:
@@ -202,14 +206,16 @@ class ResponseEncoder:
ct = response.headers.elements("Content-Type")
if self.debug:
- cherrypy.log('Content-Type: %r' % [str(h) for h in ct], 'TOOLS.ENCODE')
+ cherrypy.log('Content-Type: %r' % [str(h)
+ for h in ct], 'TOOLS.ENCODE')
if ct and self.add_charset:
ct = ct[0]
if self.text_only:
if ct.value.lower().startswith("text/"):
if self.debug:
- cherrypy.log('Content-Type %s starts with "text/"' % ct,
- 'TOOLS.ENCODE')
+ cherrypy.log(
+ 'Content-Type %s starts with "text/"' % ct,
+ 'TOOLS.ENCODE')
do_find = True
else:
if self.debug:
@@ -219,7 +225,8 @@ class ResponseEncoder:
do_find = False
else:
if self.debug:
- cherrypy.log('Finding because not text_only', 'TOOLS.ENCODE')
+ cherrypy.log('Finding because not text_only',
+ 'TOOLS.ENCODE')
do_find = True
if do_find:
@@ -234,6 +241,7 @@ class ResponseEncoder:
# GZIP
+
def compress(body, compress_level):
"""Compress 'body' at the given compress_level."""
import zlib
@@ -263,6 +271,7 @@ def compress(body, compress_level):
# ISIZE: 4 bytes
yield struct.pack("<L", size & int('FFFFFFFF', 16))
+
def decompress(body):
import gzip
@@ -383,4 +392,3 @@ def gzip(compress_level=5, mime_types=['text/html', 'text/plain'], debug=False):
if debug:
cherrypy.log('No acceptable encoding found.', context='GZIP')
cherrypy.HTTPError(406, "identity, gzip").set_response()
-