summaryrefslogtreecommitdiff
path: root/py3/cherrypy/lib/__init__.py
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2011-02-25 22:38:17 +0000
committerRobert Brewer <fumanchu@aminus.org>2011-02-25 22:38:17 +0000
commitfd8b1e2a2662d965f05a14c2c72701decd81697c (patch)
treef6b7f89ffb181bc940c7d9b3541f01f25b49699d /py3/cherrypy/lib/__init__.py
parent5450bb603f7e0cf91d216225d3fa3f524710bcd6 (diff)
downloadcherrypy-git-trunk.tar.gz
Bringing python3 back into trunk with its own py3 folder; what was in trunk goes in the py2 folder, and we can use a single setup.py to install either, depending on the version of Python that runs setup.py install.trunk
Diffstat (limited to 'py3/cherrypy/lib/__init__.py')
-rw-r--r--py3/cherrypy/lib/__init__.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/py3/cherrypy/lib/__init__.py b/py3/cherrypy/lib/__init__.py
new file mode 100644
index 00000000..611350c9
--- /dev/null
+++ b/py3/cherrypy/lib/__init__.py
@@ -0,0 +1,45 @@
+"""CherryPy Library"""
+
+# Deprecated in CherryPy 3.2 -- remove in CherryPy 3.3
+from cherrypy.lib.reprconf import _Builder, unrepr, modules, attributes
+
+class file_generator(object):
+ """Yield the given input (a file object) in chunks (default 64k). (Core)"""
+
+ def __init__(self, input, chunkSize=65536):
+ self.input = input
+ self.chunkSize = chunkSize
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ chunk = self.input.read(self.chunkSize)
+ if chunk:
+ return chunk
+ else:
+ if hasattr(self.input, 'close'):
+ self.input.close()
+ raise StopIteration()
+ next = __next__
+
+def file_generator_limited(fileobj, count, chunk_size=65536):
+ """Yield the given file object in chunks, stopping after `count`
+ bytes has been emitted. Default chunk size is 64kB. (Core)
+ """
+ remaining = count
+ while remaining > 0:
+ chunk = fileobj.read(min(chunk_size, remaining))
+ chunklen = len(chunk)
+ if chunklen == 0:
+ return
+ remaining -= chunklen
+ yield chunk
+
+def set_vary_header(response, header_name):
+ "Add a Vary header to a response"
+ varies = response.headers.get("Vary", "")
+ varies = [x.strip() for x in varies.split(",") if x.strip()]
+ if header_name not in varies:
+ varies.append(header_name)
+ response.headers['Vary'] = ", ".join(varies)