1 """CherryPy Library"""
2
3
4 from cherrypy.lib.reprconf import unrepr, modules, attributes
5
7 '''Returns a boolean indicating if the object provided implements
8 the iterator protocol (i.e. like a generator). This will return
9 false for objects which iterable, but not iterators themselves.'''
10 from types import GeneratorType
11 if isinstance(obj, GeneratorType):
12 return True
13 elif not hasattr(obj, '__iter__'):
14 return False
15 else:
16
17
18 return iter(obj) is obj
19
21
22 """Yield the given input (a file object) in chunks (default 64k). (Core)"""
23
24 - def __init__(self, input, chunkSize=65536):
25 self.input = input
26 self.chunkSize = chunkSize
27
30
32 chunk = self.input.read(self.chunkSize)
33 if chunk:
34 return chunk
35 else:
36 if hasattr(self.input, 'close'):
37 self.input.close()
38 raise StopIteration()
39 next = __next__
40
41
43 """Yield the given file object in chunks, stopping after `count`
44 bytes has been emitted. Default chunk size is 64kB. (Core)
45 """
46 remaining = count
47 while remaining > 0:
48 chunk = fileobj.read(min(chunk_size, remaining))
49 chunklen = len(chunk)
50 if chunklen == 0:
51 return
52 remaining -= chunklen
53 yield chunk
54
55
57 "Add a Vary header to a response"
58 varies = response.headers.get("Vary", "")
59 varies = [x.strip() for x in varies.split(",") if x.strip()]
60 if header_name not in varies:
61 varies.append(header_name)
62 response.headers['Vary'] = ", ".join(varies)
63