summaryrefslogtreecommitdiff
path: root/cherrypy/lib/encoding.py
diff options
context:
space:
mode:
authorSviatoslav Sydorenko <wk@sydorenko.org.ua>2016-09-08 16:12:31 +0300
committerSviatoslav Sydorenko <wk@sydorenko.org.ua>2016-09-08 16:12:31 +0300
commitdc574c422886d192b33a48b036d0e9839c3cc6e0 (patch)
treec2f25676df9d99ee26521367aa1e01692d788a86 /cherrypy/lib/encoding.py
parent2035500ef638a079665a29548aea74761d8877ef (diff)
downloadcherrypy-git-dc574c422886d192b33a48b036d0e9839c3cc6e0.tar.gz
Convert all strings to conform single-quoted style
pre-commit run double-quote-string-fixer --all-files
Diffstat (limited to 'cherrypy/lib/encoding.py')
-rw-r--r--cherrypy/lib/encoding.py44
1 files changed, 22 insertions, 22 deletions
diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py
index e1179415..dc93d990 100644
--- a/cherrypy/lib/encoding.py
+++ b/cherrypy/lib/encoding.py
@@ -66,7 +66,7 @@ class UTF8StreamEncoder:
class ResponseEncoder:
default_encoding = 'utf-8'
- failmsg = "Response body could not be encoded with %r."
+ failmsg = 'Response body could not be encoded with %r.'
encoding = None
errors = 'strict'
text_only = True
@@ -131,7 +131,7 @@ class ResponseEncoder:
encoder = self.encode_stream
else:
encoder = self.encode_string
- if "Content-Length" in response.headers:
+ if 'Content-Length' in response.headers:
# Delete Content-Length header so finalize() recalcs it.
# Encoded strings may be of different lengths from their
# unicode equivalents, and even from each other. For example:
@@ -142,7 +142,7 @@ class ResponseEncoder:
# 6
# >>> len(t.encode("utf7"))
# 8
- del response.headers["Content-Length"]
+ del response.headers['Content-Length']
# Parse the Accept-Charset request header, and try to provide one
# of the requested charsets (in order of user preference).
@@ -157,7 +157,7 @@ class ResponseEncoder:
if self.debug:
cherrypy.log('Specified encoding %r' %
encoding, 'TOOLS.ENCODE')
- if (not charsets) or "*" in charsets or encoding in charsets:
+ if (not charsets) or '*' in charsets or encoding in charsets:
if self.debug:
cherrypy.log('Attempting encoding %r' %
encoding, 'TOOLS.ENCODE')
@@ -177,7 +177,7 @@ class ResponseEncoder:
else:
for element in encs:
if element.qvalue > 0:
- if element.value == "*":
+ if element.value == '*':
# Matches any charset. Try our default.
if self.debug:
cherrypy.log('Attempting default encoding due '
@@ -192,7 +192,7 @@ class ResponseEncoder:
if encoder(encoding):
return encoding
- if "*" not in charsets:
+ if '*' not in charsets:
# If no "*" is present in an Accept-Charset field, then all
# character sets not explicitly mentioned get a quality
# value of 0, except for ISO-8859-1, which gets a quality
@@ -208,11 +208,11 @@ class ResponseEncoder:
# No suitable encoding found.
ac = request.headers.get('Accept-Charset')
if ac is None:
- msg = "Your client did not send an Accept-Charset header."
+ msg = 'Your client did not send an Accept-Charset header.'
else:
- msg = "Your client sent this Accept-Charset header: %s." % ac
- _charsets = ", ".join(sorted(self.attempted_charsets))
- msg += " We tried these charsets: %s." % (_charsets,)
+ msg = 'Your client sent this Accept-Charset header: %s.' % ac
+ _charsets = ', '.join(sorted(self.attempted_charsets))
+ msg += ' We tried these charsets: %s.' % (_charsets,)
raise cherrypy.HTTPError(406, msg)
def __call__(self, *args, **kwargs):
@@ -233,14 +233,14 @@ class ResponseEncoder:
elif self.body is None:
self.body = []
- ct = response.headers.elements("Content-Type")
+ ct = response.headers.elements('Content-Type')
if self.debug:
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 ct.value.lower().startswith('text/'):
if self.debug:
cherrypy.log(
'Content-Type %s starts with "text/"' % ct,
@@ -264,7 +264,7 @@ class ResponseEncoder:
if self.debug:
cherrypy.log('Setting Content-Type %s' % ct,
'TOOLS.ENCODE')
- response.headers["Content-Type"] = str(ct)
+ response.headers['Content-Type'] = str(ct)
return self.body
@@ -280,11 +280,11 @@ def compress(body, compress_level):
yield ntob('\x08') # CM: compression method
yield ntob('\x00') # FLG: none set
# MTIME: 4 bytes
- yield struct.pack("<L", int(time.time()) & int('FFFFFFFF', 16))
+ yield struct.pack('<L', int(time.time()) & int('FFFFFFFF', 16))
yield ntob('\x02') # XFL: max compression, slowest algo
yield ntob('\xff') # OS: unknown
- crc = zlib.crc32(ntob(""))
+ crc = zlib.crc32(ntob(''))
size = 0
zobj = zlib.compressobj(compress_level,
zlib.DEFLATED, -zlib.MAX_WBITS,
@@ -296,9 +296,9 @@ def compress(body, compress_level):
yield zobj.flush()
# CRC32: 4 bytes
- yield struct.pack("<L", crc & int('FFFFFFFF', 16))
+ yield struct.pack('<L', crc & int('FFFFFFFF', 16))
# ISIZE: 4 bytes
- yield struct.pack("<L", size & int('FFFFFFFF', 16))
+ yield struct.pack('<L', size & int('FFFFFFFF', 16))
def decompress(body):
@@ -335,7 +335,7 @@ def gzip(compress_level=5, mime_types=['text/html', 'text/plain'],
request = cherrypy.serving.request
response = cherrypy.serving.response
- set_vary_header(response, "Accept-Encoding")
+ set_vary_header(response, 'Accept-Encoding')
if not response.body:
# Response body is empty (might be a 304 for instance)
@@ -345,7 +345,7 @@ def gzip(compress_level=5, mime_types=['text/html', 'text/plain'],
# If returning cached content (which should already have been gzipped),
# don't re-zip.
- if getattr(request, "cached", False):
+ if getattr(request, 'cached', False):
if debug:
cherrypy.log('Not gzipping cached response', context='TOOLS.GZIP')
return
@@ -413,12 +413,12 @@ def gzip(compress_level=5, mime_types=['text/html', 'text/plain'],
# Return a generator that compresses the page
response.headers['Content-Encoding'] = 'gzip'
response.body = compress(response.body, compress_level)
- if "Content-Length" in response.headers:
+ if 'Content-Length' in response.headers:
# Delete Content-Length header so finalize() recalcs it.
- del response.headers["Content-Length"]
+ del response.headers['Content-Length']
return
if debug:
cherrypy.log('No acceptable encoding found.', context='GZIP')
- cherrypy.HTTPError(406, "identity, gzip").set_response()
+ cherrypy.HTTPError(406, 'identity, gzip').set_response()