1 """CherryPy Library"""
2
3
4 from cherrypy.lib.reprconf import unrepr, modules, attributes
5
7 """Yield the given input (a file object) in chunks (default 64k). (Core)"""
8
9 - def __init__(self, input, chunkSize=65536):
10 self.input = input
11 self.chunkSize = chunkSize
12
15
17 chunk = self.input.read(self.chunkSize)
18 if chunk:
19 return chunk
20 else:
21 if hasattr(self.input, 'close'):
22 self.input.close()
23 raise StopIteration()
24 next = __next__
25
27 """Yield the given file object in chunks, stopping after `count`
28 bytes has been emitted. Default chunk size is 64kB. (Core)
29 """
30 remaining = count
31 while remaining > 0:
32 chunk = fileobj.read(min(chunk_size, remaining))
33 chunklen = len(chunk)
34 if chunklen == 0:
35 return
36 remaining -= chunklen
37 yield chunk
38
40 "Add a Vary header to a response"
41 varies = response.headers.get("Vary", "")
42 varies = [x.strip() for x in varies.split(",") if x.strip()]
43 if header_name not in varies:
44 varies.append(header_name)
45 response.headers['Vary'] = ", ".join(varies)
46