wsgi.py (1356:462458cb73c1) wsgi.py (1848:4bd548074e2c)
1from tempfile import TemporaryFile
2import os, cgi
3
1from tempfile import TemporaryFile
2import os, cgi
3
4
4def read(environ):
5 length = int(environ.get('CONTENT_LENGTH', 0))
6
7 body = TemporaryFile(mode='w+b')
8 body.write(bytes(environ['wsgi.input'].read(length)))
9 body.seek(0)
10
11 environ['wsgi.input'] = body
12 return body
13
5def read(environ):
6 length = int(environ.get('CONTENT_LENGTH', 0))
7
8 body = TemporaryFile(mode='w+b')
9 body.write(bytes(environ['wsgi.input'].read(length)))
10 body.seek(0)
11
12 environ['wsgi.input'] = body
13 return body
14
15
14def application(environ, start_response):
15 file = read(environ)
16
17 form = cgi.FieldStorage(fp=file, environ=environ, keep_blank_values=True)
18
19 filename = form['file'].filename
20 data = filename.encode() + form['file'].file.read()
21
16def application(environ, start_response):
17 file = read(environ)
18
19 form = cgi.FieldStorage(fp=file, environ=environ, keep_blank_values=True)
20
21 filename = form['file'].filename
22 data = filename.encode() + form['file'].file.read()
23
22 start_response('200 OK', [
23 ('Content-Type', 'text/plain'),
24 ('Content-Length', str(len(data))),
25 ])
24 start_response(
25 '200 OK',
26 [('Content-Type', 'text/plain'), ('Content-Length', str(len(data)))],
27 )
26
27 return data
28
29 return data