|
Revision 1590, 1.3 kB
(checked in by alex, 3 years ago)
|
|
adding test files for the iframe transport for dojo.io.bind()
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/usr/bin/python |
|---|
| 2 | |
|---|
| 3 | # FROM: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/273844 |
|---|
| 4 | |
|---|
| 5 | import cgi |
|---|
| 6 | import cgitb; cgitb.enable() |
|---|
| 7 | import os, sys |
|---|
| 8 | import string |
|---|
| 9 | |
|---|
| 10 | UPLOAD_DIR = "/tmp/upload/" |
|---|
| 11 | form = cgi.FieldStorage() |
|---|
| 12 | |
|---|
| 13 | dbg = [] |
|---|
| 14 | |
|---|
| 15 | def debug(dbgstr): |
|---|
| 16 | dbg.append("DBG: "+str(dbgstr)) |
|---|
| 17 | |
|---|
| 18 | def save_uploaded_file(form_field, upload_dir): |
|---|
| 19 | global form |
|---|
| 20 | if not form.has_key(form_field): |
|---|
| 21 | debug("didn't find it! (1)") |
|---|
| 22 | return |
|---|
| 23 | fileitem = form[form_field] |
|---|
| 24 | if not fileitem.file: |
|---|
| 25 | debug(form.getvalue(form_field, "")) |
|---|
| 26 | debug(fileitem.__dict__) |
|---|
| 27 | debug("didn't find it! (2)") |
|---|
| 28 | return |
|---|
| 29 | fout = file(os.path.join(upload_dir, fileitem.filename), 'wb') |
|---|
| 30 | while 1: |
|---|
| 31 | chunk = fileitem.file.read(100000) |
|---|
| 32 | if not chunk: break |
|---|
| 33 | fout.write (chunk) |
|---|
| 34 | fout.close() |
|---|
| 35 | |
|---|
| 36 | retval = "false;"; |
|---|
| 37 | fileFields = "" |
|---|
| 38 | if form.has_key("fileFields"): |
|---|
| 39 | fval = str(form.getvalue("fileFields", "")) |
|---|
| 40 | fileFields = fval.split(",") |
|---|
| 41 | debug(str(len(fileFields))) |
|---|
| 42 | for field in fileFields: |
|---|
| 43 | debug("field: "+field) |
|---|
| 44 | save_uploaded_file(str(field).strip(), UPLOAD_DIR) |
|---|
| 45 | retval = "true;"; |
|---|
| 46 | |
|---|
| 47 | print """Content-Type: text/html |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | <html> |
|---|
| 51 | <head> |
|---|
| 52 | </head> |
|---|
| 53 | <body> |
|---|
| 54 | <textarea style="width: 100%%; height: 100px;">%s</textarea> |
|---|
| 55 | <br> |
|---|
| 56 | <textarea style="width: 100%%; height: 100px;">%s</textarea> |
|---|
| 57 | </body> |
|---|
| 58 | </html> |
|---|
| 59 | """ % (retval, string.join(dbg, "\n")) |
|---|