Changeset 1242
- Timestamp:
- 08/12/06 11:16:54
- Files:
-
- trunk/cherrypy/lib/static.py (modified) (5 diffs)
- trunk/cherrypy/tutorial/tut09_files.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/static.py
r1224 r1242 14 14 15 15 16 def serve_file(path, content Type=None, disposition=None, name=None):16 def serve_file(path, content_type=None, disposition=None, name=None): 17 17 """Set status, headers, and body in order to serve the given file. 18 18 19 The Content-Type header will be set to the content Type arg, if provided.19 The Content-Type header will be set to the content_ype arg, if provided. 20 20 If not provided, the Content-Type will be guessed by its extension. 21 21 … … 52 52 cptools.validate_since() 53 53 54 if content Type is None:54 if content_type is None: 55 55 # Set content-type based on filename extension 56 56 ext = "" … … 58 58 if i != -1: 59 59 ext = path[i:].lower() 60 content Type = mimetypes.types_map.get(ext, "text/plain")61 response.headers['Content-Type'] = content Type60 content_type = mimetypes.types_map.get(ext, "text/plain") 61 response.headers['Content-Type'] = content_type 62 62 63 63 if disposition is not None: … … 102 102 for start, stop in r: 103 103 yield "--" + boundary 104 yield "\nContent-type: %s" % content Type104 yield "\nContent-type: %s" % content_type 105 105 yield ("\nContent-range: bytes %s-%s/%s\n\n" 106 106 % (start, stop - 1, c_len)) … … 133 133 r, ext = os.path.splitext(filename) 134 134 content_type = content_types.get(ext[1:], None) 135 serve_file(filename, content Type=content_type)135 serve_file(filename, content_type=content_type) 136 136 return True 137 137 except cherrypy.NotFound: trunk/cherrypy/tutorial/tut09_files.py
r1219 r1242 28 28 arguments: 29 29 30 serve_file(path, content Type=None, disposition=None, name=None)30 serve_file(path, content_type=None, disposition=None, name=None) 31 31 32 32 Set "name" to the filename that you expect clients to use when they save 33 33 your file. Note that the "name" argument is ignored if you don't also 34 34 provide a "disposition" (usually "attachement"). You can manually set 35 "content Type", but be aware that if you also use the encoding tool, it35 "content_type", but be aware that if you also use the encoding tool, it 36 36 may choke if the file extension is not recognized as belonging to a known 37 Content-Type. Setting the content Type to "application/x-download" works37 Content-Type. Setting the content_type to "application/x-download" works 38 38 in most cases, and should prompt the user with an Open/Save dialog in 39 39 popular browsers.

