[CherryPy] #932: Function analogous to serve_file for open file objects

0 views
Skip to first unread message

CherryPy

unread,
Jun 3, 2009, 2:55:25 PM6/3/09
to cherrypy...@googlegroups.com
#932: Function analogous to serve_file for open file objects
----------------------------------+-----------------------------------------
Reporter: tsfer...@gmail.com | Owner: fumanchu
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: CherryPy code | Keywords:
----------------------------------+-----------------------------------------
I asked the following question:

In cherrypy.lib.static.py there is a method:
serve_file(path, content_type=None, disposition=None, name=None)
where the argument "path" must be a real file (absolute path). Is there
something similar to serve any Python file object?

and got the following answer from Alex Martelli:

From studying http://www.cherrypy.org/browser/trunk/cherrypy/lib/static.py
I'd have to say, no: the serve_file function is "monolithic", and does its
own bodyfile = open(path, 'rb'), nor does there seem to be any alternative
way. Pity, as it would be easy to refactor the function and add another
e.g. serve_open_file to cover your case, having both delegate to an
internal function for the "hard" logic such as multipart/byteranges
serving. May be worth your while to open a feature request ("enhancement
ticket") on cherrypy.org -- may not be a killer feature but I can see use
cases, and implementing it wouldn't be hard for the cherrypy people (visit
their site and follow the instructions on the page to "log in" to it).

It would be really nice to have this function!

-- tsf

--
Ticket URL: <http://www.cherrypy.org/ticket/932>
CherryPy <http://www.cherrypy.org>
CherryPy - a pythonic, object-oriented HTTP framework

CherryPy

unread,
Jun 8, 2009, 4:04:13 AM6/8/09
to cherrypy...@googlegroups.com
#932: Function analogous to serve_file for open file objects
----------------------------------+-----------------------------------------
Reporter: tsfer...@gmail.com | Owner: fumanchu
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: CherryPy code | Resolution:
Keywords: |
----------------------------------+-----------------------------------------
Comment (by visteya):

A `serve_file()` which accepts a file object won't be able to set
Last-Modified, Content-Type, and Content-Length response headers.

A `serve_file()` which accepts a file object has a problem: `serve_file()`
performs a `seek()` on the file object if the request has a Range header.

Since supporting ranges can't be done reliably, and that's about the only
benefit left in `serve_file()` after you take away setting of Last-
Modified, Content-Type and Content-Length, I think I'd be inclined to just
explain to people that the solution for this problem is to return their
open file object from the page handler, and set Content-Length and
Content-Type themselves as appropriate.

CherryPy

unread,
Jun 9, 2009, 1:47:24 AM6/9/09
to cherrypy...@googlegroups.com
#932: Function analogous to serve_file for open file objects
----------------------------------+-----------------------------------------
Reporter: tsfer...@gmail.com | Owner: fumanchu
Type: enhancement | Status: closed
Priority: normal | Milestone: 3.2
Component: CherryPy code | Resolution: fixed
Keywords: |
----------------------------------+-----------------------------------------
Changes (by fumanchu):

* milestone: => 3.2
* resolution: => fixed
* status: new => closed

Comment:

Fixed in [2417] and [2418], and for python3: [2420].
Reply all
Reply to author
Forward
0 new messages