Klaus Demo bjoern / 99fc09d
Fixed #57: File wrapper should accept optional 'chunksize' argument Jonas Haag 7 years ago
5 changed file(s) with 18 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
00
1 Copyright (c) 2010-2011 Jonas Haag <jonas@lophus.org> and contributors.
1 Copyright (c) 2010-2013 Jonas Haag <jonas@lophus.org> and contributors.
22 All rights reserved.
33 License: 2-clause-BSD (Berkley Software Distribution) license
44
4848 CFLAGS='-D DEBUG' make again
4949
5050 $(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c
51 @echo ' -> ' $(CC) -c $< -o $@
51 @echo ' -> ' $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
5252 @$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
5353
5454 # foo.o: shortcut to $(BUILD_DIR)/foo.o
33 FileWrapper_New(PyTypeObject* cls, PyObject* args, PyObject* kwargs)
44 {
55 PyObject* file;
6 if(!PyArg_ParseTuple(args, "O:FileWrapper", &file))
6 unsigned int ignored_blocksize;
7
8 if(!PyArg_ParseTuple(args, "O|I:FileWrapper", &file, &ignored_blocksize))
79 return NULL;
10
811 if(!PyFile_Check(file)) {
912 TYPE_ERROR("FileWrapper argument", "file", file);
1013 return NULL;
1114 }
15
1216 Py_INCREF(file);
13 FileWrapper* wrapper = PyObject_NEW(FileWrapper, &FileWrapper_Type);
1417 PyFile_IncUseCount((PyFileObject*)file);
18
19 FileWrapper* wrapper = PyObject_NEW(FileWrapper, cls);
1520 wrapper->file = file;
21
1622 return (PyObject*)wrapper;
1723 }
1824
233233 /* current_chunk contains the HTTP headers */
234234 if(send_chunk(request))
235235 goto out;
236 assert(!request->current_chunk_p);
236 assert(request->current_chunk_p == 0);
237237 /* abuse current_chunk_p to store the file fd */
238238 request->current_chunk_p = PyObject_AsFileDescriptor(request->iterable);
239239 goto out;
240240 }
241
241242 if(do_sendfile(request))
242243 goto out;
244
243245 } else {
244246 /* iterable */
245247 if(send_chunk(request))
306308
307309 assert(request->current_chunk != NULL);
308310 assert(!(request->current_chunk_p == PyString_GET_SIZE(request->current_chunk)
309 && PyString_GET_SIZE(request->current_chunk) != 0));
311 && PyString_GET_SIZE(request->current_chunk) != 0));
310312
311313 bytes_sent = write(
312314 request->client_fd,
22 import bjoern
33
44 W = {
5 'callable-iterator' : lambda f, e: iter(lambda: f.read(64*1024), ''),
6 'xreadlines' : lambda f, e: f,
7 'filewrapper' : lambda f, env: env['wsgi.file_wrapper'](f)
5 'callable-iterator': lambda f, e: iter(lambda: f.read(64*1024), ''),
6 'xreadlines': lambda f, e: f,
7 'filewrapper': lambda f, env: env['wsgi.file_wrapper'](f),
8 'filewrapper2': lambda f, env: env['wsgi.file_wrapper'](f, 1)
89 }
910
1011 F = len(sys.argv) > 1 and sys.argv[1] or 'README.rst'