Changeset 2047
- Timestamp:
- 09/28/08 02:21:29
- Files:
-
- trunk/cherrypy/lib/__init__.py (modified) (1 diff)
- trunk/cherrypy/lib/static.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/__init__.py
r2033 r2047 144 144 145 145 146 def file_generator_limited(fileobj, count, chunk_size=65536): 147 """Yield the given file object in chunks, stopping after `count` 148 bytes has been emitted. Default chunk size is 64kB. (Core) 149 """ 150 remaining = count 151 while remaining > 0: 152 chunk = fileobj.read(min(chunk_size, remaining)) 153 chunklen = len(chunk) 154 if chunklen == 0: 155 return 156 remaining -= chunklen 157 yield chunk 146 158 trunk/cherrypy/lib/static.py
r1975 r2047 11 11 12 12 import cherrypy 13 from cherrypy.lib import cptools, http 13 from cherrypy.lib import cptools, http, file_generator_limited 14 14 15 15 … … 84 84 # Return a single-part response. 85 85 start, stop = r[0] 86 if stop > c_len: 87 stop = c_len 86 88 r_len = stop - start 87 89 response.status = "206 Partial Content" … … 90 92 response.headers['Content-Length'] = r_len 91 93 bodyfile.seek(start) 92 response.body = bodyfile.read(r_len)94 response.body = file_generator_limited(bodyfile, r_len) 93 95 else: 94 96 # Return a multipart/byteranges response. … … 112 114 % (start, stop - 1, c_len)) 113 115 bodyfile.seek(start) 114 yield bodyfile.read(stop - start) 116 for chunk in file_generator_limited(bodyfile, stop-start): 117 yield chunk 115 118 yield "\r\n" 116 119 # Final boundary

