Changeset 577
- Timestamp:
- 08/29/05 16:05:54
- Files:
-
- trunk/cherrypy/test/test_tutorials.py (modified) (1 diff)
- trunk/cherrypy/tutorial/tut09_file_upload.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/test/test_tutorials.py
r567 r577 158 158 """ 159 159 self.getPage('/upload', h, "POST", b) 160 self.assertBody(''' 161 < html><body>160 self.assertBody('''<html> 161 <body> 162 162 myFile length: 5<br /> 163 163 myFile filename: hello.txt<br /> 164 164 myFile mime-type: text/plain 165 </body> </html>166 ''')165 </body> 166 </html>''') 167 167 168 168 if __name__ == "__main__": trunk/cherrypy/tutorial/tut09_file_upload.py
r567 r577 18 18 19 19 def upload(self, myFile): 20 return """21 < html><body>20 out = """<html> 21 <body> 22 22 myFile length: %s<br /> 23 23 myFile filename: %s<br /> 24 24 myFile mime-type: %s 25 </body></html> 26 """ % (len(myFile.value), 27 myFile.filename, 28 myFile.type) 25 </body> 26 </html>""" 27 28 # Although this just counts the file length, it demonstrates 29 # how to read large files in chunks instead of all at once. 30 # CherryPy uses Python's cgi module to read the uploaded file 31 # into a temporary file; myFile.file.read reads from that. 32 size = 0 33 while True: 34 data = myFile.file.read(8192) 35 if not data: 36 break 37 size += len(data) 38 39 return out % (size, myFile.filename, myFile.type) 29 40 upload.exposed = True 30 41

