Package: python-bottle Version: 0.8.0-1 Severity: normal Hello,
thanks again for maintaining bottle. In http://bottle.paws.de/docs/tutorial.html it says: File Objects and Streams Bottle passes everything that has a read() method (file objects) to the wsgi.file_wrapper provided by your WSGI server implementation. This wrapper should use optimised system calls (sendfile on UNIX) to transfer the file contents. @route('/file') def get_file(): return open('some/file.txt','r') However, in the code we have this: # Cast Files into iterables if hasattr(out, 'read') and 'wsgi.file_wrapper' in request.environ: out = request.environ.get('wsgi.file_wrapper', lambda x, y: iter(lambda: x.read(y), ''))(out, 1024*64) # Handle Iterables. We peek into them to detect their inner type. try: out = iter(out) first = out.next() while not first: first = out.next() except StopIteration: return self._cast('') except HTTPResponse, e: first = e except Exception, e: first = HTTPError(500, 'Unhandled exception', e, format_exc(10)) if isinstance(e, (KeyboardInterrupt, SystemExit, MemoryError))\ or not self.catchall: raise # These are the inner types allowed in iterator or generator objects. if isinstance(first, HTTPResponse): return self._cast(first) if isinstance(first, StringType): return itertools.chain([first], out) if isinstance(first, unicode): return itertools.imap(lambda x: x.encode(response.charset), itertools.chain([first], out)) return self._cast(HTTPError(500, 'Unsupported response type: %s'\ Bottle seems to be extracting the first element from the iterable in order to look at what the iterator returns and possibly add transparent recoding and whatnot, then it returns a chain iterator with the first element it took out and the rest. Now, the WSGI server, even if it supports the file_wrapper optimisation[1], will never be able to see that we are returning a file_wrapper, so the optimisation will never trigger, in the face of what Bottle's documentation says. [1] http://www.python.org/dev/peps/pep-0333/#optional-platform-specific-file-handling Ciao, Enrico with significantly less hair than he had this morning -- System Information: Debian Release: squeeze/sid APT prefers testing APT policy: (500, 'testing') Architecture: amd64 (x86_64) Kernel: Linux 2.6.32-trunk-amd64 (SMP w/2 CPU cores) Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/bash Versions of packages python-bottle depends on: ii python 2.5.4-9 An interactive high-level object-o ii python-support 1.0.8 automated rebuilding support for P python-bottle recommends no packages. python-bottle suggests no packages. -- no debconf information -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org