3 # Deprecated in CherryPy 3.2 -- remove in CherryPy 3.3
4 from cherrypy
.lib
.reprconf
import _Builder
, unrepr
, modules
, attributes
6 class file_generator(object):
7 """Yield the given input (a file object) in chunks (default 64k). (Core)"""
9 def __init__(self
, input, chunkSize
=65536):
11 self
.chunkSize
= chunkSize
17 chunk
= self
.input.read(self
.chunkSize
)
21 if hasattr(self
.input, 'close'):
26 def file_generator_limited(fileobj
, count
, chunk_size
=65536):
27 """Yield the given file object in chunks, stopping after `count`
28 bytes has been emitted. Default chunk size is 64kB. (Core)
32 chunk
= fileobj
.read(min(chunk_size
, remaining
))
39 def set_vary_header(response
, header_name
):
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
)